mirror of
https://github.com/tj-actions/changed-files
synced 2025-01-29 13:34:51 +00:00
feat: enhance error handling for non-git directories (#1885)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
2cb2c9234e
commit
90a06d6ba9
5 changed files with 40 additions and 2 deletions
33
.github/workflows/test.yml
vendored
33
.github/workflows/test.yml
vendored
|
@ -550,6 +550,39 @@ jobs:
|
||||||
shell:
|
shell:
|
||||||
bash
|
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:
|
test-submodules:
|
||||||
name: Test changed-files with submodule
|
name: Test changed-files with submodule
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
|
@ -264,9 +264,8 @@ export async function run(): Promise<void> {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (!hasGitDirectory) {
|
if (!hasGitDirectory) {
|
||||||
core.info(`Running on a ${github.context.eventName} event...`)
|
|
||||||
throw new Error(
|
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}".`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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'
|
return stdout.trim() === 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue