blob: 8a08119ae17cc4e925546a1ec32b091ec8b20a48 [file] [log] [blame]
Jeff Gastona423cbc2022-03-09 18:50:05 -05001#!/bin/bash
2set -e
3
Jeff Gastoneb3691e2022-04-21 12:34:52 -04004function runGradle() {
Fred Sladkeybd439812022-05-25 10:59:27 -04005 kmpArgs="-Pandroidx.compose.multiplatformEnabled=true -Pandroidx.enabled.kmp.target.platforms=+native"
Jeff Gaston29e70d92022-05-10 13:12:55 -04006 echo running ./gradlew $kmpArgs "$@"
7 if ./gradlew $kmpArgs "$@"; then
8 echo succeeded: ./gradlew $kmpArgs "$@"
9 else
10 echo failed: ./gradlew $kmpArgs "$@"
11 return 1
12 fi
Jeff Gastoneb3691e2022-04-21 12:34:52 -040013}
14
Jeff Gastona423cbc2022-03-09 18:50:05 -050015# This script regenerates signature-related information (dependency-verification-metadata and keyring)
Jeff Gastonb038ffa2022-10-06 15:05:19 -040016function regenerateVerificationMetadata() {
17 echo "regenerating verification metadata and keyring"
Jeff Gastona423cbc2022-03-09 18:50:05 -050018 # regenerate metadata
19 # Need to run a clean build, https://github.com/gradle/gradle/issues/19228
Jeff Gastonb038ffa2022-10-06 15:05:19 -040020 runGradle --write-verification-metadata pgp,sha256 --export-keys --dry-run --clean bOS
Jeff Gastona423cbc2022-03-09 18:50:05 -050021 # extract and keep only the <trusted-keys> section
22 WORK_DIR=gradle/update-keys-temp
23 rm -rf "$WORK_DIR"
24 mkdir -p "$WORK_DIR"
25
26 # extract the middle of the new file, https://github.com/gradle/gradle/issues/18569
27 grep -B 10000 "<trusted-keys>" gradle/verification-metadata.dryrun.xml > "$WORK_DIR/new.head"
28 grep -A 10000 "</trusted-keys>" gradle/verification-metadata.dryrun.xml > "$WORK_DIR/new.tail"
29 numTopLines="$(cat "$WORK_DIR/new.head" | wc -l)"
30 numTopLinesPlus1="$(($numTopLines + 1))"
31 numBottomLines="$(cat "$WORK_DIR/new.tail" | wc -l)"
32 numLines="$(cat gradle/verification-metadata.dryrun.xml | wc -l)"
33 numMiddleLines="$(($numLines - $numTopLines - $numBottomLines))"
34 # also remove 'version=' lines, https://github.com/gradle/gradle/issues/20192
35 cat gradle/verification-metadata.dryrun.xml | tail -n "+$numTopLinesPlus1" | head -n "$numMiddleLines" | sed 's/ version="[^"]*"//' > "$WORK_DIR/new.middle"
36
37 # extract the top and bottom of the old file
38 grep -B 10000 "<trusted-keys>" gradle/verification-metadata.xml > "$WORK_DIR/old.head"
39 grep -A 10000 "</trusted-keys>" gradle/verification-metadata.xml > "$WORK_DIR/old.tail"
40
Jeff Gastonb038ffa2022-10-06 15:05:19 -040041 # update verification metadata file
Jeff Gastona423cbc2022-03-09 18:50:05 -050042 cat "$WORK_DIR/old.head" "$WORK_DIR/new.middle" "$WORK_DIR/old.tail" > gradle/verification-metadata.xml
43
Jeff Gastona423cbc2022-03-09 18:50:05 -050044 echo "sorting keyring and removing duplicates"
45 # sort and unique the keyring
46 # https://github.com/gradle/gradle/issues/20140
47 # `sed 's/$/NEWLINE/g'` adds the word NEWLINE at the end of each line
48 # `tr -d '\n'` deletes the actual newlines
49 # `sed` again adds a newline at the end of each key, so each key is one line
50 # `sort` orders the keys deterministically
51 # `uniq` removes identical keys
52 # `sed 's/NEWLINE/\n/g'` puts the newlines back
53 cat gradle/verification-keyring-dryrun.keys \
54 | sed 's/$/NEWLINE/g' \
55 | tr -d '\n' \
56 | sed 's/\(-----END PGP PUBLIC KEY BLOCK-----\)/\1\n/g' \
57 | grep "END PGP PUBLIC KEY BLOCK" \
58 | sort \
59 | uniq \
60 | sed 's/NEWLINE/\n/g' \
61 > gradle/verification-keyring.keys
62
Jeff Gastonb038ffa2022-10-06 15:05:19 -040063 # remove temporary files
64 rm -rf "$WORK_DIR"
Jeff Gastona423cbc2022-03-09 18:50:05 -050065 rm -f gradle/verification-keyring-dryrun.gpg
66 rm -f gradle/verification-keyring-dryrun.keys
67 rm -f gradle/verification-metadata.dryrun.xml
68}
Jeff Gastonb038ffa2022-10-06 15:05:19 -040069regenerateVerificationMetadata
Jeff Gastona423cbc2022-03-09 18:50:05 -050070
71echo
72echo "Done. Please check that these changes look correct ('git diff')"