Skip to content

Commit 90a06d6

Browse files
feat: enhance error handling for non-git directories (#1885)
Co-authored-by: GitHub Action <[email protected]>
1 parent 2cb2c92 commit 90a06d6

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,39 @@ jobs:
550550
shell:
551551
bash
552552

553+
test-non-existing-repository:
554+
name: Test changed-files with non existing repository
555+
runs-on: ubuntu-latest
556+
needs: build
557+
if: github.event_name == 'push' && needs.build.outputs.files_changed != 'true'
558+
permissions:
559+
pull-requests: read
560+
steps:
561+
- name: Checkout into dir1
562+
uses: actions/checkout@v4
563+
with:
564+
repository: ${{ github.event.pull_request.head.repo.full_name }}
565+
submodules: true
566+
fetch-depth: 0
567+
path: dir1
568+
569+
- name: Download build assets
570+
uses: actions/download-artifact@v3
571+
with:
572+
name: build-assets
573+
path: dir1/dist
574+
575+
- name: Run changed-files with non existing repository
576+
id: changed-files
577+
continue-on-error: true
578+
uses: ./dir1
579+
580+
- name: Verify failed
581+
if: steps.changed-files.outcome != 'failure'
582+
run: |
583+
echo "Expected: (failure) got ${{ steps.changed-files.outcome }}"
584+
exit 1
585+
553586
test-submodules:
554587
name: Test changed-files with submodule
555588
runs-on: ubuntu-latest

dist/index.js

Lines changed: 4 additions & 2 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/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ export async function run(): Promise<void> {
264264
})
265265
} else {
266266
if (!hasGitDirectory) {
267-
core.info(`Running on a ${github.context.eventName} event...`)
268267
throw new Error(
269-
`Can't find local .git in ${workingDirectory} directory. Please run actions/checkout before this action (Make sure the 'path' input is correct). If you intend to use Github's REST API note that only pull_request* events are supported.`
268+
`Unable to locate the git repository in the given path: ${workingDirectory}.\n Please run actions/checkout before this action (Make sure the 'path' input is correct).\n If you intend to use Github's REST API note that only pull_request* events are supported. Current event is "${github.context.eventName}".`
270269
)
271270
}
272271

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ export const isInsideWorkTree = async ({
680680
}
681681
)
682682

683+
if (stdout.trim() !== 'true') {
684+
core.debug(
685+
`The current working directory is not inside a git repository: ${cwd}`
686+
)
687+
}
688+
683689
return stdout.trim() === 'true'
684690
}
685691

0 commit comments

Comments
 (0)