|
| 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