blob: a0487f39b7e5423ce376483aa1aca4371e9ef028 [file] [log] [blame]
Jeff Gastona423cbc2022-03-09 18:50:05 -05001#!/bin/bash
2set -e
3
Jeff Gaston1d93a522023-08-29 14:24:51 -04004# This script updates trust entries in gradle/verification-metadata.xml
5
6# Usage: $0 [--no-dry-run] [<task>]
7
8# --no-dry-run
9# Don't pass --dry-run to Gradle, so Gradle executes the corresponding tasks.
10# This is not normally necessary but in some cases can be a useful workaround.
11# When https://github.com/gradle/gradle/issues/26289 is resolved, we should reevaluate this behavior
12#
13# <task>
14# The task to ask Gradle to run. By default this is 'bOS'
15# When --no-dry-run is removed, we should reevaluate this behavior
16
17dryrun=true
18task="bOS"
19
20while [ "$1" != "" ]; do
21 arg="$1"
22 shift
23 if [ "$arg" == "--no-dry-run" ]; then
24 dryrun=false
25 continue
26 fi
27 task="$arg"
28done
29
Jeff Gastoneb3691e2022-04-21 12:34:52 -040030function runGradle() {
Jeff Gaston1d93a522023-08-29 14:24:51 -040031 echo running ./gradlew "$@"
32 if ./gradlew "$@"; then
33 echo succeeded: ./gradlew "$@"
Jeff Gaston29e70d92022-05-10 13:12:55 -040034 else
Jeff Gaston1d93a522023-08-29 14:24:51 -040035 echo failed: ./gradlew "$@"
Jeff Gaston29e70d92022-05-10 13:12:55 -040036 return 1
37 fi
Jeff Gastoneb3691e2022-04-21 12:34:52 -040038}
39
Jeff Gastona423cbc2022-03-09 18:50:05 -050040# This script regenerates signature-related information (dependency-verification-metadata and keyring)
Jeff Gastonb038ffa2022-10-06 15:05:19 -040041function regenerateVerificationMetadata() {
42 echo "regenerating verification metadata and keyring"
Jeff Gastona423cbc2022-03-09 18:50:05 -050043 # regenerate metadata
44 # Need to run a clean build, https://github.com/gradle/gradle/issues/19228
Jeff Gastond0fb9102023-08-24 15:44:58 -040045 # Resolving Configurations before task execution is expected. b/297394547
Jeff Gaston1d93a522023-08-29 14:24:51 -040046 dryrunArg=""
47 if [ "$dryrun" == "true" ]; then
48 dryrunArg="--dry-run"
49 fi
50 runGradle --stacktrace --write-verification-metadata pgp,sha256 --export-keys $dryrunArg --clean -Pandroidx.update.signatures=true -Pandroid.dependencyResolutionAtConfigurationTime.disallow=false -Pandroidx.enabled.kmp.target.platforms=+native $task
Jeff Gastona423cbc2022-03-09 18:50:05 -050051
Jeff Gastonb038ffa2022-10-06 15:05:19 -040052 # update verification metadata file
Jeff Gaston1d93a522023-08-29 14:24:51 -040053
54 # first, make sure the resulting file is named "verification-metadata.xml"
55 if [ "$dryrun" == "true" ]; then
56 mv gradle/verification-metadata.dryrun.xml gradle/verification-metadata.xml
57 fi
58
59 # next, remove 'version=' lines https://github.com/gradle/gradle/issues/20192
Jeff Gastonbee81162023-09-07 11:26:17 -040060 sed -i 's/\(trusted-key.*\)version="[^"]*"/\1/' gradle/verification-metadata.xml
Jeff Gastona423cbc2022-03-09 18:50:05 -050061
Jeff Gastoncb1093f2023-04-18 12:02:19 -040062 # rename keyring
Jeff Gaston1d93a522023-08-29 14:24:51 -040063 mv gradle/verification-keyring-dryrun.keys gradle/verification-keyring.keys 2>/dev/null || true
Jeff Gastoncb1093f2023-04-18 12:02:19 -040064
Jeff Gastonb038ffa2022-10-06 15:05:19 -040065 # remove temporary files
Jeff Gastona423cbc2022-03-09 18:50:05 -050066 rm -f gradle/verification-keyring-dryrun.gpg
Jeff Gaston1d93a522023-08-29 14:24:51 -040067 rm -f gradle/verification-keyring.gpg
Jeff Gastona423cbc2022-03-09 18:50:05 -050068}
Jeff Gastonb038ffa2022-10-06 15:05:19 -040069regenerateVerificationMetadata
Jeff Gastona423cbc2022-03-09 18:50:05 -050070
71echo
Jeff Gastoneaac29c2023-02-07 15:11:00 -050072echo 'Done. Please check that these changes look correct (`git diff`)'
Jeff Gaston1d93a522023-08-29 14:24:51 -040073echo "If Gradle did not make all expected updates to verification-metadata.xml, you can try '--no-dry-run'. This is slow so you may also want to specify a task. Example: $0 --dry-run exportSboms"