daml/ci/cron/wednesday.yml

120 lines
3.8 KiB
YAML
Raw Normal View History

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
pr: none
trigger: none
schedules:
- cron: "0 6 * * Wed"
displayName: weekly snapshot
branches:
include:
- main
always: true
jobs:
- job: open_release_pr
timeoutInMinutes: 60
pool:
vmImage: ubuntu-18.04
steps:
- checkout: self
persistCredentials: true
- template: ../bash-lib.yml
parameters:
var_name: bash_lib
- bash: |
set -euo pipefail
source "$(bash_lib)"
AUTH="$(get_gh_auth_header)"
BASE_SHA=$(git rev-parse HEAD)
az extension add --name azure-devops
echo "$(System.AccessToken)" | az devops login --org "https://dev.azure.com/digitalasset"
reset() {
git checkout -f $BASE_SHA
git reset --hard
}
open_pr() {
local branch title body out pr_number
branch=$1
title="$2"
body="$3"
out="${4:-}"
git branch -D $branch || true
git checkout -b $branch
git add .
git -c user.name="Azure Pipelines DAML Build" \
-c user.email="support@digitalasset.com" \
commit \
-m "$(printf "$title\n\n$body\n\nCHANGELOG_BEGIN\nCHANGELOG_END\n")"
git push origin $branch:$branch
pr_number=$(jq -n \
--arg branch "$branch" \
--arg title "$title" \
--arg body "$(printf "$body")" \
'{"title": $title, "head": $branch, "base": "main", "body": $body}' \
| curl -H "Content-Type: application/json" \
-H "$AUTH" \
--silent \
--location \
-d @- \
https://api.github.com/repos/digital-asset/daml/pulls \
| jq '.number')
az pipelines build queue \
--branch $branch \
--definition-name "PRs" \
--org "https://dev.azure.com/digitalasset" \
--project daml
if [ -n "$out" ]; then
echo $pr_number > $out
fi
}
assign_and_label() {
local pr_number assignee
pr_number=$1
assignee=$2
curl -H "Content-Type: application/json" \
-X PATCH \
-H "$AUTH" \
--silent \
--location \
-d "{\"assignees\": [\"$assignee\"], \"labels\": [\"Standard-Change\"]}" \
https://api.github.com/repos/digital-asset/daml/issues/$pr_number
# For the purposes of "common" features, such as assignees and
# labels, PRs are issues as far as the GH API is concerned.
}
rotate() {
local tmp
tmp=$(mktemp)
cp release/rotation $tmp
(tail -n +2 $tmp; head -1 $tmp) > release/rotation
}
reset
NEXT_SLACK=$(head -1 release/rotation | awk '{print $1}')
NEXT_GH=$(head -1 release/rotation | awk '{print $2}')
./release.sh new snapshot
RELEASE=$(head -1 LATEST | awk '{print $2}')
PR_FILE=$(mktemp)
open_pr "auto-release-pr-$(date -I)" \
"release $RELEASE" \
"This PR has been created by a script, which is not very smart and does not have all the context. Please do double-check that the version prefix is correct before merging.\n\n@$NEXT_GH is in charge of this release." \
$PR_FILE
PR=$(cat $PR_FILE)
assign_and_label $PR $NEXT_GH
reset
rotate
open_pr "rotate-after-$RELEASE" \
"rotate release duty after $RELEASE" \
"@$NEXT_GH is taking care of $RELEASE (#$PR), so they get pushed back to the end of the line.\n\nPlease do not merge this before #$PR."