Skip to content

Commit 4d9c525

Browse files
authored
action.py: Support file globbing for inputs (#6)
* action.py: Support file globbing for inputs * Delay path resolution * workflows: Add glob selftest * workflows, test: Add more artifacts so we can test file globbing properly * README: Add info about file globbing to README
1 parent 9824fe3 commit 4d9c525

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

.github/workflows/selftest.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,16 @@ jobs:
3737
- name: Verify artifact signature
3838
run: |
3939
sigstore verify --certificate ./test/artifact.txt.crt --signature ./test/artifact.txt.sig --staging ./test/artifact.txt
40+
41+
selftest-glob:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v3
45+
- name: Sign artifacts and publish signatures
46+
uses: ./
47+
id: sigstore-python
48+
with:
49+
inputs: ./test/*.txt
50+
- name: Verify artifact signatures
51+
run: |
52+
sigstore verify ./test/artifact.txt ./test/artifact1.txt ./test/artifact2.txt

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ To sign one or more files:
5050
inputs: file0.txt file1.txt file2.txt
5151
```
5252

53+
The `inputs` argument also supports file globbing:
54+
55+
```yaml
56+
- uses: trailofbits/[email protected]
57+
with:
58+
inputs: ./path/to/inputs/*.txt
59+
```
60+
5361
### `oidc-client-id`
5462

5563
**Default**: `sigstore`

action.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import subprocess
1010
import sys
11+
from glob import glob
1112
from pathlib import Path
1213

1314
_OUTPUTS = [sys.stderr]
@@ -43,7 +44,7 @@ def _fatal_help(msg):
4344
sys.exit(1)
4445

4546

46-
inputs = [Path(p).resolve() for p in sys.argv[1].split()]
47+
inputs = sys.argv[1].split()
4748
summary = Path(os.getenv("GITHUB_STEP_SUMMARY")).open("a")
4849

4950
# The arguments we pass into `sigstore-python` get built up in this list.
@@ -103,12 +104,16 @@ def _fatal_help(msg):
103104
for input_ in inputs:
104105
# Forbid things that look like flags. This isn't a security boundary; just
105106
# a way to prevent (less motivated) users from breaking the action on themselves.
106-
if str(input_).startswith("-"):
107+
if input_.startswith("-"):
107108
_fatal_help(f"input {input_} looks like a flag")
108109

109-
if not input_.is_file():
110-
_fatal_help(f"input {input_} does not look like a file")
111-
sigstore_python_args.append(input_)
110+
files = [Path(f).resolve() for f in glob(input_)]
111+
112+
for file_ in files:
113+
if not file_.is_file():
114+
_fatal_help(f"input {file_} does not look like a file")
115+
116+
sigstore_python_args.extend(files)
112117

113118
_debug(f"running: sigstore-python {[str(a) for a in sigstore_python_args]}")
114119

test/artifact1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World 1!

test/artifact2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World 2!

0 commit comments

Comments
 (0)