|
26 | 26 | from glob import glob
|
27 | 27 | from pathlib import Path
|
28 | 28 |
|
| 29 | +import requests |
| 30 | + |
29 | 31 | _HERE = Path(__file__).parent.resolve()
|
30 | 32 | _TEMPLATES = _HERE / "templates"
|
31 | 33 |
|
@@ -53,6 +55,22 @@ def _log(msg):
|
53 | 55 | print(msg, file=sys.stderr)
|
54 | 56 |
|
55 | 57 |
|
| 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 | + |
56 | 74 | def _sigstore_sign(global_args, sign_args):
|
57 | 75 | return ["python", "-m", "sigstore", *global_args, "sign", *sign_args]
|
58 | 76 |
|
@@ -163,6 +181,13 @@ def _fatal_help(msg):
|
163 | 181 | else:
|
164 | 182 | sigstore_verify_args.extend(["--cert-oidc-issuer", verify_oidc_issuer])
|
165 | 183 |
|
| 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 | + |
166 | 191 | for input_ in inputs:
|
167 | 192 | # Forbid things that look like flags. This isn't a security boundary; just
|
168 | 193 | # a way to prevent (less motivated) users from breaking the action on themselves.
|
|
0 commit comments