-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add provenance instruction for maven and gradle #573
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ project simply generates provenance as a separate step in an existing workflow. | |
- [Integration With Other Build Systems](#integration-with-other-build-systems) | ||
- [Provenance for GoReleaser](#provenance-for-goreleaser) | ||
- [Provenance for Bazel](#provenance-for-bazel) | ||
- [Provenance for Java](#provenance-for-java) | ||
|
||
--- | ||
|
||
|
@@ -424,3 +425,157 @@ jobs: | |
base64-subjects: "${{ needs.build.outputs.hashes }}" | ||
upload-assets: true # upload to a new release | ||
``` | ||
|
||
### Provenance for Java | ||
|
||
If you develop with Java and use [Maven](#maven) or [Gradle](#gradle), you can | ||
easily generate SLSA3 provenance by updating your existing workflow with the | ||
steps indicated in the workflow below: | ||
|
||
#### Maven | ||
``` | ||
jobs: | ||
build: | ||
# ================================================== | ||
# | ||
# Step 1: Declare an `outputs` for the artifacts generated by | ||
# the build and their hashes. | ||
# | ||
# ================================================== | ||
outputs: | ||
artifacts: ${{ steps.build.outputs.artifacts }} | ||
hashes: ${{ steps.hash.outputs.hashes }} | ||
|
||
[...] | ||
|
||
steps: | ||
[...] | ||
- name: Build using maven | ||
# ================================================= | ||
# | ||
# Step 2: Add an `id: build` field | ||
# to your maven build step. | ||
# | ||
# ================================================= | ||
id: build | ||
run: | | ||
# Your normal build workflow targets here | ||
mvn clean package | ||
|
||
# ====================================================== | ||
# | ||
# Step 3: Save the location of the maven output files | ||
# for easier reference | ||
# | ||
# ===================================================== | ||
ARTIFACT_PATTERN=./target/$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)*.jar | ||
echo "::set-output name=artifact_pattern::$ARTIFACT_PATTERN" | ||
|
||
# ======================================================== | ||
# | ||
# Step 4: Add a step to generate the provenance subjects | ||
# as shown below. Update the sha256 sum arguments | ||
# to include all binaries that you generate | ||
# provenance for. | ||
# | ||
# ======================================================== | ||
- name: Generate subject | ||
id: hash | ||
run: | | ||
echo "::set-output name=hashes::$(sha256sum ${{ steps.build.outputs.artifact_pattern }} | base64 -w0)" | ||
|
||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0 | ||
with: | ||
name: maven-build-outputs | ||
path: ${{ steps.build.outputs.artifact_pattern }} | ||
if-no-files-found: error | ||
|
||
# ========================================================= | ||
# | ||
# Step 5: Call the generic workflow to generate provenance | ||
# by declaring the job below. | ||
# | ||
# ========================================================= | ||
provenance: | ||
needs: [build] | ||
permissions: | ||
actions: read | ||
id-token: write | ||
contents: read | ||
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | ||
with: | ||
base64-subjects: "${{ needs.build.outputs.hashes }}" | ||
# TODO: uncomment when ready | ||
# upload-assets: true # upload to a new release | ||
``` | ||
|
||
#### Gradle | ||
``` | ||
jobs: | ||
build: | ||
# ================================================== | ||
# | ||
# Step 1: Declare an `outputs` for the artifacts generated by | ||
# the build and their hashes. | ||
# | ||
# ================================================== | ||
outputs: | ||
hashes: ${{ steps.hash.outputs.hashes }} | ||
|
||
[...] | ||
|
||
steps: | ||
[...] | ||
- name: Build using gradle | ||
# ================================================= | ||
# | ||
# Step 2: Add an `id: build` field | ||
# to your gradle build step. | ||
# | ||
# ================================================= | ||
id: build | ||
run: | | ||
# Your normal build workflow targets here | ||
./gradlew clean build | ||
|
||
# ======================================================== | ||
# | ||
# Step 4: Add a step to generate the provenance subjects | ||
# as shown below. Update the sha256 sum arguments | ||
# to include all binaries that you generate | ||
# provenance for. | ||
# This build assumes build artifacts are saved | ||
# in ./build/libs | ||
# | ||
# ======================================================== | ||
- name: Generate subject | ||
id: hash | ||
run: | | ||
echo "::set-output name=hashes::$(sha256sum ./build/libs/* | base64 -w0)" | ||
|
||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0 | ||
with: | ||
name: gradle-build-outputs | ||
path: ./build/libs/ | ||
if-no-files-found: error | ||
|
||
# ========================================================= | ||
# | ||
# Step 5: Call the generic workflow to generate provenance | ||
# by declaring the job below. | ||
# | ||
# ========================================================= | ||
provenance: | ||
needs: [build] | ||
permissions: | ||
actions: read | ||
id-token: write | ||
contents: read | ||
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | ||
with: | ||
base64-subjects: "${{ needs.build.outputs.hashes }}" | ||
# TODO: uncomment when ready | ||
# upload-assets: true # upload to a new release | ||
``` |
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.
This is an optional step correct? Only needed if we want to later upload to the results for the release.
Fine for this PR, just want to be sure.