Skip to content

Commit 720dff5

Browse files
authored
Switching to git log approach (#254)
1 parent f2f3a5c commit 720dff5

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

__tests__/bundle_publish.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("bundle_publish", () => {
3131
it("should return true when directory has changes in HEAD commit", async () => {
3232
mockedExec.exec
3333
.mockImplementationOnce(async (cmd, args, options) => {
34-
// diff-tree returns changed files
34+
// git log returns changed files
3535
if (options?.listeners?.stdout) {
3636
options.listeners.stdout(Buffer.from("test-bundle/massdriver.yaml\ntest-bundle/src/main.tf\n"))
3737
}
@@ -41,15 +41,15 @@ describe("bundle_publish", () => {
4141

4242
await bundlePublish()
4343

44-
// Verify diff-tree was called to check HEAD commit
44+
// Verify git log was called to check HEAD commit
4545
expect(mockedExec.exec).toHaveBeenCalledWith(
4646
"git",
47-
["diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD", "--", "test-bundle"],
47+
["log", "--format=", "--name-only", "-1", "HEAD", "--", "test-bundle"],
4848
expect.objectContaining({
4949
ignoreReturnCode: true,
50-
silent: true,
5150
listeners: expect.objectContaining({
52-
stdout: expect.any(Function)
51+
stdout: expect.any(Function),
52+
stderr: expect.any(Function)
5353
})
5454
})
5555
)
@@ -69,7 +69,7 @@ describe("bundle_publish", () => {
6969
it("should skip publish when no changes detected in HEAD commit", async () => {
7070
mockedExec.exec
7171
.mockImplementationOnce(async (cmd, args, options) => {
72-
// diff-tree returns no files (empty output)
72+
// git log returns no files (empty output)
7373
if (options?.listeners?.stdout) {
7474
options.listeners.stdout(Buffer.from(""))
7575
}

dist/bundle_publish/index.js

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bundle_publish.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,41 @@ import * as exec from "@actions/exec"
88
const hasChangesInDirectory = async (
99
directory: string
1010
): Promise<boolean> => {
11+
core.info(`====== [hasChanges] START ======`)
1112
core.info(`[hasChanges] Checking for changes in directory: ${directory}`)
1213

13-
// Check what files changed in the current commit (HEAD)
14-
// This works even with shallow clones (fetch-depth: 1)
15-
core.info(`[hasChanges] Checking files changed in HEAD commit in ${directory}...`)
14+
// Use git log to get files changed in HEAD commit - works with shallow clones
15+
core.info(`[hasChanges] Running: git log --format="" --name-only -1 HEAD -- ${directory}`)
1616

1717
let changedFiles = ""
18-
const diffTreeExitCode = await exec.exec(
18+
await exec.exec(
1919
"git",
20-
["diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD", "--", directory],
20+
["log", "--format=", "--name-only", "-1", "HEAD", "--", directory],
2121
{
2222
ignoreReturnCode: true,
23-
silent: true,
2423
listeners: {
2524
stdout: (data: Buffer) => {
2625
changedFiles += data.toString()
26+
},
27+
stderr: (data: Buffer) => {
28+
core.info(`[hasChanges] git stderr: ${data.toString()}`)
2729
}
2830
}
2931
}
3032
)
3133

32-
// diff-tree returns 0 even if no files changed, so check the output
34+
core.info(`[hasChanges] Raw output length: ${changedFiles.length}`)
35+
core.info(`[hasChanges] Raw output (first 200 chars): ${changedFiles.substring(0, 200)}`)
36+
37+
// Check if any files were returned
3338
if (changedFiles.trim().length > 0) {
3439
const fileCount = changedFiles.trim().split('\n').length
3540
core.info(`[hasChanges] ✓ Found ${fileCount} changed file(s) in ${directory} in HEAD commit`)
3641
return true
3742
}
3843

3944
core.info(`[hasChanges] ✗ No changes detected in ${directory} in HEAD commit`)
45+
core.info(`====== [hasChanges] END ======`)
4046
return false
4147
}
4248

0 commit comments

Comments
 (0)