mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-08 21:34:22 +03:00
179d85362d
* update copyright * undo hack from #18168 * update hash in platform-independence-pre-check
154 lines
4.7 KiB
YAML
154 lines
4.7 KiB
YAML
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
parameters:
|
|
var_name: ""
|
|
condition: 'True'
|
|
|
|
steps:
|
|
- bash: |
|
|
set -euo pipefail
|
|
TMP=$(mktemp)
|
|
cat > "$TMP" <<'END'
|
|
PROJ_DIR="$PWD"
|
|
escape_slack() {
|
|
local r
|
|
r="$1"
|
|
r="${r//&/&}"
|
|
r="${r//>/>}"
|
|
r="${r//</<}"
|
|
echo "$r"
|
|
}
|
|
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 body pr_number base header output
|
|
branch="$1"
|
|
title="$2"
|
|
body="${3:-}"
|
|
pr_number="${4:-}"
|
|
base="${5:-main}"
|
|
header=$(mktemp)
|
|
output=$(mktemp)
|
|
|
|
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\n$body\n")"
|
|
git push origin $branch:$branch
|
|
jq -n --arg title "$title" \
|
|
--arg branch "$branch" \
|
|
--arg base "$base" \
|
|
--arg body "$(printf "$body")" \
|
|
'{"title": $title, "head": $branch, "base": $base, "body": $body}' \
|
|
| curl -H "Content-Type: application/json" \
|
|
-H "$(get_gh_auth_header)" \
|
|
--fail \
|
|
--silent \
|
|
--location \
|
|
--dump-header "$header" \
|
|
--output "$output" \
|
|
-d @- \
|
|
https://api.github.com/repos/digital-asset/daml/pulls
|
|
cat "$header" "$output"
|
|
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"
|
|
}
|
|
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
|
|
}
|
|
wrap_gcloud() (
|
|
cred="$1"
|
|
cmd="$2"
|
|
key=$(mktemp)
|
|
config_dir=$(mktemp -d)
|
|
trap "rm -rf $key $config_dir" EXIT
|
|
echo "$cred" > $key
|
|
export CLOUDSDK_CONFIG="$config_dir"
|
|
export BOTO_CONFIG=/dev/null
|
|
gcloud auth activate-service-account --key-file=$key
|
|
eval "$cmd"
|
|
)
|
|
gcs() (
|
|
cred="$1"
|
|
cmd="${@:2}"
|
|
|
|
wrap_gcloud "$cred" "gsutil $cmd"
|
|
)
|
|
setvar() {
|
|
echo "Setting '$1' to '$2'"
|
|
echo "##vso[task.setvariable variable=$1;isOutput=true]$2"
|
|
}
|
|
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}'
|
|
}
|
|
trigger_azure() (
|
|
token=$1
|
|
shift
|
|
build=$1
|
|
shift
|
|
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" \
|
|
--project daml \
|
|
$@
|
|
)
|
|
|
|
END
|
|
echo "##vso[task.setvariable variable=${{parameters.var_name}}]$TMP"
|
|
displayName: install Bash lib
|
|
condition: ${{parameters.condition}}
|