Skip to content

Prepare release

Prepare release #29

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 }}