Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action: use shlex.split #104

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/selftest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ jobs:
run: |
[[ -f ./test/artifact.txt.sigstore ]] || exit 1

selftest-whitespace:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
if: ${{ matrix.os != 'ubuntu-latest' }}
with:
python-version: "3.x"
- name: Sign artifact and publish signature
uses: ./
id: sigstore-python
with:
inputs: |
./test/artifact.txt
./test/white\ space.txt
./test/"more white space.txt"
internal-be-careful-debug: true
- name: Check outputs
shell: bash
run: |
[[ -f ./test/artifact.txt.sigstore ]] || exit 1
[[ -f ./test/white\ space.txt ]] || exit 1
[[ -f ./test/more\ white\ space.txt ]] || exit 1

selftest-release-signing-artifacts-no-op:
strategy:
matrix:
Expand Down Expand Up @@ -314,6 +345,7 @@ jobs:

needs:
- selftest
- selftest-whitespace
- selftest-release-signing-artifacts-no-op
- selftest-xfail-invalid-inputs
- selftest-staging
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ The `inputs` argument also supports file globbing:
inputs: ./path/to/inputs/*.txt
```

Multiple lines are fine, and whitespace in filenames can also be escaped using
POSIX shell lexing rules:

```yaml
- uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: |
./path/to/inputs/*.txt
./another/path/foo\ bar.txt
./a/third/path/"easier to quote than to escape".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.
Expand Down
7 changes: 2 additions & 5 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# is a whitespace-separated list of inputs

import os
import shlex
import string
import subprocess
import sys
Expand Down Expand Up @@ -100,16 +101,12 @@ def _sigstore_verify(global_args, verify_args):
]


def _warning(msg):
print(f"::warning::⚠️ {msg}")


def _fatal_help(msg):
print(f"::error::❌ {msg}")
sys.exit(1)


inputs = sys.argv[1].split()
inputs = shlex.split(sys.argv[1])

# The arguments we pass into `sigstore-python` get built up in these lists.
sigstore_global_args = []
Expand Down
1 change: 1 addition & 0 deletions test/more white space.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is another input with a whitespace filename.
1 change: 1 addition & 0 deletions test/white space.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This input has a filename with whitespace in it.
Loading