Skip to content

Prepare release

Prepare release #37

name: Prepare release
on:
workflow_dispatch:
inputs:
version:
description: "The version to release"
required: true
concurrency:
group: "Prepare Release ${{ github.event.inputs.version }}"
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
# We need to include LFS files as some are needed for building the documentation
- name: Checkout Code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
ref: ${{ github.ref }}
token: ${{ secrets.BOT_TOKEN }}
lfs: true
- name: Set up Python 3.8
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry==1.7.1
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@6d6857d36972b65feb161a90e484f2984215f83e
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@4e5fb42d249be6a45a298f3c9543b111b02f7907
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 }}