1#!/bin/bash 2set -veux -o pipefail 3 4if [[ -f /VERSION ]]; then 5 cat /VERSION 6fi 7 8readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" 9 10echo "Verifying that all artifacts are here..." 11find "$KOKORO_GFILE_DIR" 12 13# The output from all the jobs are coalesced into a single dir 14LOCAL_MVN_ARTIFACTS="$KOKORO_GFILE_DIR"/github/grpc-java/mvn-artifacts/ 15LOCAL_OTHER_ARTIFACTS="$KOKORO_GFILE_DIR"/github/grpc-java/artifacts/ 16 17# verify that files from all 3 grouped jobs are present. 18# platform independent artifacts, from linux job: 19[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-core-*.jar' | wc -l)" != '0' ]] 20 21# android artifact from linux job: 22[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-android-*.aar' | wc -l)" != '0' ]] 23 24# cronet artifact from linux job: 25[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-cronet-*.aar' | wc -l)" != '0' ]] 26 27# binder artifact from linux job: 28[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-binder-*.aar' | wc -l)" != '0' ]] 29 30# from linux job: 31[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_64.exe' | wc -l)" != '0' ]] 32[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_32.exe' | wc -l)" != '0' ]] 33 34# for linux aarch64 platform 35[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-aarch_64.exe' | wc -l)" != '0' ]] 36 37# for linux ppc64le platform 38[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-ppcle_64.exe' | wc -l)" != '0' ]] 39 40# for linux s390x platform 41[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-s390_64.exe' | wc -l)" != '0' ]] 42 43# from macos job: 44[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-osx-x86_64.exe' | wc -l)" != '0' ]] 45# copy all x86 artifacts to aarch until native artifacts are built 46find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-osx-x86_64.exe*' -exec bash -c 'cp "${0}" "${0/x86/aarch}"' {} \; 47 48# from windows job: 49[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-windows-x86_64.exe' | wc -l)" != '0' ]] 50[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-windows-x86_32.exe' | wc -l)" != '0' ]] 51 52 53mkdir -p ~/.config/ 54gsutil cp gs://grpc-testing-secrets/sonatype_credentials/sonatype-upload ~/.config/sonatype-upload 55 56mkdir -p ~/java_signing/ 57gsutil cp -r gs://grpc-testing-secrets/java_signing/ ~/ 58gpg --batch --import ~/java_signing/grpc-java-team-sonatype.asc 59 60gsutil cat gs://grpc-testing-secrets/dockerhub_credentials/grpcpackages.password \ 61 | docker login --username grpcpackages --password-stdin 62 63# gpg commands changed between v1 and v2 are different. 64gpg --version 65 66# This is the version found on kokoro. 67if gpg --version | grep 'gpg (GnuPG) 1.'; then 68 # This command was tested on 1.4.16 69 find "$LOCAL_MVN_ARTIFACTS" -type f \ 70 -not -name "maven-metadata.xml*" -not -name "*.sha*" -not -name "*.md5" -exec \ 71 bash -c 'cat ~/java_signing/passphrase | gpg --batch --passphrase-fd 0 --detach-sign -a {}' \; 72fi 73 74# This is the version found on corp workstations. Maybe kokoro will be updated to gpg2 some day. 75if gpg --version | grep 'gpg (GnuPG) 2.'; then 76 # This command was tested on 2.2.2 77 find "$LOCAL_MVN_ARTIFACTS" -type f \ 78 -not -name "maven-metadata.xml*" -not -name "*.sha*" -not -name "*.md5" -exec \ 79 gpg --batch --passphrase-file ~/java_signing/passphrase --pinentry-mode loopback \ 80 --detach-sign -a {} \; 81fi 82 83# Just the numbers; does not include leading 'v' 84VERSION="$(cat $LOCAL_OTHER_ARTIFACTS/version)" 85EXAMPLE_HOSTNAME_ID="$(cat "$LOCAL_OTHER_ARTIFACTS/example-hostname.id")" 86docker load --input "$LOCAL_OTHER_ARTIFACTS/example-hostname.tar" 87LATEST_VERSION="$((echo "v$VERSION"; git ls-remote -t --refs https://github.com/grpc/grpc-java.git | cut -f 2 | sed s#refs/tags/##) | sort -V | tail -n 1)" 88 89 90STAGING_REPO=a93898609ef848 91"$GRPC_JAVA_DIR"/buildscripts/sonatype-upload.sh "$STAGING_REPO" "$LOCAL_MVN_ARTIFACTS" 92 93docker tag "$EXAMPLE_HOSTNAME_ID" "grpc/java-example-hostname:${VERSION}" 94docker push "grpc/java-example-hostname:${VERSION}" 95if [[ "v$VERSION" = "$LATEST_VERSION" ]]; then 96 docker tag "$EXAMPLE_HOSTNAME_ID" grpc/java-example-hostname:latest 97 docker push grpc/java-example-hostname:latest 98fi 99