-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(ci): add slsa provenance for release artifacts #263
Merged
melix
merged 4 commits into
micronaut-projects:master
from
behnazh-w:add-slsa-provenance
Sep 28, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6c87b6b
feat(ci): add slsa provenance for release artifacts
behnazh-w 29ffa13
chore: collect artifacts from local build repository
behnazh-w 8938a2b
chore: package all the artifacts into a single ZIP file
behnazh-w 9754e69
chore: add .module and .toml files to artifacts
behnazh-w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ on: | |
types: [published] | ||
jobs: | ||
release: | ||
outputs: | ||
hashes: ${{ steps.hash.outputs.hashes }} # Computed hashes for build artifacts. | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
|
@@ -31,6 +33,7 @@ jobs: | |
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Publish to Sonatype OSSRH | ||
id: publish | ||
env: | ||
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | ||
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
|
@@ -42,7 +45,30 @@ jobs: | |
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} | ||
run: | | ||
echo $GPG_FILE | base64 -d > secring.gpg | ||
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository | ||
# Publish both locally and to Sonatype. | ||
# The artifacts stored locally will be used to generate the SLSA provenance. | ||
./gradlew publishAllPublicationsToBuildRepository publishToSonatype closeAndReleaseSonatypeStagingRepository | ||
# Read the current version from gradle.properties. | ||
VERSION=$(./gradlew properties | grep 'version:' | awk '{print $2}') | ||
# Read the project group from gradle.properties. | ||
GROUP_PATH=$(./gradlew properties| grep "projectGroup" | awk '{print $2}' | sed 's/\./\//g') | ||
echo "::set-output name=version::$VERSION" | ||
echo "::set-output name=group::$GROUP_PATH" | ||
- name: Generate subject | ||
id: hash | ||
run: | | ||
# Find the relevant published artifacts in the local repository. | ||
ARTIFACTS=$(find build/repo/${{ steps.publish.outputs.group }}/*/${{ steps.publish.outputs.version }}/* \ | ||
-regextype sed -regex '\(.*\.jar\|.*\.pom\|.*\.module\|.*\.toml\)') | ||
# Compute the hashes for the artifacts. | ||
echo "::set-output name=hashes::$(sha256sum $ARTIFACTS | base64 -w0)" | ||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 | ||
with: | ||
name: gradle-build-outputs | ||
path: build/repo/${{ steps.publish.outputs.group }}/*/${{ steps.publish.outputs.version }}/* | ||
if-no-files-found: error | ||
retention-days: 5 | ||
- name: Generate docs | ||
env: | ||
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} | ||
|
@@ -86,3 +112,36 @@ jobs: | |
MICRONAUT_BUILD_EMAIL: ${{ secrets.MICRONAUT_BUILD_EMAIL }} | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
provenance: | ||
needs: [release] | ||
permissions: | ||
actions: read # To read the workflow path. | ||
id-token: write # To sign the provenance. | ||
contents: write # To add assets to a release. | ||
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | ||
with: | ||
base64-subjects: "${{ needs.release.outputs.hashes }}" | ||
upload-assets: true # Upload to a new release | ||
|
||
github_release: | ||
needs: [release, provenance] | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/tags/') | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 | ||
- name: Download artifacts | ||
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v3.0.0 | ||
with: | ||
name: gradle-build-outputs | ||
path: build/repo | ||
- name: Upload assets | ||
# Upload the artifacts and SLSA L3 provenance as assets to the existing | ||
# release. Note that the provenance will attest to each artifact file and | ||
# not the aggregated ZIP file. | ||
run: | | ||
find build/repo -regextype sed -regex '\(.*\.jar\|.*\.pom\|.*\.module\|.*\.toml\)' | xargs zip artifacts.zip | ||
gh release upload ${{ github.ref_name }} artifacts.zip | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be wrong, but I think that if you use the
publishToBuildRepository
task, then you don't need to search for the group or version anymore, and you can use thebuild/repo
directory as the upload source for GH.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to read the group because I need to resolve the path to the artifacts for uploading them as artifacts. The path can be different in different repositories that use this template.
I read the version just to make sure the artifacts are collected from the right path, but that is just to be extra cautious.