Skip to content

Commit cbf0f5b

Browse files
authored
Add release script (#43)
- Can download a release and sign with sigstore/pgp, generate hashes and bundle up for release - Releaser can upload this bundle directly to maven central Signed-off-by: Appu Goundan <[email protected]> Signed-off-by: Appu Goundan <[email protected]>
1 parent 57e35a7 commit cbf0f5b

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

java/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ A jar file will be created at `./build/libs/protobuf-specs-<version>.jar`
1212

1313
## Releasing
1414

15+
### Generate Release artifacts
1516
1. On creation of a tag in the style `release/java/v1.2.3`, new artifacts will be built and
1617
uploaded to a github release `release/java/v1.2.3`
17-
2. TODO: Explain how a releaser can then complete the release process on their machine by signing
18-
with pgp and uploading to maven central.
18+
1. Once a release is created, check it and remove the draft label on the github release page.
19+
1. On a machine with your pgp key, `gpg`, `bash` and `cosign`, go to `protobuf-specs/java/scripts`
20+
1. Run `./sign_and_bundle_release.sh v1.2.3` to generate a release bundle for `release/java/v1.2.3`
21+
22+
### Publish on Maven Central
23+
1. Log into https://s01.oss.sonatype.org with credentials that have permissions to upload to `dev.sigstore`
24+
1. Take the release bundle, `release_java_v1.2.3/protobuf-specs-1.2.3-bundle.jar` and upload via the `Staging Upload -> (Upload Mode) Artifact Bundle`
25+
1. Once the bundle is validated and checked, release it via `Staging Repositories`, if any issues occur, drop it and fix the issues before restarting the release process.
26+
27+
## How do I get permissions to upload to Maven Central
28+
29+
- Create an account: https://central.sonatype.org/publish/publish-guide/
30+
- Request permissions to publish to dev.sigstore on JIRA ([example](https://issues.sonatype.org/browse/OSSRH-83556)) and get [Bob](https://github.com/bobcallaway) (or [Appu](https://github.com/loosebazooka) to signoff on it.
1931

2032
## Why is the gradle wrapper jar checked in?
2133

java/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ plugins {
77
id("com.diffplug.spotless") version "6.11.0"
88
}
99

10+
description = "Code generated library for the Sigstore bundle format protobufs"
11+
1012
sourceSets {
1113
main {
1214
proto {

java/scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
release_*/
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
REQUIRED_PROGRAMS=("gpg" "cosign" "jq" "curl" "wget" "md5sum" "sha1sum" "sha256sum" "sha512sum" "jar")
5+
6+
usage() {
7+
echo -e "Usage: $0 \e[4mVERSION\e[0m"
8+
echo -e "\e[4mVERSION\e[0m is part of the tag release/java/<version>, ex v1.0.0"
9+
echo -e "Requires" "${REQUIRED_PROGRAMS[@]}"
10+
}
11+
12+
main() {
13+
# accepts exactly one arg
14+
if [ $# -ne 1 ];
15+
then
16+
usage "$@"
17+
exit 1
18+
fi
19+
20+
RELEASE_TAG=$1
21+
22+
# check is all required programs are available on system
23+
for i in "${REQUIRED_PROGRAMS[@]}"
24+
do
25+
command -v "$i" >/dev/null 2>&1 || {
26+
echo -e "required program $i was not found" >&2
27+
usage "$@"
28+
exit 1
29+
}
30+
done
31+
32+
# download release from github
33+
echo "Downloading release release/java/${1} from github"
34+
RELEASE_REPO="sigstore/protobuf-specs"
35+
RELEASE_URL="https://api.github.com/repos/${RELEASE_REPO}/releases/tags/release/java/${RELEASE_TAG}"
36+
RELEASE_INFO=$(curl -s -H "Accept: application/vnd.github+json" "${RELEASE_URL}")
37+
RELEASE_VERSION="$(echo "$RELEASE_INFO" | jq -r '.tag_name')"
38+
39+
if [ "null" == "$RELEASE_VERSION" ]; then
40+
echo "ERROR: could not parse tag_name from release info"
41+
echo "$RELEASE_INFO"
42+
exit 1
43+
fi
44+
45+
RELEASE_DIR="${RELEASE_VERSION//\//_}"
46+
47+
echo "Release version is: ${RELEASE_VERSION}"
48+
49+
if [ -d "$RELEASE_DIR" ]; then
50+
echo "Directory '$RELEASE_DIR' already exists"
51+
exit 1
52+
fi
53+
54+
# query the json for all the release assets
55+
readarray -t ASSET_URLS < <(echo "$RELEASE_INFO" | jq -r '.assets[].browser_download_url')
56+
57+
echo "Downloading release artifacts"
58+
for i in "${ASSET_URLS[@]}"
59+
do
60+
echo "$i"
61+
wget -q --directory-prefix "$RELEASE_DIR" "$i"
62+
done
63+
cd "$RELEASE_DIR"
64+
65+
# cosign sign all the files
66+
echo "Signing with cosign"
67+
for file in *; do
68+
# skip intoto attestations, they are already signed
69+
if [[ "$file" == *.intoto.jsonl ]] ; then
70+
continue;
71+
fi
72+
COSIGN_EXPERIMENTAL=1 cosign sign-blob --yes "$file" --output-signature="$file.sig" --output-certificate="$file.pem" --bundle "$file.bundle"
73+
done
74+
75+
# then gpg sign all the files (including sigstore files)
76+
# this command uses gpgs default password acceptance mechansim accept a passcode
77+
echo "Signing with gpg"
78+
for file in *; do
79+
gpg --batch --detach-sign --armor -o "$file.asc" "$file"
80+
done
81+
82+
echo "Generating checksums"
83+
for file in *; do
84+
md5sum "$file" | cut -c -32 | tr -d '\n' > "$file.md5"
85+
sha1sum "$file" | cut -c -40 | tr -d '\n' > "$file.sha1"
86+
sha256sum "$file" | cut -c -64 | tr -d '\n' > "$file.sha256"
87+
sha512sum "$file" | cut -c -128 | tr -d '\n' > "$file.sha512"
88+
done
89+
90+
# create a maven central compatible bundle jar
91+
echo "Creating maven bundle"
92+
POM=$(ls ./*.pom)
93+
BUNDLE_NAME=${POM%.pom}-bundle.jar
94+
jar -cvf "${BUNDLE_NAME}" ./*
95+
96+
echo "Upload $(realpath "$BUNDLE_NAME") to maven central (https://s01.oss.sonatype.org)"
97+
}
98+
99+
main "$@"

0 commit comments

Comments
 (0)