2020-08-14 12:35:57 +03:00
|
|
|
# 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
|
|
|
|
}
|
2020-08-17 14:42:35 +03:00
|
|
|
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
|
|
|
|
}
|
2020-09-14 21:38:31 +03:00
|
|
|
save_gcp_data() {
|
|
|
|
local restore_trap cred local_file remote_path key cleanup
|
|
|
|
|
|
|
|
cred="$1"
|
|
|
|
local_file="$2"
|
|
|
|
remote_path="$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 cp "$local_file" "$remote_path"
|
|
|
|
eval "$cleanup"
|
|
|
|
trap - EXIT
|
|
|
|
eval "$restore_trap"
|
|
|
|
}
|
2020-08-14 12:35:57 +03:00
|
|
|
END
|
|
|
|
echo "##vso[task.setvariable variable=${{parameters.var_name}}]$TMP"
|