Skip to content

Commit 7643db0

Browse files
tnytownwoodruffw
andauthored
action: download default release assets to sign (#46)
* action: download default release assets to sign Signed-off-by: Andrew Pan <[email protected]> * README.md: doc `release-signing-artifacts` change Signed-off-by: Andrew Pan <[email protected]> * action.py: use requests library for download Signed-off-by: Andrew Pan <[email protected]> * Apply suggestions from code review Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: Andrew Pan <[email protected]> Signed-off-by: William Woodruff <[email protected]> Co-authored-by: William Woodruff <[email protected]> Co-authored-by: William Woodruff <[email protected]>
1 parent f3663a3 commit 7643db0

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ Example:
367367
The `release-signing-artifacts` setting controls whether or not `sigstore-python`
368368
uploads signing artifacts to the release publishing event that triggered this run.
369369

370+
If enabled, this setting also re-uploads and signs GitHub's default source code artifacts,
371+
as they are not guaranteed to be stable.
372+
370373
By default, no release assets are uploaded.
371374

372375
Requires the [`contents: write` permission](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token).

action.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from glob import glob
2727
from pathlib import Path
2828

29+
import requests
30+
2931
_HERE = Path(__file__).parent.resolve()
3032
_TEMPLATES = _HERE / "templates"
3133

@@ -53,6 +55,22 @@ def _log(msg):
5355
print(msg, file=sys.stderr)
5456

5557

58+
def _download_ref_asset(ext):
59+
repo = os.getenv('GITHUB_REPOSITORY')
60+
ref = os.getenv("GITHUB_REF")
61+
62+
artifact = Path(f"/tmp/{os.getenv('GITHUB_REF_NAME')}").with_suffix(ext)
63+
64+
# GitHub supports /:org/:repo/archive/:ref<.tar.gz|.zip>.
65+
r = requests.get(f"https://github.com/{repo}/archive/{ref}{ext}", stream=True)
66+
r.raise_for_status()
67+
with artifact.open("wb") as io:
68+
for chunk in r.iter_content(chunk_size=None):
69+
io.write(chunk)
70+
71+
return str(artifact)
72+
73+
5674
def _sigstore_sign(global_args, sign_args):
5775
return ["python", "-m", "sigstore", *global_args, "sign", *sign_args]
5876

@@ -163,6 +181,13 @@ def _fatal_help(msg):
163181
else:
164182
sigstore_verify_args.extend(["--cert-oidc-issuer", verify_oidc_issuer])
165183

184+
if os.getenv("GHA_SIGSTORE_PYTHON_RELEASE_SIGNING_ARTIFACTS") == "true":
185+
for filetype in [".zip", ".tar.gz"]:
186+
artifact = _download_ref_asset(filetype)
187+
if artifact is not None:
188+
signing_artifact_paths.append(artifact)
189+
inputs.append(artifact)
190+
166191
for input_ in inputs:
167192
# Forbid things that look like flags. This isn't a security boundary; just
168193
# a way to prevent (less motivated) users from breaking the action on themselves.

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ runs:
123123
GHA_SIGSTORE_PYTHON_VERIFY: "${{ inputs.verify }}"
124124
GHA_SIGSTORE_PYTHON_VERIFY_CERT_IDENTITY: "${{ inputs.verify-cert-identity }}"
125125
GHA_SIGSTORE_PYTHON_VERIFY_OIDC_ISSUER: "${{ inputs.verify-oidc-issuer }}"
126+
GHA_SIGSTORE_PYTHON_RELEASE_SIGNING_ARTIFACTS: "${{ inputs.release-signing-artifacts }}"
126127
GHA_SIGSTORE_PYTHON_INTERNAL_BE_CAREFUL_DEBUG: "${{ inputs.internal-be-careful-debug }}"
127128
shell: bash
128129

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
sigstore ~= 1.1
2+
requests ~= 2.28

0 commit comments

Comments
 (0)