Skip to content

Commit

Permalink
feat: enhance error handling for non-git directories (#1885)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
jackton1 and actions-user authored Jan 25, 2024
1 parent 2cb2c92 commit 90a06d6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,39 @@ jobs:
shell:
bash

test-non-existing-repository:
name: Test changed-files with non existing repository
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && needs.build.outputs.files_changed != 'true'
permissions:
pull-requests: read
steps:
- name: Checkout into dir1
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: 0
path: dir1

- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
path: dir1/dist

- name: Run changed-files with non existing repository
id: changed-files
continue-on-error: true
uses: ./dir1

- name: Verify failed
if: steps.changed-files.outcome != 'failure'
run: |
echo "Expected: (failure) got ${{ steps.changed-files.outcome }}"
exit 1
test-submodules:
name: Test changed-files with submodule
runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ export async function run(): Promise<void> {
})
} else {
if (!hasGitDirectory) {
core.info(`Running on a ${github.context.eventName} event...`)
throw new Error(
`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.`
`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}".`
)
}

Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ export const isInsideWorkTree = async ({
}
)

if (stdout.trim() !== 'true') {
core.debug(
`The current working directory is not inside a git repository: ${cwd}`
)
}

return stdout.trim() === 'true'
}

Expand Down

0 comments on commit 90a06d6

Please sign in to comment.