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: download default release assets to sign #46

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ Example:
The `release-signing-artifacts` setting controls whether or not `sigstore-python`
uploads signing artifacts to the release publishing event that triggered this run.

If enabled, this setting also re-uploads and signs GitHub's default source code artifacts,
as they are not guaranteed to be stable.

By default, no release assets are uploaded.

Requires the [`contents: write` permission](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token).
Expand Down
25 changes: 25 additions & 0 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from glob import glob
from pathlib import Path

import requests

_HERE = Path(__file__).parent.resolve()
_TEMPLATES = _HERE / "templates"

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


def _download_ref_asset(ext):
repo = os.getenv('GITHUB_REPOSITORY')
ref = os.getenv("GITHUB_REF")

artifact = f"/tmp/{os.getenv('GITHUB_REF_NAME')}{ext}"
woodruffw marked this conversation as resolved.
Show resolved Hide resolved

# GitHub supports /:org/:repo/archive/:ref<.tar.gz|.zip>.
r = requests.get(f"https://github.com/{repo}/archive/{ref}{ext}", stream=True)
r.raise_for_status()
with Path(artifact).open("wb") as io:
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
for chunk in r.iter_content(chunk_size=None):
io.write(chunk)

return artifact
woodruffw marked this conversation as resolved.
Show resolved Hide resolved


def _sigstore_sign(global_args, sign_args):
return ["python", "-m", "sigstore", *global_args, "sign", *sign_args]

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

if os.getenv("GHA_SIGSTORE_PYTHON_RELEASE_SIGNING_ARTIFACTS") == "true":
for filetype in [".zip", ".tar.gz"]:
artifact = _download_ref_asset(filetype)
if artifact is not None:
signing_artifact_paths.append(artifact)
inputs.append(artifact)

for input_ in inputs:
# Forbid things that look like flags. This isn't a security boundary; just
# a way to prevent (less motivated) users from breaking the action on themselves.
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ runs:
GHA_SIGSTORE_PYTHON_VERIFY: "${{ inputs.verify }}"
GHA_SIGSTORE_PYTHON_VERIFY_CERT_IDENTITY: "${{ inputs.verify-cert-identity }}"
GHA_SIGSTORE_PYTHON_VERIFY_OIDC_ISSUER: "${{ inputs.verify-oidc-issuer }}"
GHA_SIGSTORE_PYTHON_RELEASE_SIGNING_ARTIFACTS: "${{ inputs.release-signing-artifacts }}"
GHA_SIGSTORE_PYTHON_INTERNAL_BE_CAREFUL_DEBUG: "${{ inputs.internal-be-careful-debug }}"
shell: bash

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sigstore ~= 1.1
requests ~= 2.28