Skip to content

Commit b3c6899

Browse files
authored
Migrate to a CI build with SLSA provenance (#896)
Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
1 parent c248281 commit b3c6899

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This workflow publishes a new release to Maven central.
2+
#
3+
# The release MUST be initiated by running the release.sh script. That script will run
4+
# ./mvnw release:prepare and make the necessary changes for this workflow to then take
5+
# over and perform the actual release.
6+
7+
name: Publish new release
8+
on:
9+
push:
10+
tags:
11+
- "*"
12+
- "!*.pr*"
13+
- "!*b"
14+
15+
jobs:
16+
release:
17+
runs-on: "ubuntu-20.04"
18+
env:
19+
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
20+
TAG: ${{ github.ref_name }}
21+
outputs:
22+
hash: ${{ steps.hash.outputs.hash }}
23+
artifact_name: ${{ steps.hash.outputs.artifact_name }}
24+
steps:
25+
- name: Validate version name
26+
run: |
27+
[[ "$TAG" =~ jackson-core-[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)? ]] || exit 1
28+
- uses: actions/checkout@v3
29+
- name: Set up JDK
30+
uses: actions/setup-java@v3
31+
with:
32+
distribution: "temurin"
33+
java-version: "8"
34+
cache: "maven"
35+
server-id: sonatype-nexus-staging
36+
server-username: CI_DEPLOY_USERNAME
37+
server-password: CI_DEPLOY_PASSWORD
38+
# See https://github.com/actions/setup-java/blob/v2/docs/advanced-usage.md#Publishing-using-Apache-Maven
39+
# gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
40+
# gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
41+
- name: Perform release
42+
# The following command will only succeed if the preparation was done via the
43+
# release.sh script.
44+
run: ./mvnw -B -q -ff -ntp release:perform -DlocalCheckout=true
45+
- name: Generate hash
46+
id: hash
47+
run: |
48+
ARTIFACT_NAME="$( \
49+
./mvnw help:evaluate \
50+
-Dexpression=project.artifactId -q -DforceStdout)-$( \
51+
./mvnw help:evaluate \
52+
-Dexpression=project.version -q -DforceStdout)"
53+
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
54+
55+
cd ./target
56+
echo "hash=$( \
57+
sha256sum $ARTIFACT_NAME*.jar | \
58+
base64 -w0 \
59+
)" >> "$GITHUB_OUTPUT"
60+
61+
provenance:
62+
needs: [release]
63+
permissions:
64+
actions: read # To read the workflow path.
65+
id-token: write # To sign the provenance.
66+
contents: write # To add assets to a release.
67+
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.4.0
68+
with:
69+
base64-subjects: "${{ needs.release.outputs.hash }}"
70+
provenance-name: "${{ needs.release.outputs.artifact_name }}.jar.intoto.jsonl"
71+
upload-assets: true # Optional: Upload to a new release

release.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# This script simulates the Maven Release Plugin, but only performs
4+
# release:clean and release:prepare. The release:perform step is handled by the
5+
# CI when the tag is pushed.
6+
#
7+
# However, release:perform on Git requires the release.properties file. We must
8+
# therefore modify the first commit created by release:prepare to include this
9+
# file, and then delete the file in the second commit.
10+
#
11+
# This will ensure that release.properties is available to release:perform in
12+
# the CI, while keeping with the expectation that this file does not get
13+
# commited (long-term) to the repository.
14+
15+
set -euo pipefail
16+
17+
# Prepare but don't push, we'll need to modify the commits
18+
./mvnw release:clean release:prepare -DpushChanges=false
19+
20+
# Step back to the first commit (from SNAPSHOT to release)
21+
git reset HEAD~1
22+
23+
# delete tag created by release:prepare
24+
tag_name="$(git tag --points-at)"
25+
git tag -d "$tag_name"
26+
27+
# Add release.properties to that commit
28+
git add release.properties
29+
git commit --amend --no-edit
30+
31+
# recreate tag
32+
git tag "$tag_name" -m "[maven-release-plugin] copy for tag $tag_name"
33+
34+
# Recreate second commit (from release to SNAPSHOT), removing
35+
# release.properties from the repository
36+
git rm release.properties
37+
git add pom.xml
38+
git commit -m "[maven-release-plugin] prepare for next development iteration"
39+
40+
# push everything
41+
git push
42+
git push origin "$tag_name"
43+
44+
# clean up
45+
rm pom.xml.releaseBackup

0 commit comments

Comments
 (0)