# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 parameters: var_name: '' steps: - bash: | set -euo pipefail TMP=$(mktemp) cat > $TMP <<'END' get_gh_auth_header() { # Credentials are persisted in a different way on GCP and Azure nodes. if header=$(git config 'http.https://github.com/digital-asset/daml.extraheader'); then # On Azure nodes, the auth header is stored directly in the git # config. echo $header else # On GCP nodes, the credentials are stored as part of the remote # url instead of as a separate header. The format is # https://username:password@github.com/:user/:repo.git echo "Authorization: basic $(git config remote.origin.url | grep -o '://.*:.*@' | cut -c4- | rev | cut -c2- | rev | tr -d '\n' | base64 -w0)" fi } open_pr() { local branch title branch="$1" title="$2" git branch -D $branch || true git checkout -b $branch git -c user.name="Azure Pipelines DAML Build" \ -c user.email="support@digitalasset.com" \ commit \ -m "$(printf "$title\n\nCHANGELOG_BEGIN\nCHANGELOG_END\n")" git push origin $branch:$branch jq -n --arg title "$title" \ --arg branch "$branch" \ '{"title": $title, "head": $branch, "base": "master"}' \ | curl -H "Content-Type: application/json" \ -H "$(get_gh_auth_header)" \ --fail \ --silent \ --include \ --location \ -d @- \ https://api.github.com/repos/digital-asset/daml/pulls } user_slack_handle() { local email sha sha=$1 email=$(git log -n 1 --format=%ae $sha) if cat ci/slack_user_ids | grep $email >/dev/null 2>&1; then echo $(cat ci/slack_user_ids | grep $email | awk '{print $2}') else echo "" fi } tell_slack() { local message channel message="$1" channel=${2:-$(Slack.team-daml)} jq -n --arg message "$message" '{"text": $message}' \ | curl -XPOST -i -H 'Content-Type: application/json' -d @- $channel } gcs() { local args cleanup cmd cred key restore_trap ret ret=1 cred="$1" cmd="$2" args=(${@:3}) key=$(mktemp) # There may already be a trap; this will save it restore_trap=$(trap -p EXIT) cleanup="rm -rf $key ~/.config/gcloud" trap "$cleanup" EXIT echo "$cred" > $key gcloud auth activate-service-account --key-file=$key BOTO_CONFIG=/dev/null gsutil $cmd "${args[@]}" ret=$? eval "$cleanup" trap - EXIT eval "$restore_trap" return $ret } gpg_verify() { local key gpg_dir signature_file res signature_file=$1 key=$(mktemp) cat > $key <