Skip to content

Commit 396ae72

Browse files
Expose the signature and certificate outputs as workflow artifacts (#11)
* Expose the signature and certificate outputs as workflow artifacts * Put each path on a newline * Cleanup * Support `--certificate` and `--signature` flags * Don't write artifact paths if `--no-default-files` has been provided * README, action: configure workflow artifacts Signed-off-by: William Woodruff <[email protected]> * workflows/selftest: test artifact uploads Signed-off-by: William Woodruff <[email protected]> * action: fiddle with condition Signed-off-by: William Woodruff <[email protected]> Co-authored-by: William Woodruff <[email protected]>
1 parent 940b873 commit 396ae72

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

.github/workflows/selftest.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,15 @@ jobs:
5050
- name: Verify artifact signatures
5151
run: |
5252
sigstore verify ./test/artifact.txt ./test/artifact1.txt ./test/artifact2.txt
53+
54+
selftest-upload-artifacts:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v3
58+
- name: Sign artifact and publish signature
59+
uses: ./
60+
id: sigstore-python
61+
with:
62+
inputs: ./test/artifact.txt
63+
staging: true
64+
upload-signing-artifacts: true

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ Example:
278278
staging: true
279279
```
280280

281+
### `upload-signing-artifacts`
282+
283+
**Default**: `false`
284+
285+
The `upload-signing-artifacts` setting controls whether or not `sigstore-python` creates
286+
[workflow artifacts](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts)
287+
for the outputs produced by signing operations.
288+
289+
By default, no workflow artifacts are uploaded. When enabled, the default
290+
workflow artifact retention period is used.
291+
292+
Example:
293+
294+
```yaml
295+
- uses: trailofbits/[email protected]
296+
with:
297+
inputs: file.txt
298+
upload-signing-artifacts: true
299+
```
300+
281301
### Internal options
282302
<details>
283303
<summary>⚠️ Internal options ⚠️</summary>

action.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def _fatal_help(msg):
5353
# The environment variables that we apply to `sigstore-python`.
5454
sigstore_python_env = {}
5555

56+
# A list of paths to signing artifacts generated by `sigstore-python`. We want
57+
# to upload these as workflow artifacts after signing.
58+
signing_artifact_paths = []
59+
5660
if _DEBUG:
5761
sigstore_python_env["SIGSTORE_LOGLEVEL"] = "DEBUG"
5862

@@ -70,10 +74,12 @@ def _fatal_help(msg):
7074
output_signature = os.getenv("GHA_SIGSTORE_PYTHON_OUTPUT_SIGNATURE")
7175
if output_signature != "":
7276
sigstore_python_args.extend(["--output-signature", output_signature])
77+
signing_artifact_paths.append(output_signature)
7378

7479
output_certificate = os.getenv("GHA_SIGSTORE_PYTHON_OUTPUT_CERTIFICATE")
7580
if output_certificate != "":
7681
sigstore_python_args.extend(["--output-certificate", output_certificate])
82+
signing_artifact_paths.append(output_certificate)
7783

7884
if os.getenv("GHA_SIGSTORE_PYTHON_OVERWRITE", "false") != "false":
7985
sigstore_python_args.append("--overwrite")
@@ -112,6 +118,10 @@ def _fatal_help(msg):
112118
for file_ in files:
113119
if not file_.is_file():
114120
_fatal_help(f"input {file_} does not look like a file")
121+
if "--output_certificate" not in sigstore_python_args:
122+
signing_artifact_paths.append(f"{file_}.crt")
123+
if "--output_signature" not in sigstore_python_args:
124+
signing_artifact_paths.append(f"{file_}.sig")
115125

116126
sigstore_python_args.extend(files)
117127

@@ -150,4 +160,24 @@ def _fatal_help(msg):
150160
"""
151161
)
152162

163+
# Now populate the `GHA_SIGSTORE_PYTHON_SIGNING_ARTIFACTS` environment variable
164+
# so that later steps know which files to upload as workflow artifacts.
165+
#
166+
# In GitHub Actions, environment variables can be made to persist across
167+
# workflow steps by appending to the file at `GITHUB_ENV`.
168+
if "--no-default-files" not in sigstore_python_args:
169+
with Path(os.getenv("GITHUB_ENV")).open("a") as gh_env:
170+
# Multiline values must match the following syntax:
171+
#
172+
# {name}<<{delimiter}
173+
# {value}
174+
# {delimiter}
175+
gh_env.write(
176+
"GHA_SIGSTORE_PYTHON_SIGNING_ARTIFACTS<<EOF"
177+
+ os.linesep
178+
+ os.linesep.join(signing_artifact_paths)
179+
+ os.linesep
180+
+ "EOF"
181+
)
182+
153183
sys.exit(status.returncode)

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ inputs:
5454
description: "use sigstore's staging instances, instead of the default production instances"
5555
required: false
5656
default: false
57+
upload-signing-artifacts:
58+
description: "upload all signing artifacts as workflow artifacts"
59+
required: false
60+
default: false
5761
internal-be-careful-debug:
5862
description: "run with debug logs (default false)"
5963
required: false
6064
default: false
65+
6166
runs:
6267
using: "composite"
6368
steps:
@@ -86,3 +91,9 @@ runs:
8691
GHA_SIGSTORE_PYTHON_STAGING: "${{ inputs.staging }}"
8792
GHA_SIGSTORE_PYTHON_INTERNAL_BE_CAREFUL_DEBUG: "${{ inputs.internal-be-careful-debug }}"
8893
shell: bash
94+
95+
- uses: actions/upload-artifact@v3
96+
if: ${{ inputs.upload-signing-artifacts == 'true' }}
97+
with:
98+
name: "signing-artifacts-${{ github.job }}"
99+
path: "${{ env.GHA_SIGSTORE_PYTHON_SIGNING_ARTIFACTS }}"

0 commit comments

Comments
 (0)