2024-01-15 22:27:42 +03:00
|
|
|
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2020-08-14 12:35:57 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
parameters:
|
2021-10-13 15:55:20 +03:00
|
|
|
var_name: ""
|
2023-07-12 12:31:38 +03:00
|
|
|
condition: 'True'
|
2020-08-14 12:35:57 +03:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- bash: |
|
|
|
|
set -euo pipefail
|
|
|
|
TMP=$(mktemp)
|
2021-10-13 15:55:20 +03:00
|
|
|
cat > "$TMP" <<'END'
|
|
|
|
PROJ_DIR="$PWD"
|
2020-12-16 14:18:41 +03:00
|
|
|
escape_slack() {
|
|
|
|
local r
|
|
|
|
r="$1"
|
|
|
|
r="${r//&/&}"
|
|
|
|
r="${r//>/>}"
|
|
|
|
r="${r//</<}"
|
|
|
|
echo "$r"
|
|
|
|
}
|
2020-08-14 12:35:57 +03:00
|
|
|
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-12-10 12:08:28 +03:00
|
|
|
open_pr() {
|
2024-01-09 20:20:53 +03:00
|
|
|
local branch title body pr_number base header output
|
2020-12-10 12:08:28 +03:00
|
|
|
branch="$1"
|
|
|
|
title="$2"
|
2022-06-28 20:45:37 +03:00
|
|
|
body="${3:-}"
|
2022-06-29 18:57:55 +03:00
|
|
|
pr_number="${4:-}"
|
2024-01-09 20:20:53 +03:00
|
|
|
base="${5:-main}"
|
2022-06-28 20:45:37 +03:00
|
|
|
header=$(mktemp)
|
|
|
|
output=$(mktemp)
|
|
|
|
|
2020-12-10 12:08:28 +03:00
|
|
|
git branch -D $branch || true
|
|
|
|
git checkout -b $branch
|
2022-03-08 16:25:25 +03:00
|
|
|
git -c user.name="Azure Pipelines Daml Build" \
|
2020-12-10 12:08:28 +03:00
|
|
|
-c user.email="support@digitalasset.com" \
|
|
|
|
commit \
|
2024-01-04 21:07:31 +03:00
|
|
|
-m "$(printf "$title\n\n$body\n")"
|
2020-12-10 12:08:28 +03:00
|
|
|
git push origin $branch:$branch
|
|
|
|
jq -n --arg title "$title" \
|
|
|
|
--arg branch "$branch" \
|
2024-01-09 20:20:53 +03:00
|
|
|
--arg base "$base" \
|
2022-06-28 20:45:37 +03:00
|
|
|
--arg body "$(printf "$body")" \
|
2024-01-09 20:20:53 +03:00
|
|
|
'{"title": $title, "head": $branch, "base": $base, "body": $body}' \
|
2020-12-10 12:08:28 +03:00
|
|
|
| curl -H "Content-Type: application/json" \
|
|
|
|
-H "$(get_gh_auth_header)" \
|
|
|
|
--fail \
|
|
|
|
--silent \
|
|
|
|
--location \
|
2022-06-28 20:45:37 +03:00
|
|
|
--dump-header "$header" \
|
|
|
|
--output "$output" \
|
2020-12-10 12:08:28 +03:00
|
|
|
-d @- \
|
|
|
|
https://api.github.com/repos/digital-asset/daml/pulls
|
2022-06-29 18:57:55 +03:00
|
|
|
cat "$header" "$output"
|
2022-06-28 20:45:37 +03:00
|
|
|
if [ -n "$pr_number" ]; then
|
|
|
|
jq '.number' "$output" > "$pr_number"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
request_pr_review() {
|
|
|
|
local pr_number reviewer
|
|
|
|
pr_number="$1"
|
|
|
|
reviewer="$2"
|
|
|
|
|
|
|
|
jq -n --arg reviewer "$reviewer" \
|
|
|
|
'{"reviewers": [$reviewer]}' \
|
|
|
|
| curl -H "Content-Type: application/json" \
|
|
|
|
-H "$(get_gh_auth_header)" \
|
|
|
|
--fail \
|
|
|
|
--silent \
|
|
|
|
--location \
|
|
|
|
-d @- \
|
|
|
|
"https://api.github.com/repos/digital-asset/daml/pulls/$pr_number/requested_reviewers"
|
2020-12-10 12:08:28 +03:00
|
|
|
}
|
2020-12-04 15:16:34 +03:00
|
|
|
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
|
|
|
|
}
|
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
|
|
|
|
}
|
2022-06-17 18:56:51 +03:00
|
|
|
wrap_gcloud() (
|
2020-09-14 21:38:31 +03:00
|
|
|
cred="$1"
|
2020-10-08 19:37:14 +03:00
|
|
|
cmd="$2"
|
2020-09-14 21:38:31 +03:00
|
|
|
key=$(mktemp)
|
2021-03-08 10:56:33 +03:00
|
|
|
config_dir=$(mktemp -d)
|
2022-06-17 18:56:51 +03:00
|
|
|
trap "rm -rf $key $config_dir" EXIT
|
2020-09-14 21:38:31 +03:00
|
|
|
echo "$cred" > $key
|
2021-03-08 10:56:33 +03:00
|
|
|
export CLOUDSDK_CONFIG="$config_dir"
|
2022-06-17 18:56:51 +03:00
|
|
|
export BOTO_CONFIG=/dev/null
|
2020-09-14 21:38:31 +03:00
|
|
|
gcloud auth activate-service-account --key-file=$key
|
2022-06-17 18:56:51 +03:00
|
|
|
eval "$cmd"
|
|
|
|
)
|
|
|
|
gcs() (
|
|
|
|
cred="$1"
|
|
|
|
cmd="${@:2}"
|
2020-09-14 21:38:31 +03:00
|
|
|
|
2022-06-17 18:56:51 +03:00
|
|
|
wrap_gcloud "$cred" "gsutil $cmd"
|
|
|
|
)
|
2021-02-09 13:42:34 +03:00
|
|
|
setvar() {
|
|
|
|
echo "Setting '$1' to '$2'"
|
|
|
|
echo "##vso[task.setvariable variable=$1;isOutput=true]$2"
|
|
|
|
}
|
2021-10-07 15:46:55 +03:00
|
|
|
next_in_rotation() {
|
|
|
|
awk '/^[^#]/ {print $0}' "$PROJ_DIR/release/rotation" | head -n 1
|
|
|
|
}
|
|
|
|
next_in_rotation_slack() {
|
|
|
|
next_in_rotation | awk '{print $1}'
|
|
|
|
}
|
|
|
|
next_in_rotation_github() {
|
|
|
|
next_in_rotation | awk '{print $2}'
|
|
|
|
}
|
2021-11-24 21:05:04 +03:00
|
|
|
trigger_azure() (
|
|
|
|
token=$1
|
2021-11-26 19:50:53 +03:00
|
|
|
shift
|
|
|
|
build=$1
|
|
|
|
shift
|
2021-11-24 21:05:04 +03:00
|
|
|
az extension add --name azure-devops
|
|
|
|
trap 'az devops logout' EXIT
|
|
|
|
echo $token \
|
|
|
|
| az devops login --org "https://dev.azure.com/digitalasset"
|
|
|
|
az pipelines build queue \
|
|
|
|
--definition-name $build \
|
|
|
|
--org "https://dev.azure.com/digitalasset" \
|
2021-11-26 19:50:53 +03:00
|
|
|
--project daml \
|
|
|
|
$@
|
2021-11-24 21:05:04 +03:00
|
|
|
)
|
2021-02-09 13:42:34 +03:00
|
|
|
|
2020-08-14 12:35:57 +03:00
|
|
|
END
|
|
|
|
echo "##vso[task.setvariable variable=${{parameters.var_name}}]$TMP"
|
2020-10-05 18:31:11 +03:00
|
|
|
displayName: install Bash lib
|
2023-07-12 12:31:38 +03:00
|
|
|
condition: ${{parameters.condition}}
|