-
Notifications
You must be signed in to change notification settings - Fork 152
130 lines (112 loc) · 4.89 KB
/
prepare_release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Prepare release
on:
workflow_dispatch:
inputs:
version:
description: "The version to release"
required: true
concurrency:
group: "Prepare release"
cancel-in-progress: true
env:
BRANCH_NAME: ${{ github.ref_name }}
BRANCH_IS_MAIN: ${{ github.ref_name == 'main' }}
BRANCH_IS_RELEASE: ${{ startsWith(github.ref_name, 'release/') }}
jobs:
prepare-release:
name: Prepare release ${{ github.event.inputs.version }}
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
env:
VERSION: ${{ github.event.inputs.version }}
steps:
# Mask internal URLs if logged
- name: Add masks
id: masks
run: |
echo "::add-mask::${{ secrets.INTERNAL_PYPI_URL_FOR_MASK }}"
echo "::add-mask::${{ secrets.INTERNAL_REPO_URL_FOR_MASK }}"
# Make sure that the target branch is:
# - main, for release-candidates or major/minor releases
# - a release branch, for dot/patch releases
- name: Stop if branch is not main or release
if: ${{ always() && !cancelled() }}
run: |
if [[ "${BRANCH_IS_MAIN}" == "false" && "${BRANCH_IS_RELEASE}" == 'false' ]]; then
echo "Release cannot be done: target branch is not main or a release branch"
echo "Got branch ${BRANCH_NAME}"
exit 1
fi
- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
ref: ${{ github.ref }}
token: ${{ secrets.BOT_TOKEN }}
- name: Set up Python 3.8
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry==1.2.2
make setup_env
# Make sure that the workflow has been triggered from a release branch if this is a patch
# release or from main otherwise. If not, the release preparation process is stopped
# Additionally, for dot/patch releases, if the release branch name does not match the current
# release version, the release preparation process is stopped as well
- name: Check release preparation is from right branch
run: |
IS_PATCH="$(poetry run python ./script/make_utils/version_utils.py is_patch_release --version "$VERSION")"
if [[ "${IS_PATCH}" == "true" ]]; then
if [[ "${BRANCH_IS_RELEASE}" == "false" ]]; then
echo "Patch release cannot be done: target branch is not a release branch"
echo "Got branch '${BRANCH_NAME}'"
exit 1
else
# Release branches are only used for non-release candidates and have a special naming
# format (for example, "release/1.1.x" is used for all patch versions related to version 1.1)
VERSION_MAJOR_MINOR=$(echo "${VERSION}" | cut -d '.' -f -2)
EXPECTED_BRANCH_NAME="release/${VERSION_MAJOR_MINOR}.x"
if [[ "${EXPECTED_BRANCH_NAME}" != "${BRANCH_NAME}" ]]; then
echo "Patch release cannot be done: target branch name does not match the current version"
echo "Got branch '${BRANCH_NAME}' for version '${VERSION}'"
echo "Expected branch '${EXPECTED_BRANCH_NAME}'"
exit 1
fi
fi
elif [[ "${IS_PATCH}" == "false" && "${BRANCH_IS_MAIN}" == "false" ]]; then
echo "Release cannot be done: target branch is not main"
echo "Got branch '${BRANCH_NAME}'"
exit 1
fi
- name: Set version
run: |
make set_version
- name: Build apidocs
run: |
make apidocs
# Open a PR with the new version and updated apidocs
- name: Open PR
uses: peter-evans/create-pull-request@284f54f989303d2699d373481a0cfa13ad5a6666
with:
token: ${{ secrets.BOT_TOKEN }}
commit-message: "chore: prepare release ${{ env.VERSION }}"
branch: "chore/prepare_release_${{ env.VERSION }}"
base: "${{ github.ref_name }}"
title: "Prepare release ${{ env.VERSION }}"
body: "Set version ${{ env.VERSION }} and build apidocs"
- name: Slack Notification
if: ${{ always() && !success() }}
continue-on-error: true
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8
env:
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
SLACK_COLOR: ${{ job.status }}
SLACK_MESSAGE: "Preparing release ${{ env.VERSION }} finished with status \
${{ job.status }} (${{ env.ACTION_RUN_URL }})"
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}