Skip to content

Conversation

@jmgate
Copy link
Collaborator

@jmgate jmgate commented Jul 16, 2025

Type: Task

Description

See sandialabs/reverse_argparse#315.

Summary by Sourcery

Integrate SLSA provenance generation into the release pipeline by restructuring the semantic-release workflow into separate release, provenance, and publish jobs with artifact hashing, uploading, runner hardening, and cleanup steps.

New Features:

  • Generate and attach SLSA provenance for release assets using slsa-framework’s generic SLSA 3 workflow.

Enhancements:

  • Restructure semantic-release workflow into distinct release, provenance, and publish jobs with artifact hashing and uploading.
  • Harden runners and clean up provenance files before publishing to PyPI.

CI:

  • Add concurrency group for release workflows.
  • Update GitHub Actions semantic-release.yml to orchestrate release, provenance generation, and publishing steps.

See https://slsa.dev/ for motivation.

Creating a patch release to ensure these additions to the automated
release process work.

Note that the `release` job has been subdivided, because the SLSA
provenance reusable workflow cannot be used as a step within a job, but
must be used as a job on its own.
@jmgate jmgate self-assigned this Jul 16, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 16, 2025

Reviewer's Guide

This PR refactors the semantic-release GitHub Actions workflow to centralize concurrency, compute and upload artifact hashes, generate SLSA provenance attestations, and introduce a dedicated publish job that hardens the runner, aggregates artifacts and provenance, and publishes to GitHub Releases and PyPI.

Flow diagram for the new release and publish process

flowchart TD
  Start([Start]) --> Release[Release Job]
  Release -->|If released| Hash[Hash Build Artifacts]
  Hash --> Upload[Upload Build Artifacts]
  Upload --> Provenance[Provenance Job]
  Provenance --> Publish[Publish Job]
  Publish -->|Download Artifacts & Provenance| Aggregate[Aggregate Artifacts]
  Aggregate -->|Remove Provenance for PyPI| Clean[Clean Artifacts]
  Clean -->|Publish| GitHub[GitHub Releases]
  Clean -->|Publish| PyPI[PyPI]
  GitHub --> End([End])
  PyPI --> End
Loading

File-Level Changes

Change Details Files
Centralized workflow concurrency handling
  • Added top-level concurrency group for 'release'
  • Removed per-job 'concurrency: release' directive
.github/workflows/semantic-release.yml
Enhanced release job to hash and upload build artifacts
  • Inserted 'Hash Build Artifacts' step to compute SHA256 hashes
  • Added 'Upload Build Artifacts' step using actions/upload-artifact
  • Exposed hashes and release status as job outputs
.github/workflows/semantic-release.yml
Added provenance generation job using SLSA framework
  • Created 'provenance' job that runs generator_generic_slsa3 workflow
  • Passed base64-encoded artifact hashes into the provenance workflow
  • Configured job-level permissions for actions, id-token, and contents
.github/workflows/semantic-release.yml
Introduced dedicated publish job for hardened publishing
  • Added 'publish' job dependent on release and provenance success
  • Hardened runner using step-security/harden-runner
  • Checked out repo with full history and downloaded artifacts/provenance
  • Published to GitHub Releases, removed provenance from dist, and published to PyPI
.github/workflows/semantic-release.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jmgate - I've reviewed your changes - here's some feedback:

  • In the provenance job, explicitly upload the generated provenance file (e.g. with actions/upload-artifact) so that the publish job’s download-artifact step can reliably fetch it.
  • Add a validation step in the publish job to verify the downloaded provenance file matches the computed artifact hashes before publishing to ensure integrity.
  • Consider parameterizing the artifact and provenance filenames/paths (instead of hardcoding in rm -f) to make future workflow updates less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the provenance job, explicitly upload the generated provenance file (e.g. with actions/upload-artifact) so that the publish job’s download-artifact step can reliably fetch it.
- Add a validation step in the publish job to verify the downloaded provenance file matches the computed artifact hashes before publishing to ensure integrity.
- Consider parameterizing the artifact and provenance filenames/paths (instead of hardcoding in rm -f) to make future workflow updates less error-prone.

## Individual Comments

### Comment 1
<location> `.github/workflows/semantic-release.yml:42` </location>
<code_context>

-    - name: Publish to PyPI
-      uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
+    - name: Hash Build Artifacts
+      if: steps.release.outputs.released == 'true'
+      id: hash
+      run: |
+        cd dist
+        echo "hashes=$(find . -type f -exec sha256sum {} + | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"
+
+    - name: Upload Build Artifacts
</code_context>

<issue_to_address>
The artifact hashing step may not be robust to non-ASCII filenames or large numbers of files.

Using `find . -type f -exec sha256sum {} + | sort | base64` may not handle filenames with spaces, newlines, or non-ASCII characters correctly. Consider `find . -type f -print0 | xargs -0 sha256sum` for better robustness. Also, be aware of potential command limits with very large file counts.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        echo "hashes=$(find . -type f -exec sha256sum {} + | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"
=======
        echo "hashes=$(find . -type f -print0 | xargs -0 sha256sum | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

id: hash
run: |
cd dist
echo "hashes=$(find . -type f -exec sha256sum {} + | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The artifact hashing step may not be robust to non-ASCII filenames or large numbers of files.

Using find . -type f -exec sha256sum {} + | sort | base64 may not handle filenames with spaces, newlines, or non-ASCII characters correctly. Consider find . -type f -print0 | xargs -0 sha256sum for better robustness. Also, be aware of potential command limits with very large file counts.

Suggested change
echo "hashes=$(find . -type f -exec sha256sum {} + | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"
echo "hashes=$(find . -type f -print0 | xargs -0 sha256sum | sort | base64 | tr -d '\n')" >> "$GITHUB_OUTPUT"

@codecov
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6ed94c3) to head (9050760).
⚠️ Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          176       176           
  Branches        15        15           
=========================================
  Hits           176       176           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jmgate jmgate merged commit e4c75df into master Jul 16, 2025
14 checks passed
@jmgate jmgate deleted the add-slsa-provenance branch July 16, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants