blob: e47d2274022ece495115bd6b86aeda80afbdee3d [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)
16function regenerateTrustedKeys() {
17 echo "regenerating list of trusted keys"
18 # regenerate metadata
19 # Need to run a clean build, https://github.com/gradle/gradle/issues/19228
Jeff Gastoneb3691e2022-04-21 12:34:52 -040020 runGradle --write-verification-metadata pgp,sha256 --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
41 # update file
42 cat "$WORK_DIR/old.head" "$WORK_DIR/new.middle" "$WORK_DIR/old.tail" > gradle/verification-metadata.xml
43
44 # remove temporary files
45 rm -rf "$WORK_DIR"
46 rm -rf gradle/verification-metadata.dryrun.xml
47}
48regenerateTrustedKeys
49
50# updates the keyring, including sorting entries and removing duplicates
51function regenerateKeyring() {
52 # a separate step from regenerating the verification metadata, https://github.com/gradle/gradle/issues/20138
53 echo "regenerating keyring"
Jeff Gastoneb3691e2022-04-21 12:34:52 -040054 runGradle --write-verification-metadata sha256 --export-keys --dry-run bOS
Jeff Gastona423cbc2022-03-09 18:50:05 -050055
56 echo "sorting keyring and removing duplicates"
57 # sort and unique the keyring
58 # https://github.com/gradle/gradle/issues/20140
59 # `sed 's/$/NEWLINE/g'` adds the word NEWLINE at the end of each line
60 # `tr -d '\n'` deletes the actual newlines
61 # `sed` again adds a newline at the end of each key, so each key is one line
62 # `sort` orders the keys deterministically
63 # `uniq` removes identical keys
64 # `sed 's/NEWLINE/\n/g'` puts the newlines back
65 cat gradle/verification-keyring-dryrun.keys \
66 | sed 's/$/NEWLINE/g' \
67 | tr -d '\n' \
68 | sed 's/\(-----END PGP PUBLIC KEY BLOCK-----\)/\1\n/g' \
69 | grep "END PGP PUBLIC KEY BLOCK" \
70 | sort \
71 | uniq \
72 | sed 's/NEWLINE/\n/g' \
73 > gradle/verification-keyring.keys
74
75 # remove unused files
76 rm -f gradle/verification-keyring-dryrun.gpg
77 rm -f gradle/verification-keyring-dryrun.keys
78 rm -f gradle/verification-metadata.dryrun.xml
79}
80regenerateKeyring
81
82echo
83echo "Done. Please check that these changes look correct ('git diff')"