Skip to content

Commit 124977e

Browse files
authored
Merge pull request #618 from sigstore/setup-release
Release to maven central (sigstore-java only)
2 parents 1e12b86 + 9cb1207 commit 124977e

File tree

3 files changed

+117
-133
lines changed

3 files changed

+117
-133
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Release sigstore-java to Maven Central
2+
on:
3+
workflow_dispatch:
4+
# user is expected to use a tag as the branch to run the action on
5+
6+
jobs:
7+
process-tag:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
version: ${{ steps.version.outputs.version }}
11+
steps:
12+
- name: checkout
13+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
14+
- name: process tag
15+
id: version
16+
run: |
17+
TAG=${{ github.ref_name }}
18+
echo "version=${TAG#"v"}" >> $GITHUB_OUTPUT
19+
- name: verify tag matches gradle version
20+
run: |
21+
set -Eeo pipefail
22+
version=$(grep "^version=" gradle.properties | cut -d'=' -f2)
23+
if [[ ! "$version" == "${{ steps.version.outputs.version }}" ]]; then
24+
echo "tagged version ${{ github.ref }} (as ${{ steps.version.outputs.version }}) does not match gradle.properties $version"
25+
exit 1
26+
fi
27+
28+
ci:
29+
needs: [process-tag]
30+
permissions:
31+
id-token: write # To run github oidc tests
32+
uses: ./.github/workflows/ci.yaml
33+
34+
build:
35+
permissions:
36+
id-token: write # To sign the artifacts
37+
runs-on: ubuntu-latest
38+
needs: [ci, process-tag]
39+
outputs:
40+
hashes: ${{ steps.hash.outputs.hashes }}
41+
steps:
42+
- name: checkout tag
43+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
44+
45+
- name: Set up JDK 11
46+
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
47+
with:
48+
java-version: 11
49+
distribution: 'temurin'
50+
51+
- name: Build, Sign and Release to Maven Central
52+
run: |
53+
./gradlew clean :sigstore-java:publishMavenJavaPublicationToSonatypeRepository -Prelease
54+
env:
55+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_PRIVATE_KEY }}
56+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PGP_PASSPHRASE }}
57+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
58+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
59+
60+
- name: SLSA -- Hash Artifacts
61+
id: hash
62+
run: |
63+
mkdir slsa-files
64+
cp sigstore-java/build/libs/*.jar slsa-files
65+
cp sigstore-java/build/publications/mavenJava/pom-default.xml slsa-files/sigstore-java-${{ needs.process-tag.outputs.version }}.pom
66+
cp sigstore-java/build/publications/mavenJava/module.json slsa-files/sigstore-java-${{ needs.process-tag.outputs.version }}.module
67+
cd slsa-files
68+
echo "hashes=$(sha256sum ./* | base64 -w0)" >> $GITHUB_OUTPUT
69+
70+
- name: Upload build artifacts
71+
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
72+
with:
73+
name: project-release-artifacts
74+
path: ./slsa-files
75+
if-no-files-found: error
76+
77+
provenance:
78+
needs: [build, process-tag]
79+
permissions:
80+
actions: read # To read the workflow path.
81+
id-token: write # To sign the provenance.
82+
contents: write # To add assets to a release.
83+
# use tags here: https://github.com/slsa-framework/slsa-github-generator#referencing-slsa-builders-and-generators
84+
# remember to update "Download Attestations" when SLSA updates to actions/download-artifact@v4
85+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
86+
with:
87+
provenance-name: "sigstore-java-${{ needs.process-tag.outputs.version }}.attestation.intoto.jsonl"
88+
base64-subjects: "${{ needs.build.outputs.hashes }}"
89+
90+
create-release-on-github:
91+
runs-on: ubuntu-latest
92+
needs: [provenance, build, process-tag]
93+
permissions:
94+
contents: write
95+
steps:
96+
- name: Download attestation
97+
# keep at v3.x since slsa generator uses 3.x (update this when slsa-framework updates)
98+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
99+
with:
100+
name: "${{ needs.provenance.outputs.attestation-name }}"
101+
path: ./release/
102+
- name: Download gradle release artifacts
103+
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
104+
with:
105+
name: project-release-artifacts
106+
path: ./release/
107+
- name: Create release
108+
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # tag=v0.1.15
109+
with:
110+
tag_name: v${{ needs.process-tag.outputs.version }}
111+
body: "See [CHANGELOG.md](https://github.com/${{ vars.GITHUB_REPOSITORY }}/blob/main/CHANGELOG.md) for more details."
112+
files: ./release/*

.github/workflows/tag-and-build-release.yaml

Lines changed: 0 additions & 110 deletions
This file was deleted.

build-logic/publishing/src/main/kotlin/build-logic.publish-to-central.gradle.kts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.gradle.api.publish.internal.PublicationInternal
2-
31
plugins {
42
id("java-library")
53
id("maven-publish")
@@ -61,27 +59,11 @@ publishing {
6159
}
6260
}
6361
}
64-
}
65-
66-
val createReleaseBundle by tasks.registering(Sync::class) {
67-
description = "This task should be used by github actions to create release artifacts along with a slsa attestation"
68-
val releaseDir = layout.buildDirectory.dir("release")
69-
outputs.dir(releaseDir)
70-
71-
into(releaseDir)
72-
rename("pom-default.xml", "${project.name}-${project.version}.pom")
73-
rename("module.json", "${project.name}-${project.version}.module")
74-
}
75-
76-
publishing {
77-
publications.configureEach {
78-
(this as PublicationInternal<*>).allPublishableArtifacts {
79-
val publicationArtifact = this
80-
createReleaseBundle.configure {
81-
dependsOn(publicationArtifact)
82-
from(publicationArtifact.file)
83-
}
62+
repositories {
63+
maven {
64+
name = "sonatype"
65+
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
66+
credentials(PasswordCredentials::class)
8467
}
8568
}
8669
}
87-

0 commit comments

Comments
 (0)