|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Fail on any error. |
| 4 | +set -e |
| 5 | + |
| 6 | +mkdir -p "${KOKORO_ARTIFACTS_DIR}/output_dir" |
| 7 | +cd "${KOKORO_ARTIFACTS_DIR}/output_dir" |
| 8 | + |
| 9 | +GCS_BUCKET="androidx-test-staging/release" |
| 10 | +ATTESTATION_FILE="attestation.intoto.jsonl" |
| 11 | +INPUT_ZIP="axt_m2repository_unsigned.zip" |
| 12 | +OUTPUT_ZIP="axt_m2repository_unsigned_and_attested.zip" |
| 13 | + |
| 14 | +# 1. Find the full GCS path of the zip file |
| 15 | +ZIP_GCS_PATH=$(gcloud storage ls "gs://${GCS_BUCKET}/*/*/${CANDIDATE_NAME}/axt_m2repository_unsigned.zip" | head -n 1) |
| 16 | + |
| 17 | +if [[ -z "${ZIP_GCS_PATH}" ]]; then |
| 18 | + echo "Error: Could not find the zip file for candidate ${CANDIDATE_NAME}." |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +# 2. Extract the parent path: gs://[BUCKET_NAME]/[timestamp]/[build id] |
| 23 | +# Removes '/axt_m2repository_unsigned.zip' |
| 24 | +DIR_PATH="${ZIP_GCS_PATH%/*}" |
| 25 | +# Removes '/[CANDIDATE_NAME]' |
| 26 | +DIR_PATH="${DIR_PATH%/*}" |
| 27 | + |
| 28 | +echo "Target build directory identified: ${DIR_PATH}" |
| 29 | + |
| 30 | +# 3. Download and rename the ZIP file to current working directory |
| 31 | +echo "Downloading zip file..." |
| 32 | +gcloud storage cp "${ZIP_GCS_PATH}" "./${INPUT_ZIP}" |
| 33 | + |
| 34 | +# 4. Download and rename the attestation file |
| 35 | +if gcloud storage ls "${DIR_PATH}/${CANDIDATE_NAME}.intoto.jsonl" > /dev/null 2>&1; then |
| 36 | + echo "Downloading attestation..." |
| 37 | + gcloud storage cp "${DIR_PATH}/${CANDIDATE_NAME}.intoto.jsonl" "./${ATTESTATION_FILE}" |
| 38 | +else |
| 39 | + echo "Error: Could not find an attestation file in ${DIR_PATH}" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +SCRATCH_DIR=$(mktemp -d -t axt_attest_XXXXXX) |
| 44 | + |
| 45 | +echo "Unzipping $INPUT_ZIP to temporary directory..." |
| 46 | +unzip -q "$INPUT_ZIP" -d "$SCRATCH_DIR" |
| 47 | + |
| 48 | +echo "Scanning for .pom files..." |
| 49 | +find "$SCRATCH_DIR" -type f -name "*.pom" | while IFS= read -r pom_path; do |
| 50 | + pom_dir=$(dirname "$pom_path") |
| 51 | + pom_filename=$(basename "$pom_path") |
| 52 | + |
| 53 | + # Remove .pom extension to get artifactid-version |
| 54 | + artifact_prefix="${pom_filename%.pom}" |
| 55 | + |
| 56 | + target_attestation="$pom_dir/$artifact_prefix.intoto.jsonl" |
| 57 | + |
| 58 | + cp "$ATTESTATION_FILE" "$target_attestation" |
| 59 | + echo "Added attestation: $target_attestation" |
| 60 | +done |
| 61 | + |
| 62 | +echo "Re-zipping content to $OUTPUT_ZIP..." |
| 63 | +OUTPUT_ZIP_ABS="$(pwd)/$OUTPUT_ZIP" |
| 64 | + |
| 65 | +# Delete output zip if it already exists to avoid appending |
| 66 | +rm -f "$OUTPUT_ZIP_ABS" |
| 67 | + |
| 68 | +(cd "$SCRATCH_DIR" && zip -r -q "$OUTPUT_ZIP_ABS" .) |
| 69 | + |
| 70 | +echo "Success! Created $OUTPUT_ZIP" |
0 commit comments