Skip to content

Commit faa37e3

Browse files
authored
action: use shlex.split (#104)
* action: use shlex.split Closes #77. Signed-off-by: William Woodruff <[email protected]> * whitespace selftests Signed-off-by: William Woodruff <[email protected]> * document `inputs` a bit more Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: William Woodruff <[email protected]>
1 parent b3690e3 commit faa37e3

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

.github/workflows/selftest.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@ jobs:
3838
run: |
3939
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
4040
41+
selftest-whitespace:
42+
strategy:
43+
matrix:
44+
os:
45+
- ubuntu-latest
46+
- macos-latest
47+
- windows-latest
48+
runs-on: ${{ matrix.os }}
49+
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-python@v5
53+
if: ${{ matrix.os != 'ubuntu-latest' }}
54+
with:
55+
python-version: "3.x"
56+
- name: Sign artifact and publish signature
57+
uses: ./
58+
id: sigstore-python
59+
with:
60+
inputs: |
61+
./test/artifact.txt
62+
./test/white\ space.txt
63+
./test/"more white space.txt"
64+
internal-be-careful-debug: true
65+
- name: Check outputs
66+
shell: bash
67+
run: |
68+
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
69+
[[ -f ./test/white\ space.txt ]] || exit 1
70+
[[ -f ./test/more\ white\ space.txt ]] || exit 1
71+
4172
selftest-release-signing-artifacts-no-op:
4273
strategy:
4374
matrix:
@@ -314,6 +345,7 @@ jobs:
314345

315346
needs:
316347
- selftest
348+
- selftest-whitespace
317349
- selftest-release-signing-artifacts-no-op
318350
- selftest-xfail-invalid-inputs
319351
- selftest-staging

README.md

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

69+
Multiple lines are fine, and whitespace in filenames can also be escaped using
70+
POSIX shell lexing rules:
71+
72+
```yaml
73+
- uses: sigstore/[email protected]
74+
with:
75+
inputs: |
76+
./path/to/inputs/*.txt
77+
./another/path/foo\ bar.txt
78+
./a/third/path/"easier to quote than to escape".txt
79+
```
80+
6981
> [!NOTE]\
7082
> In versions of this action before 2.0.0, the `inputs` setting allowed for shell expansion.
7183
> This was unintentional, and was removed with 2.0.0.

action.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# is a whitespace-separated list of inputs
2121

2222
import os
23+
import shlex
2324
import string
2425
import subprocess
2526
import sys
@@ -100,16 +101,12 @@ def _sigstore_verify(global_args, verify_args):
100101
]
101102

102103

103-
def _warning(msg):
104-
print(f"::warning::⚠️ {msg}")
105-
106-
107104
def _fatal_help(msg):
108105
print(f"::error::❌ {msg}")
109106
sys.exit(1)
110107

111108

112-
inputs = sys.argv[1].split()
109+
inputs = shlex.split(sys.argv[1])
113110

114111
# The arguments we pass into `sigstore-python` get built up in these lists.
115112
sigstore_global_args = []

test/more white space.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is another input with a whitespace filename.

test/white space.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This input has a filename with whitespace in it.

0 commit comments

Comments
 (0)