1#!/bin/bash 2# Copyright 2023 The gRPC Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -e 17 18ARCHIVE_WITH_SUBMODULES="$1" 19BUILD_SCRIPT="$2" 20EXIT_CODE_FILE="$3" 21SCRIPT_LOG_FILE="$4" 22ARTIFACTS_OUT_FILE="$5" 23shift 5 24 25# Extract grpc repo archive 26tar -xopf ${ARCHIVE_WITH_SUBMODULES} 27cd grpc 28 29# Extract all input archives with artifacts into input_artifacts directory 30# TODO(jtattermusch): Deduplicate the snippet below (it appears in multiple files). 31mkdir -p input_artifacts 32pushd input_artifacts >/dev/null 33# all remaining args are .tar.gz archives with input artifacts 34for input_artifact_archive in "$@" 35do 36 # extract the .tar.gz with artifacts into a directory named after a basename 37 # of the archive itself (and strip the "artifact/" prefix) 38 # Note that input artifacts from different dependencies can have files 39 # with the same name, so disambiguating through the name of the archive 40 # is important. 41 archive_extract_dir="$(basename ${input_artifact_archive} .tar.gz)" 42 mkdir -p "${archive_extract_dir}" 43 pushd "${archive_extract_dir}" >/dev/null 44 tar --strip-components=1 -xopf ../../../${input_artifact_archive} 45 popd >/dev/null 46done 47popd >/dev/null 48 49mkdir -p artifacts 50 51# Run the build script with args, storing its stdout and stderr 52# in a log file. 53SCRIPT_EXIT_CODE=0 54../"${BUILD_SCRIPT}" >"../${SCRIPT_LOG_FILE}" 2>&1 || SCRIPT_EXIT_CODE="$?" 55 56# Store build script's exitcode in a file. 57# Note that the build atifacts task will terminate with success even when 58# there was an error building the artifacts. 59# The error status (an associated log) will be reported by an associated 60# bazel test. 61echo "${SCRIPT_EXIT_CODE}" >"../${EXIT_CODE_FILE}" 62 63# collect the artifacts 64# TODO(jtattermusch): add tar flags to create deterministic tar archive 65tar -czvf ../"${ARTIFACTS_OUT_FILE}" artifacts 66