Jeff Gaston | a423cbc | 2022-03-09 18:50:05 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
Jeff Gaston | eb3691e | 2022-04-21 12:34:52 -0400 | [diff] [blame] | 4 | function runGradle() { |
| 5 | kmpArgs="-Pandroidx.compose.multiplatformEnabled=true -Pandroidx.kmp.native.enabled=true" |
| 6 | ./gradlew $kmpArgs "$@" |
| 7 | } |
| 8 | |
Jeff Gaston | a423cbc | 2022-03-09 18:50:05 -0500 | [diff] [blame] | 9 | # This script regenerates signature-related information (dependency-verification-metadata and keyring) |
| 10 | function regenerateTrustedKeys() { |
| 11 | echo "regenerating list of trusted keys" |
| 12 | # regenerate metadata |
| 13 | # Need to run a clean build, https://github.com/gradle/gradle/issues/19228 |
Jeff Gaston | eb3691e | 2022-04-21 12:34:52 -0400 | [diff] [blame] | 14 | runGradle --write-verification-metadata pgp,sha256 --dry-run --clean bOS |
Jeff Gaston | a423cbc | 2022-03-09 18:50:05 -0500 | [diff] [blame] | 15 | # extract and keep only the <trusted-keys> section |
| 16 | WORK_DIR=gradle/update-keys-temp |
| 17 | rm -rf "$WORK_DIR" |
| 18 | mkdir -p "$WORK_DIR" |
| 19 | |
| 20 | # extract the middle of the new file, https://github.com/gradle/gradle/issues/18569 |
| 21 | grep -B 10000 "<trusted-keys>" gradle/verification-metadata.dryrun.xml > "$WORK_DIR/new.head" |
| 22 | grep -A 10000 "</trusted-keys>" gradle/verification-metadata.dryrun.xml > "$WORK_DIR/new.tail" |
| 23 | numTopLines="$(cat "$WORK_DIR/new.head" | wc -l)" |
| 24 | numTopLinesPlus1="$(($numTopLines + 1))" |
| 25 | numBottomLines="$(cat "$WORK_DIR/new.tail" | wc -l)" |
| 26 | numLines="$(cat gradle/verification-metadata.dryrun.xml | wc -l)" |
| 27 | numMiddleLines="$(($numLines - $numTopLines - $numBottomLines))" |
| 28 | # also remove 'version=' lines, https://github.com/gradle/gradle/issues/20192 |
| 29 | cat gradle/verification-metadata.dryrun.xml | tail -n "+$numTopLinesPlus1" | head -n "$numMiddleLines" | sed 's/ version="[^"]*"//' > "$WORK_DIR/new.middle" |
| 30 | |
| 31 | # extract the top and bottom of the old file |
| 32 | grep -B 10000 "<trusted-keys>" gradle/verification-metadata.xml > "$WORK_DIR/old.head" |
| 33 | grep -A 10000 "</trusted-keys>" gradle/verification-metadata.xml > "$WORK_DIR/old.tail" |
| 34 | |
| 35 | # update file |
| 36 | cat "$WORK_DIR/old.head" "$WORK_DIR/new.middle" "$WORK_DIR/old.tail" > gradle/verification-metadata.xml |
| 37 | |
| 38 | # remove temporary files |
| 39 | rm -rf "$WORK_DIR" |
| 40 | rm -rf gradle/verification-metadata.dryrun.xml |
| 41 | } |
| 42 | regenerateTrustedKeys |
| 43 | |
| 44 | # updates the keyring, including sorting entries and removing duplicates |
| 45 | function regenerateKeyring() { |
| 46 | # a separate step from regenerating the verification metadata, https://github.com/gradle/gradle/issues/20138 |
| 47 | echo "regenerating keyring" |
Jeff Gaston | eb3691e | 2022-04-21 12:34:52 -0400 | [diff] [blame] | 48 | runGradle --write-verification-metadata sha256 --export-keys --dry-run bOS |
Jeff Gaston | a423cbc | 2022-03-09 18:50:05 -0500 | [diff] [blame] | 49 | |
| 50 | echo "sorting keyring and removing duplicates" |
| 51 | # sort and unique the keyring |
| 52 | # https://github.com/gradle/gradle/issues/20140 |
| 53 | # `sed 's/$/NEWLINE/g'` adds the word NEWLINE at the end of each line |
| 54 | # `tr -d '\n'` deletes the actual newlines |
| 55 | # `sed` again adds a newline at the end of each key, so each key is one line |
| 56 | # `sort` orders the keys deterministically |
| 57 | # `uniq` removes identical keys |
| 58 | # `sed 's/NEWLINE/\n/g'` puts the newlines back |
| 59 | cat gradle/verification-keyring-dryrun.keys \ |
| 60 | | sed 's/$/NEWLINE/g' \ |
| 61 | | tr -d '\n' \ |
| 62 | | sed 's/\(-----END PGP PUBLIC KEY BLOCK-----\)/\1\n/g' \ |
| 63 | | grep "END PGP PUBLIC KEY BLOCK" \ |
| 64 | | sort \ |
| 65 | | uniq \ |
| 66 | | sed 's/NEWLINE/\n/g' \ |
| 67 | > gradle/verification-keyring.keys |
| 68 | |
| 69 | # remove unused files |
| 70 | rm -f gradle/verification-keyring-dryrun.gpg |
| 71 | rm -f gradle/verification-keyring-dryrun.keys |
| 72 | rm -f gradle/verification-metadata.dryrun.xml |
| 73 | } |
| 74 | regenerateKeyring |
| 75 | |
| 76 | echo |
| 77 | echo "Done. Please check that these changes look correct ('git diff')" |