Skip to content

Commit d260c7b

Browse files
authored
selftest: add checks to selftest-glob (#75)
1 parent d48c9cd commit d260c7b

File tree

8 files changed

+71
-2
lines changed

8 files changed

+71
-2
lines changed

.github/workflows/selftest.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,60 @@ jobs:
9494
inputs: ./test/*.txt
9595
staging: true
9696
internal-be-careful-debug: true
97+
- name: Check outputs
98+
run: |
99+
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
100+
[[ -f ./test/artifact1.txt.sigstore ]] || exit 1
101+
[[ -f ./test/artifact2.txt.sigstore ]] || exit 1
102+
103+
selftest-xfail-glob-input-expansion:
104+
runs-on: ubuntu-latest
105+
env:
106+
TEST_DIR: test
107+
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
108+
steps:
109+
- uses: actions/checkout@v3
110+
- name: Sign artifacts and publish signatures
111+
continue-on-error: true
112+
uses: ./
113+
id: sigstore-python
114+
with:
115+
# This should fail since we should never directly expand ${TEST_DIR};
116+
# the user should have to pre-expand it for us.
117+
inputs: ./${TEST_DIR}/*.txt
118+
staging: true
119+
internal-be-careful-debug: true
120+
- name: Check failure
121+
env:
122+
XFAIL: ${{ steps.sigstore-python.outcome == 'failure' }}
123+
JOB_NAME: ${{ github.job }}
124+
run: |
125+
echo "xfail ${JOB_NAME}: ${XFAIL}"
126+
127+
[[ "${XFAIL}" == "true" ]] || { >&2 echo "expected step to fail"; exit 1; }
128+
129+
selftest-glob-multiple:
130+
runs-on: ubuntu-latest
131+
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
132+
steps:
133+
- uses: actions/checkout@v3
134+
- name: Sign artifacts and publish signatures
135+
uses: ./
136+
id: sigstore-python
137+
with:
138+
inputs: ./test/artifact*.txt ./test/another*.txt ./test/subdir/*.txt
139+
staging: true
140+
internal-be-careful-debug: true
141+
- name: Check outputs
142+
run: |
143+
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
144+
[[ -f ./test/artifact1.txt.sigstore ]] || exit 1
145+
[[ -f ./test/artifact2.txt.sigstore ]] || exit 1
146+
[[ -f ./test/another1.txt.sigstore ]] || exit 1
147+
[[ -f ./test/another2.txt.sigstore ]] || exit 1
148+
[[ -f ./test/subdir/hello1.txt.sigstore ]] || exit 1
149+
[[ -f ./test/subdir/hello2.txt.sigstore ]] || exit 1
150+
[[ -f ./test/subdir/hello3.txt.sigstore ]] || exit 1
97151
98152
selftest-upload-artifacts:
99153
runs-on: ubuntu-latest
@@ -234,6 +288,7 @@ jobs:
234288
- selftest-xfail-invalid-inputs
235289
- selftest-staging
236290
- selftest-glob
291+
- selftest-glob-multiple
237292
- selftest-upload-artifacts
238293
- selftest-custom-paths
239294
- selftest-verify

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ The `inputs` argument also supports file globbing:
6666
inputs: ./path/to/inputs/*.txt
6767
```
6868

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

7175
**Default**: Empty (the GitHub Actions credential will be used)

action.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22

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

204-
files = [Path(f).resolve() for f in glob(input_)]
204+
# NOTE: We use a set here to deduplicate inputs, in case a glob expands
205+
# to the same input multiple times.
206+
files = {Path(f).resolve() for f in glob(input_)}
207+
208+
# Prevent empty glob expansions, rather than silently allowing them.
209+
# Either behavior is technically correct but an empty glob indicates
210+
# user confusion, so we fail for them.
211+
if not files:
212+
_fatal_help(f"input {input_} doesn't expand to one or more filenames")
205213

206214
for file_ in files:
207215
if not file_.is_file():

test/another1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Another input.

test/another2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Yet another input.

test/subdir/hello1.txt

Whitespace-only changes.

test/subdir/hello2.txt

Whitespace-only changes.

test/subdir/hello3.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)