9
9
types : [published]
10
10
jobs :
11
11
release :
12
+ outputs :
13
+ artifacts-sha256 : ${{ steps.hash.outputs.artifacts-sha256 }} # Computed hashes for build artifacts.
12
14
runs-on : ubuntu-latest
13
15
steps :
14
16
- name : Checkout repository
@@ -19,18 +21,19 @@ jobs:
19
21
- name : Set up JDK
20
22
uses : actions/setup-java@v3
21
23
with :
22
- distribution : ' adopt'
23
24
java-version : ' 11'
25
+ distribution : ' temurin'
24
26
- name : Set the current release version
25
27
id : release_version
26
- run : echo ::set-output name= release_version:: ${GITHUB_REF:11}
28
+ run : echo " release_version= ${GITHUB_REF:11}" >> $GITHUB_OUTPUT
27
29
- name : Run pre-release
28
30
uses : micronaut-projects/github-actions/pre-release@master
29
31
env :
30
32
MICRONAUT_BUILD_EMAIL : ${{ secrets.MICRONAUT_BUILD_EMAIL }}
31
33
with :
32
34
token : ${{ secrets.GITHUB_TOKEN }}
33
35
- name : Publish to Sonatype OSSRH
36
+ id : publish
34
37
env :
35
38
SONATYPE_USERNAME : ${{ secrets.SONATYPE_USERNAME }}
36
39
SONATYPE_PASSWORD : ${{ secrets.SONATYPE_PASSWORD }}
@@ -42,13 +45,46 @@ jobs:
42
45
GRADLE_ENTERPRISE_CACHE_PASSWORD : ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
43
46
run : |
44
47
echo $GPG_FILE | base64 -d > secring.gpg
45
- ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
48
+ # Publish both locally and to Sonatype.
49
+ # The artifacts stored locally will be used to generate the SLSA provenance.
50
+ ./gradlew publishAllPublicationsToBuildRepository publishToSonatype closeAndReleaseSonatypeStagingRepository
51
+ # Read the current version from gradle.properties.
52
+ VERSION=$(./gradlew properties | grep 'version:' | awk '{print $2}')
53
+ # Read the project group from gradle.properties.
54
+ GROUP_PATH=$(./gradlew properties| grep "projectGroup" | awk '{print $2}' | sed 's/\./\//g')
55
+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
56
+ echo "group=$GROUP_PATH" >> "$GITHUB_OUTPUT"
57
+ - name : Generate subject
58
+ id : hash
59
+ run : |
60
+ # Find the relevant published artifacts in the local repository.
61
+ ARTIFACTS=$(find build/repo/${{ steps.publish.outputs.group }}/*/${{ steps.publish.outputs.version }}/* \
62
+ -regextype sed -regex '\(.*\.jar\|.*\.pom\|.*\.module\|.*\.toml\)')
63
+ # Compute the hashes for the artifacts.
64
+ # Set the hash as job output for debugging.
65
+ echo "artifacts-sha256=$(sha256sum $ARTIFACTS | base64 -w0)" >> "$GITHUB_OUTPUT"
66
+ # Store the hash in a file, which is uploaded as a workflow artifact.
67
+ echo $(sha256sum $ARTIFACTS | base64 -w0) > artifacts-sha256
68
+ - name : Upload build artifacts
69
+ uses : actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
70
+ with :
71
+ name : gradle-build-outputs
72
+ path : build/repo/${{ steps.publish.outputs.group }}/*/${{ steps.publish.outputs.version }}/*
73
+ retention-days : 5
74
+ - name : Upload artifacts-sha256
75
+ uses : actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
76
+ with :
77
+ name : artifacts-sha256
78
+ path : artifacts-sha256
79
+ retention-days : 5
46
80
- name : Generate docs
81
+ run : ./gradlew docs
47
82
env :
48
83
GRADLE_ENTERPRISE_ACCESS_KEY : ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
49
84
GRADLE_ENTERPRISE_CACHE_USERNAME : ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
50
85
GRADLE_ENTERPRISE_CACHE_PASSWORD : ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
51
- run : ./gradlew docs
86
+ GH_TOKEN_PUBLIC_REPOS_READONLY : ${{ secrets.GH_TOKEN_PUBLIC_REPOS_READONLY }}
87
+ GH_USERNAME : ${{ secrets.GH_USERNAME }}
52
88
- name : Export Gradle Properties
53
89
uses : micronaut-projects/github-actions/export-gradle-properties@master
54
90
- name : Publish to Github Pages
@@ -86,3 +122,57 @@ jobs:
86
122
MICRONAUT_BUILD_EMAIL : ${{ secrets.MICRONAUT_BUILD_EMAIL }}
87
123
with :
88
124
token : ${{ secrets.GITHUB_TOKEN }}
125
+
126
+ provenance-subject :
127
+ needs : [release]
128
+ runs-on : ubuntu-latest
129
+ outputs :
130
+ artifacts-sha256 : ${{ steps.set-hash.outputs.artifacts-sha256 }}
131
+ steps :
132
+ - name : Download artifacts-sha256
133
+ uses : actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
134
+ with :
135
+ name : artifacts-sha256
136
+ # The SLSA provenance generator expects the hash digest of artifacts to be passed as a job
137
+ # output. So we need to download the artifacts-sha256 and set it as job output. The hash of
138
+ # the artifacts should be set as output directly in the release job. But due to a known bug
139
+ # in GitHub Actions we have to use a workaround.
140
+ # See https://github.com/community/community/discussions/37942.
141
+ - name : Set artifacts-sha256 as output
142
+ id : set-hash
143
+ shell : bash
144
+ run : echo "artifacts-sha256=$(cat artifacts-sha256)" >> "$GITHUB_OUTPUT"
145
+
146
+ provenance :
147
+ needs : [release, provenance-subject]
148
+ permissions :
149
+ actions : read # To read the workflow path.
150
+ id-token : write # To sign the provenance.
151
+ contents : write # To add assets to a release.
152
+ uses :
slsa-framework/slsa-github-generator/.github/workflows/[email protected]
153
+ with :
154
+ base64-subjects : " ${{ needs.provenance-subject.outputs.artifacts-sha256 }}"
155
+ upload-assets : true # Upload to a new release.
156
+ compile-generator : true # Build the generator from source.
157
+
158
+ github_release :
159
+ needs : [release]
160
+ runs-on : ubuntu-latest
161
+ if : startsWith(github.ref, 'refs/tags/')
162
+ steps :
163
+ - name : Checkout repository
164
+ uses : actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
165
+ - name : Download artifacts
166
+ uses : actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1
167
+ with :
168
+ name : gradle-build-outputs
169
+ path : build/repo
170
+ - name : Upload assets
171
+ # Upload the artifacts and SLSA L3 provenance as assets to the existing
172
+ # release. Note that the provenance will attest to each artifact file and
173
+ # not the aggregated ZIP file.
174
+ run : |
175
+ find build/repo -regextype sed -regex '\(.*\.jar\|.*\.pom\|.*\.module\|.*\.toml\)' | xargs zip artifacts.zip
176
+ gh release upload ${{ github.ref_name }} artifacts.zip
177
+ env :
178
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments