|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Fetches a validated-but-unpublished Central Portal deployment into a local |
| 3 | +# Maven-layout directory, so Gradle can resolve from file:// instead of hitting |
| 4 | +# the Portal's flaky /download/ endpoint (which returns 500 for missing files |
| 5 | +# and disables the whole repo). |
| 6 | +# |
| 7 | +# Usage: |
| 8 | +# ./fetch-rc-bundle.sh <deployment-id> <version> |
| 9 | +# |
| 10 | +# The Portal auth header is read automatically from the `centralManualTestingAuthHeaderValue` |
| 11 | +# property in (in order): |
| 12 | +# 1. ~/.gradle/gradle.properties |
| 13 | +# 2. <script-dir>/gradle.properties (examples/ExampleApp/gradle.properties) |
| 14 | +# You can override with the TOKEN_VALUE env var. |
| 15 | +# |
| 16 | +# Modules are discovered dynamically from `embrace-*` directories in the SDK |
| 17 | +# repo root. Extensions are restricted to those actually produced by our |
| 18 | +# publish pipeline (pom / module / jar|aar plus checksums + .asc signatures). |
| 19 | +# |
| 20 | +# Output: |
| 21 | +# ./embrace-bundle-<version>-<deployment-id>/ (Maven layout) |
| 22 | +# Any existing directory with the same name is deleted first. |
| 23 | +# |
| 24 | +# Point Gradle at the resulting directory: |
| 25 | +# maven { url = uri("file:///.../embrace-bundle-<version>-<deployment-id>/") } |
| 26 | + |
| 27 | +set -u |
| 28 | + |
| 29 | +if [[ $# -ne 2 ]]; then |
| 30 | + echo "Usage: $0 <deployment-id> <version>" |
| 31 | + echo "Example: $0 abcdefgh-1234-ijkl-5678-abcdefghijkl 8.2.1" |
| 32 | + exit 2 |
| 33 | +fi |
| 34 | + |
| 35 | +DEPLOYMENT_ID="$1" |
| 36 | +VERSION="$2" |
| 37 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 38 | +SDK_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 39 | + |
| 40 | +read_gradle_prop() { |
| 41 | + local key="$1" file="$2" |
| 42 | + [[ -f "$file" ]] || return 1 |
| 43 | + awk -F= -v k="$key" ' |
| 44 | + $0 ~ "^[[:space:]]*"k"[[:space:]]*=" { |
| 45 | + sub("^[[:space:]]*"k"[[:space:]]*=[[:space:]]*", "") |
| 46 | + sub("[[:space:]]*$", "") |
| 47 | + print |
| 48 | + found = 1 |
| 49 | + exit |
| 50 | + } |
| 51 | + END { exit !found } |
| 52 | + ' "$file" |
| 53 | +} |
| 54 | + |
| 55 | +TOKEN_SOURCE="" |
| 56 | +if [[ -n "${TOKEN_VALUE:-}" ]]; then |
| 57 | + TOKEN_SOURCE="\$TOKEN_VALUE env var" |
| 58 | +else |
| 59 | + for candidate in "$HOME/.gradle/gradle.properties" "$SCRIPT_DIR/gradle.properties"; do |
| 60 | + if value=$(read_gradle_prop "centralManualTestingAuthHeaderValue" "$candidate"); then |
| 61 | + TOKEN_VALUE="$value" |
| 62 | + TOKEN_SOURCE="$candidate" |
| 63 | + break |
| 64 | + fi |
| 65 | + done |
| 66 | +fi |
| 67 | + |
| 68 | +if [[ -z "${TOKEN_VALUE:-}" ]]; then |
| 69 | + echo "ERROR: could not find 'centralManualTestingAuthHeaderValue' in:" |
| 70 | + echo " - \$TOKEN_VALUE env var" |
| 71 | + echo " - $HOME/.gradle/gradle.properties" |
| 72 | + echo " - $SCRIPT_DIR/gradle.properties" |
| 73 | + echo "Set it in one of those, e.g. in ~/.gradle/gradle.properties:" |
| 74 | + echo " centralManualTestingAuthHeaderValue=Bearer <base64(user:pass)>" |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | + |
| 78 | +OUT="${SCRIPT_DIR}/embrace-bundle-${VERSION}-${DEPLOYMENT_ID}" |
| 79 | +BASE="https://central.sonatype.com/api/v1/publisher/deployment/${DEPLOYMENT_ID}/download" |
| 80 | + |
| 81 | +# Discover all embrace-* module directories in the SDK root. |
| 82 | +MODULES=() |
| 83 | +while IFS= read -r name; do |
| 84 | + [[ -d "$SDK_ROOT/$name" ]] || continue |
| 85 | + MODULES+=("$name") |
| 86 | +done < <(ls "$SDK_ROOT" 2>/dev/null | grep "^embrace-" | sort) |
| 87 | + |
| 88 | +if [[ ${#MODULES[@]} -eq 0 ]]; then |
| 89 | + echo "ERROR: no embrace-* modules found under $SDK_ROOT" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +# Extensions actually produced by our publish pipeline (verified against a |
| 94 | +# previously fetched bundle). `aar` and `jar` are both tried per module; only |
| 95 | +# one will exist. No sources/javadoc classifiers are published. |
| 96 | +EXTENSIONS=( |
| 97 | + pom pom.asc pom.md5 pom.sha1 pom.sha256 pom.sha512 |
| 98 | + module module.asc module.md5 module.sha1 module.sha256 module.sha512 |
| 99 | + jar jar.asc jar.md5 jar.sha1 jar.sha256 jar.sha512 |
| 100 | + aar aar.asc aar.md5 aar.sha1 aar.sha256 aar.sha512 |
| 101 | +) |
| 102 | + |
| 103 | +# Plugin marker is POM-only (packaging=pom). |
| 104 | +MARKER_EXTENSIONS=(pom pom.asc pom.md5 pom.sha1 pom.sha256 pom.sha512) |
| 105 | + |
| 106 | +# Clean any prior bundle for this (version, deployment) so the new fetch is authoritative. |
| 107 | +if [[ -d "$OUT" ]]; then |
| 108 | + echo "Removing existing bundle: $OUT" |
| 109 | + rm -rf "$OUT" |
| 110 | +fi |
| 111 | + |
| 112 | +ok=0 |
| 113 | +missing=0 |
| 114 | +fetch() { |
| 115 | + local path="$1" |
| 116 | + local target="${OUT}/${path}" |
| 117 | + mkdir -p "$(dirname "$target")" |
| 118 | + local code |
| 119 | + code=$(curl -sS -L -o "$target" -w "%{http_code}" \ |
| 120 | + -H "Authorization: ${TOKEN_VALUE}" "${BASE}/${path}") |
| 121 | + if [[ "$code" == "200" ]]; then |
| 122 | + ok=$((ok + 1)) |
| 123 | + echo " [200] ${path}" |
| 124 | + else |
| 125 | + rm -f "$target" |
| 126 | + missing=$((missing + 1)) |
| 127 | + fi |
| 128 | +} |
| 129 | + |
| 130 | +echo "Deployment: ${DEPLOYMENT_ID}" |
| 131 | +echo "Version: ${VERSION}" |
| 132 | +echo "Token from: ${TOKEN_SOURCE}" |
| 133 | +echo "Modules: ${#MODULES[@]} (from ${SDK_ROOT})" |
| 134 | +echo "Output: ${OUT}" |
| 135 | +echo |
| 136 | + |
| 137 | +for m in "${MODULES[@]}"; do |
| 138 | + echo "-- io.embrace:${m}:${VERSION}" |
| 139 | + for ext in "${EXTENSIONS[@]}"; do |
| 140 | + fetch "io/embrace/${m}/${VERSION}/${m}-${VERSION}.${ext}" |
| 141 | + done |
| 142 | +done |
| 143 | + |
| 144 | +echo |
| 145 | +echo "-- plugin marker io.embrace.gradle:io.embrace.gradle.gradle.plugin:${VERSION}" |
| 146 | +for ext in "${MARKER_EXTENSIONS[@]}"; do |
| 147 | + fetch "io/embrace/gradle/io.embrace.gradle.gradle.plugin/${VERSION}/io.embrace.gradle.gradle.plugin-${VERSION}.${ext}" |
| 148 | +done |
| 149 | + |
| 150 | +echo |
| 151 | +echo "Done. Downloaded: ${ok}. Skipped (missing/error): ${missing}." |
| 152 | + |
| 153 | +# Patch settings.gradle.kts so Gradle picks up the new bundle. Replaces either |
| 154 | +# the literal <path-to-bundle> placeholder or a previously-written bundle path. |
| 155 | +SETTINGS="${SCRIPT_DIR}/settings.gradle.kts" |
| 156 | +if [[ $ok -eq 0 ]]; then |
| 157 | + echo "Skipping settings.gradle.kts update (no artifacts downloaded)." |
| 158 | +elif [[ ! -f "$SETTINGS" ]]; then |
| 159 | + echo "WARNING: $SETTINGS not found — skipping settings update." |
| 160 | +else |
| 161 | + # BSD + GNU sed compatible: -i.bak then remove the backup. |
| 162 | + sed -i.bak \ |
| 163 | + -e "s|<path-to-bundle>|${OUT}|g" \ |
| 164 | + -e "s|file://[^\"]*embrace-bundle-[^\"]*|file://${OUT}|g" \ |
| 165 | + "$SETTINGS" |
| 166 | + rm -f "${SETTINGS}.bak" |
| 167 | + if grep -q "file://${OUT}" "$SETTINGS"; then |
| 168 | + echo "Updated ${SETTINGS} → file://${OUT}" |
| 169 | + else |
| 170 | + echo "WARNING: no <path-to-bundle> or prior bundle URL found in ${SETTINGS}." |
| 171 | + echo " Add url = uri(\"file://<path-to-bundle>/\") to centralManualTesting" |
| 172 | + echo " and rerun, or point Gradle manually at: file://${OUT}/" |
| 173 | + fi |
| 174 | +fi |
0 commit comments