Skip to content

Commit f908497

Browse files
authored
Merge pull request #29 from GrantBirki/output-fmt
Pretty output formatting
2 parents 9bc6139 + fcf1469 commit f908497

6 files changed

Lines changed: 56 additions & 23 deletions

File tree

.github/workflows/acceptance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ jobs:
5555
- uses: actions/upload-artifact@v4
5656
with:
5757
name: json-diff
58-
path: ~/diff.json
58+
path: diff.json
5959
retention-days: 1

.github/workflows/sample-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ jobs:
4141
- uses: actions/upload-artifact@v4
4242
with:
4343
name: json-diff
44-
path: ~/diff.json
44+
path: diff.json
4545
retention-days: 1

__tests__/functions/git-diff.test.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ test('executes gitDiff', async () => {
5151
)
5252
expect(results.files[0].chunks[0].changes[2].type).toBe('DeletedLine')
5353

54-
expect(infoMock).toHaveBeenCalledWith('total files changed (raw diff): 5')
55-
expect(infoMock).toHaveBeenCalledWith('total files changed (json diff): 5')
54+
expect(infoMock).toHaveBeenCalledWith('🏃 starting the git-diff-action')
55+
expect(infoMock).toHaveBeenCalledWith(
56+
'🧮 total detected files changed (raw diff): 5'
57+
)
58+
expect(infoMock).toHaveBeenCalledWith(
59+
'🧮 total detected files changed (json diff): 5'
60+
)
5661
})
5762

5863
test('executes gitDiff with binary files', async () => {
@@ -76,11 +81,16 @@ test('executes gitDiff with binary files', async () => {
7681
expect(results.files[0].chunks[0].changes[2].type).toBe('DeletedLine')
7782

7883
expect(results.files.length).toBe(7)
84+
expect(infoMock).toHaveBeenCalledWith('🏃 starting the git-diff-action')
85+
expect(infoMock).toHaveBeenCalledWith(
86+
'📂 reading git diff from file: __tests__/fixtures/with-binary-files.diff'
87+
)
88+
expect(infoMock).toHaveBeenCalledWith(
89+
'🧮 total detected files changed (raw diff): 7'
90+
)
7991
expect(infoMock).toHaveBeenCalledWith(
80-
'reading git diff from file: __tests__/fixtures/with-binary-files.diff'
92+
'🧮 total detected files changed (json diff): 7'
8193
)
82-
expect(infoMock).toHaveBeenCalledWith('total files changed (raw diff): 7')
83-
expect(infoMock).toHaveBeenCalledWith('total files changed (json diff): 7')
8494
})
8595

8696
// this test case is a bug test
@@ -99,13 +109,18 @@ test('executes gitDiff with binary files and --binary flag and breaks (bug test)
99109
expect(lastFile.path).toBe('kv-cache.js')
100110

101111
expect(results.files.length).toBe(4)
112+
expect(infoMock).toHaveBeenCalledWith('🏃 starting the git-diff-action')
102113
expect(infoMock).toHaveBeenCalledWith(
103-
'reading git diff from file: __tests__/fixtures/with-binary-files-and-binary-flag.diff'
114+
'📂 reading git diff from file: __tests__/fixtures/with-binary-files-and-binary-flag.diff'
104115
)
105116

106117
// note that the total files changed is 7, but the json diff only has 4 files
107-
expect(infoMock).toHaveBeenCalledWith('total files changed (raw diff): 7')
108-
expect(infoMock).toHaveBeenCalledWith('total files changed (json diff): 4')
118+
expect(infoMock).toHaveBeenCalledWith(
119+
'🧮 total detected files changed (raw diff): 7'
120+
)
121+
expect(infoMock).toHaveBeenCalledWith(
122+
'🧮 total detected files changed (json diff): 4'
123+
)
109124
})
110125

111126
test('executes gitDiff by using the git binary', async () => {
@@ -150,8 +165,12 @@ test('executes gitDiff by using the git binary', async () => {
150165
expect(infoMock).toHaveBeenCalledWith(
151166
'max_buffer_size is not defined, using default of 1000000'
152167
)
153-
expect(infoMock).toHaveBeenCalledWith('total files changed (raw diff): 5')
154-
expect(infoMock).toHaveBeenCalledWith('total files changed (json diff): 5')
168+
expect(infoMock).toHaveBeenCalledWith(
169+
'🧮 total detected files changed (raw diff): 5'
170+
)
171+
expect(infoMock).toHaveBeenCalledWith(
172+
'🧮 total detected files changed (json diff): 5'
173+
)
155174
expect(debugMock).toHaveBeenCalledWith(
156175
'running git diff command: git --no-pager diff --no-color --full-index HEAD^1 .'
157176
)

dist/index.js

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

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/git-diff.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import fs from 'fs'
88
// If an error occurs, setFailed is called and it returns null
99
export async function gitDiff() {
1010
try {
11+
core.info('🏃 starting the git-diff-action')
12+
1113
// Get the base branch to use for the diff
1214
const baseBranch = core.getInput('base_branch')
1315
core.debug(`base_branch: ${baseBranch}`)
@@ -26,7 +28,7 @@ export async function gitDiff() {
2628
core.debug(`git_diff_file: ${gitDiffFile}`)
2729
// If git_diff_file is provided, read the file and return the diff
2830
if (gitDiffFile !== 'false') {
29-
core.info(`reading git diff from file: ${gitDiffFile}`)
31+
core.info(`📂 reading git diff from file: ${gitDiffFile}`)
3032
gitDiff = fs.readFileSync(gitDiffFile, 'utf8')
3133
} else {
3234
// if max_buffer_size is not defined, just use the default
@@ -65,7 +67,9 @@ export async function gitDiff() {
6567
// if for some reason you have the literal string 'diff --git' in your file...
6668
// ... this will report one more file changed than reality (or more if you have more of those strings in your file)
6769
const totalFilesChanged = gitDiff.split('diff --git').length - 1
68-
core.info(`total files changed (raw diff): ${totalFilesChanged}`)
70+
core.info(
71+
`🧮 total detected files changed (raw diff): ${totalFilesChanged}`
72+
)
6973

7074
// only log the raw diff if the Action is explicitly set to run in debug mode
7175
core.debug(`raw git diff: ${gitDiff}`)
@@ -77,7 +81,7 @@ export async function gitDiff() {
7781
// Write the raw diff to a file if the path is provided
7882
const rawPath = core.getInput('raw_diff_file_output')
7983
if (rawPath) {
80-
core.debug(`writing raw diff to ${rawPath}`)
84+
core.info(`💾 writing raw diff to: ${rawPath}`)
8185
core.setOutput('raw-diff-path', rawPath)
8286
fs.writeFileSync(rawPath, gitDiff)
8387
}
@@ -87,7 +91,9 @@ export async function gitDiff() {
8791
const jsonDiff = JSON.stringify(diff)
8892

8993
// log the total amount of files changed in the json diff
90-
core.info(`total files changed (json diff): ${diff.files.length}`)
94+
core.info(
95+
`🧮 total detected files changed (json diff): ${diff.files.length}`
96+
)
9197

9298
// only log the json diff if the Action is explicitly set to run in debug mode
9399
core.debug(`jsonDiff: ${jsonDiff}`)
@@ -100,11 +106,12 @@ export async function gitDiff() {
100106
// Write the JSON diff to a file if the path is provided
101107
const jsonPath = core.getInput('json_diff_file_output')
102108
if (jsonPath) {
103-
core.debug(`writing json diff to ${jsonPath}`)
109+
core.info(`💾 writing json diff to: ${jsonPath}`)
104110
core.setOutput('json-diff-path', jsonPath)
105111
fs.writeFileSync(jsonPath, jsonDiff)
106112
}
107113

114+
core.info('✅ git-diff-action completed successfully')
108115
return diff
109116
} catch (e) {
110117
core.setFailed(`error getting git diff: ${e}`)

0 commit comments

Comments
 (0)