|
1 | 1 | import { error, getInput, info, isDebug } from '@actions/core' |
2 | 2 | import { context } from '@actions/github' |
3 | | -import { spawn, spawnSync } from 'child_process' |
| 3 | +import { spawn } from 'child_process' |
4 | 4 | import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs' |
5 | 5 | import * as os from 'os' |
6 | 6 | import * as path from 'path' |
| 7 | +import { simpleGit } from 'simple-git' |
7 | 8 |
|
8 | 9 | // Gather GITHUB_* and CI env vars for the lacework iac binary to read directly |
9 | 10 | function gatherGitHubEnvVars(): string[] { |
@@ -115,29 +116,15 @@ export function generateUILink() { |
115 | 116 | return url |
116 | 117 | } |
117 | 118 |
|
118 | | -export function getModifiedFiles(): string | undefined { |
119 | | - const eventPath = process.env.GITHUB_EVENT_PATH |
120 | | - if (!eventPath) return undefined |
121 | | - |
122 | | - let eventData: any |
| 119 | +export async function getModifiedFiles(): Promise<string | undefined> { |
123 | 120 | try { |
124 | | - eventData = JSON.parse(readFileSync(eventPath, 'utf8')) |
| 121 | + const diff = await simpleGit().diff(['--name-only', 'HEAD^1...HEAD']) |
| 122 | + const files = diff.trim().split('\n').filter(Boolean).join(',') |
| 123 | + return files || undefined |
125 | 124 | } catch (e) { |
126 | | - info(`Failed to parse GitHub event file: ${e}`) |
127 | | - return undefined |
128 | | - } |
129 | | - |
130 | | - const baseSha = eventData.pull_request?.base?.sha |
131 | | - if (!baseSha) return undefined |
132 | | - |
133 | | - const result = spawnSync('git', ['diff', '--name-only', `${baseSha}...HEAD`]) |
134 | | - if (result.status !== 0) { |
135 | | - info(`Failed to get modified files: ${result.stderr?.toString()}`) |
| 125 | + info(`Failed to get modified files: ${e}`) |
136 | 126 | return undefined |
137 | 127 | } |
138 | | - |
139 | | - const files = result.stdout.toString().trim().split('\n').filter(Boolean).join(',') |
140 | | - return files || undefined |
141 | 128 | } |
142 | 129 |
|
143 | 130 | export function shouldRunIaCScanner(modifiedFiles: string): boolean { |
|
0 commit comments