Skip to content

Commit

Permalink
feature: print helm-docs diff when fail-on-diff is true
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Feb 21, 2025
1 parent 1fa217c commit 0e9b59e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ jobs:
uses: actions/checkout@v4

- name: Test Local Action
continue-on-error: true
id: test-action
uses: ./
with:
chart-search-root: __tests__/fixtures
fail-on-diff: true

- name: Print Output
id: output
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ version: 0.1.0
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
appVersion: "1.2.0"
32 changes: 31 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe('run function', () => {
const gitMock: jest.Mocked<SimpleGit> = {
status: jest.fn().mockResolvedValue({
files: [{ path: './**/README.md' }]
})
}),
diff: jest.fn().mockResolvedValue('- old \n+ new ')
} as any

simpleGitMock.mockReturnValue(gitMock)
Expand All @@ -100,6 +101,35 @@ describe('run function', () => {
expect(gitMock.status).toHaveBeenCalledTimes(1)

expect(setFailedMock).toHaveBeenCalledWith("'README.md' has changed")
expect(gitMock.diff).toHaveBeenCalledWith(['--', 'README.md'])
expect(infoMock).toHaveBeenCalledWith(
"Diff for 'README.md':\n- old \n+ new "
)
expect(setFailedMock).toHaveBeenCalledWith("'README.md' has changed")
})

it("should handle fail-on-diff === 'true' when diff fails", async () => {
installHelmDocsMock.mockResolvedValue('/mocked/path')
getInputMock.mockImplementation((inputName: string) => {
if (inputName === 'fail-on-diff') {
return 'true'
}
return 'README.md'
})

const gitMock: jest.Mocked<SimpleGit> = {
status: jest.fn().mockResolvedValue({
files: [{ path: 'README.md' }]
}),
diff: jest.fn().mockRejectedValue(new Error('diff failed'))
} as any

simpleGitMock.mockReturnValue(gitMock)

await run()

expect(gitMock.diff).toHaveBeenCalledWith(['--', 'README.md'])
expect(infoMock).toHaveBeenCalledWith("Unable to get diff for 'README.md'")
})

it("should handle git-push === 'true'", async () => {
Expand Down
7 changes: 7 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export async function run(): Promise<void> {
if (outputStatus.length > 0) {
switch (true) {
case failOnDiff === 'true':
try {
const diff = await git.diff(['--', outputFile])
core.info(`Diff for '${outputFile}':\n${diff}`)
} catch {
core.info(`Unable to get diff for '${outputFile}'`)
}
core.setFailed(`'${outputFile}' has changed`)
break
case gitPush === 'true':
Expand Down

0 comments on commit 0e9b59e

Please sign in to comment.