Skip to content

Commit

Permalink
selftest: add checks to selftest-glob (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw committed Aug 10, 2023
1 parent d48c9cd commit d260c7b
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/selftest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,60 @@ jobs:
inputs: ./test/*.txt
staging: true
internal-be-careful-debug: true
- name: Check outputs
run: |
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
[[ -f ./test/artifact1.txt.sigstore ]] || exit 1
[[ -f ./test/artifact2.txt.sigstore ]] || exit 1
selftest-xfail-glob-input-expansion:
runs-on: ubuntu-latest
env:
TEST_DIR: test
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v3
- name: Sign artifacts and publish signatures
continue-on-error: true
uses: ./
id: sigstore-python
with:
# This should fail since we should never directly expand ${TEST_DIR};
# the user should have to pre-expand it for us.
inputs: ./${TEST_DIR}/*.txt
staging: true
internal-be-careful-debug: true
- name: Check failure
env:
XFAIL: ${{ steps.sigstore-python.outcome == 'failure' }}
JOB_NAME: ${{ github.job }}
run: |
echo "xfail ${JOB_NAME}: ${XFAIL}"
[[ "${XFAIL}" == "true" ]] || { >&2 echo "expected step to fail"; exit 1; }
selftest-glob-multiple:
runs-on: ubuntu-latest
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v3
- name: Sign artifacts and publish signatures
uses: ./
id: sigstore-python
with:
inputs: ./test/artifact*.txt ./test/another*.txt ./test/subdir/*.txt
staging: true
internal-be-careful-debug: true
- name: Check outputs
run: |
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
[[ -f ./test/artifact1.txt.sigstore ]] || exit 1
[[ -f ./test/artifact2.txt.sigstore ]] || exit 1
[[ -f ./test/another1.txt.sigstore ]] || exit 1
[[ -f ./test/another2.txt.sigstore ]] || exit 1
[[ -f ./test/subdir/hello1.txt.sigstore ]] || exit 1
[[ -f ./test/subdir/hello2.txt.sigstore ]] || exit 1
[[ -f ./test/subdir/hello3.txt.sigstore ]] || exit 1
selftest-upload-artifacts:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -234,6 +288,7 @@ jobs:
- selftest-xfail-invalid-inputs
- selftest-staging
- selftest-glob
- selftest-glob-multiple
- selftest-upload-artifacts
- selftest-custom-paths
- selftest-verify
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ The `inputs` argument also supports file globbing:
inputs: ./path/to/inputs/*.txt
```

> [!NOTE]\
> In versions of this action before 2.0.0, the `inputs` setting allowed for shell expansion.
> This was unintentional, and was removed with 2.0.0.
### `identity-token`

**Default**: Empty (the GitHub Actions credential will be used)
Expand Down
12 changes: 10 additions & 2 deletions action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python

# Copyright 2022 The Sigstore Authors
#
Expand Down Expand Up @@ -201,7 +201,15 @@ def _fatal_help(msg):
if input_.startswith("-"):
_fatal_help(f"input {input_} looks like a flag")

files = [Path(f).resolve() for f in glob(input_)]
# NOTE: We use a set here to deduplicate inputs, in case a glob expands
# to the same input multiple times.
files = {Path(f).resolve() for f in glob(input_)}

# Prevent empty glob expansions, rather than silently allowing them.
# Either behavior is technically correct but an empty glob indicates
# user confusion, so we fail for them.
if not files:
_fatal_help(f"input {input_} doesn't expand to one or more filenames")

for file_ in files:
if not file_.is_file():
Expand Down
1 change: 1 addition & 0 deletions test/another1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Another input.
1 change: 1 addition & 0 deletions test/another2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yet another input.
Empty file added test/subdir/hello1.txt
Empty file.
Empty file added test/subdir/hello2.txt
Empty file.
Empty file added test/subdir/hello3.txt
Empty file.

0 comments on commit d260c7b

Please sign in to comment.