Skip to content

Commit 1ddeb82

Browse files
authored
action: use a venv to prevent PEP 668 errors (#145)
* action: use a venv to prevent PEP 668 errors Signed-off-by: William Woodruff <[email protected]> * action: use sys.executable Signed-off-by: William Woodruff <[email protected]> * fight with Windows Signed-off-by: William Woodruff <[email protected]> * setup: minimum Python is 3.8 This has been true for a while. Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: William Woodruff <[email protected]>
1 parent 9466100 commit 1ddeb82

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

.github/workflows/selftest.yml

+24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
- ubuntu-latest
2020
- macos-latest
2121
- windows-latest
22+
# TODO: Can be removed when 24.04 becomes ubuntu-latest.
23+
- ubuntu-24.04
2224
runs-on: ${{ matrix.os }}
2325
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
2426
steps:
@@ -38,6 +40,28 @@ jobs:
3840
run: |
3941
[[ -f ./test/artifact.txt.sigstore.json ]] || exit 1
4042
43+
selftest-runner-python:
44+
strategy:
45+
matrix:
46+
os:
47+
- ubuntu-latest
48+
# TODO: Can be removed when 24.04 becomes ubuntu-latest.
49+
- ubuntu-24.04
50+
runs-on: ${{ matrix.os }}
51+
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork
52+
steps:
53+
- uses: actions/checkout@v4
54+
- name: Sign artifact and publish signature
55+
uses: ./
56+
id: sigstore-python
57+
with:
58+
inputs: ./test/artifact.txt
59+
internal-be-careful-debug: true
60+
- name: Check outputs
61+
shell: bash
62+
run: |
63+
[[ -f ./test/artifact.txt.sigstore.json ]] || exit 1
64+
4165
selftest-whitespace:
4266
strategy:
4367
matrix:

action.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def _download_ref_asset(ext):
8686

8787

8888
def _sigstore_sign(global_args, sign_args):
89-
return ["python", "-m", "sigstore", *global_args, "sign", *sign_args]
89+
return [sys.executable, "-m", "sigstore", *global_args, "sign", *sign_args]
9090

9191

9292
def _sigstore_verify(global_args, verify_args):
9393
return [
94-
"python",
94+
sys.executable,
9595
"-m",
9696
"sigstore",
9797
*global_args,

action.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ runs:
8383
using: "composite"
8484
steps:
8585
- name: Set up sigstore-python
86+
id: setup
8687
run: |
8788
# NOTE: Sourced, not executed as a script.
8889
source "${GITHUB_ACTION_PATH}/setup/setup.bash"
@@ -93,10 +94,13 @@ runs:
9394
- name: Run sigstore-python
9495
id: sigstore-python
9596
run: |
96-
${GITHUB_ACTION_PATH}/action.py "${GHA_SIGSTORE_PYTHON_INPUTS}"
97+
"${VENV_PYTHON_PATH}" \
98+
"${GITHUB_ACTION_PATH}/action.py" \
99+
"${GHA_SIGSTORE_PYTHON_INPUTS}"
97100
env:
98101
# The year is 2023, and nonsense like this is still necessary on Windows.
99102
PYTHONUTF8: "1"
103+
VENV_PYTHON_PATH: "${{ steps.setup.outputs.venv-python-path }}"
100104
GHA_SIGSTORE_PYTHON_IDENTITY_TOKEN: "${{ inputs.identity-token }}"
101105
GHA_SIGSTORE_PYTHON_SIGNATURE: "${{ inputs.signature }}"
102106
GHA_SIGSTORE_PYTHON_CERTIFICATE: "${{ inputs.certificate }}"

setup/setup.bash

+21-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,33 @@ if [[ "${0}" == "${BASH_SOURCE[0]}" ]]; then
3535
die "Internal error: setup harness was executed instead of being sourced?"
3636
fi
3737

38-
# Check the Python version, making sure it's new enough (3.7+)
38+
# Check the Python version, making sure it's new enough (3.8+)
3939
# The installation step immediately below will technically catch this,
4040
# but doing it explicitly gives us the opportunity to produce a better
4141
# error message.
4242
vers=$(python -V | cut -d ' ' -f2)
4343
maj_vers=$(cut -d '.' -f1 <<< "${vers}")
4444
min_vers=$(cut -d '.' -f2 <<< "${vers}")
4545

46-
[[ "${maj_vers}" == "3" && "${min_vers}" -ge 7 ]] || die "Bad Python version: ${vers}"
46+
[[ "${maj_vers}" == "3" && "${min_vers}" -ge 8 ]] || die "Bad Python version: ${vers}"
4747

48-
python -m pip install --requirement "${GITHUB_ACTION_PATH}/requirements.txt"
48+
# If the user didn't explicitly configure a Python version with
49+
# `actions/setup-python`, then we might be using the distribution's Python and
50+
# therefore be subject to PEP 668. We use a virtual environment unconditionally
51+
# to prevent that kind of confusion.
52+
python -m venv "${GITHUB_ACTION_PATH}/.action-env"
4953

50-
debug "sigstore-python: $(python -m sigstore --version)"
54+
# Annoying: Windows venvs use a different structure, for unknown reasons.
55+
if [[ -d "${GITHUB_ACTION_PATH}/.action-env/bin" ]]; then
56+
VENV_PYTHON_PATH="${GITHUB_ACTION_PATH}/.action-env/bin/python"
57+
else
58+
VENV_PYTHON_PATH="${GITHUB_ACTION_PATH}/.action-env/Scripts/python"
59+
fi
60+
61+
"${VENV_PYTHON_PATH}" -m pip install --requirement "${GITHUB_ACTION_PATH}/requirements.txt"
62+
63+
debug "sigstore-python: $("${VENV_PYTHON_PATH}" -m sigstore --version)"
64+
65+
# Finally, propagate VENV_PYTHON_PATH so we can actually kick-start
66+
# the extension from it.
67+
echo "venv-python-path=${VENV_PYTHON_PATH}" >> "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)