Skip to content

Commit

Permalink
chore: run prepare release from release branch for patches
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBredehoft committed Aug 31, 2023
1 parent 36e6edc commit 4e21965
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 63 deletions.
79 changes: 44 additions & 35 deletions .github/workflows/prepare_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: false

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 }}
Expand All @@ -28,24 +33,24 @@ jobs:
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 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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
with:
ref: ${{ github.ref }}
token: ${{ secrets.BOT_TOKEN }}

# Make sure that the target branch is main
- name: Stop if branch is not main
id: check-branch-is-main
if: ${{ always() && !cancelled() }}
env:
BRANCH_IS_MAIN: ${{ github.ref_name == 'main'}}
run: |
if [[ "${BRANCH_IS_MAIN}" != "true" ]]; then
echo "Release cannot be prepared: target branch is not main"
exit 1
fi
- name: Set up Python 3.8
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
with:
Expand All @@ -57,44 +62,48 @@ jobs:
python -m pip install poetry==1.2.2
make setup_env
- name: Set version
# 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 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: |
make set_version
if [[ "${{ env.IS_PATCH }}" == 'true']]; then
- name: Build apidocs
run: |
make apidocs
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
# Prepare title and branch name for the upcoming pull-request
# In case the current version represents a patch release, modify the title and branch name
# in order to not trigger the release process once the pull-request is merged, as patch
# releases ar expected to be triggered from the existing release branch (and not main)
- name: Prepare title and branch name for PR
run: |
IS_PATCH="$(poetry run python ./script/make_utils/version_utils.py is_patch_release --version ${{ env.VERSION }})"
elif [[ "${RELEASE_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 ${PROJECT_VERSION}"
exit 1
fi
BRANCH_PATCH_STRING=""
TITLE_PATCH_STRING=""
if [[ "${IS_PATCH}" == "true" ]]; then
BRANCH_PATCH_STRING="patch_"
TITLE_PATCH_STRING="patch "
elif [[ "${{ env.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
BRANCH_NAME="chore/prepare_${BRANCH_PATCH_STRING}release_${{ env.VERSION }}"
PR_TITLE="Prepare ${TITLE_PATCH_STRING}release ${{ env.VERSION }}"
- name: Set version
run: |
make set_version
echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV"
echo "PR_TITLE=${PR_TITLE}" >> "$GITHUB_ENV"
- 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: "${{ env.BRANCH_NAME }}"
branch: "chore/prepare_release_${{ env.VERSION }}"
base: "${{ github.ref_name }}"
title: "${{ env.PR_TITLE }}"
title: "Prepare release ${{ env.VERSION }}"
body: "Set version ${{ env.VERSION }} and build apidocs"

- name: Slack Notification
Expand Down
66 changes: 38 additions & 28 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ on:
workflow_dispatch:

# Releases are also allowed to be automatically triggered once the release preparation
# pull-request (targeting main) is merged, as this suggest a rc or major/minor (non-patch) release
# has been prepared. In this case, we also make sure that the PR has changes in at least one file
# related to `make set_version` or `make apidocs`. Additionally, they can also be automatically
# triggered once a PR is merged into a release branch as this suggests we are taking care of a
# patch release
# pull-request is merged in main (major/minor releases or release candidates) or in a release
# branch (patch releases). We also make sure that the PR has changes in at least one file
# related to `make set_version` or `make apidocs`
pull_request:
types:
- closed
branches:
- main
- 'release/'
- 'release/*'
paths:
- src/concrete/ml/version.py
- 'docs/developer-guide/api/**'
Expand All @@ -26,6 +24,7 @@ concurrency:

env:
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
BRANCH_NAME: ${{ github.ref_name }}
BRANCH_IS_MAIN: ${{ github.ref_name == 'main' }}
BRANCH_IS_RELEASE: ${{ startsWith(github.ref_name, 'release/') }}

Expand All @@ -46,10 +45,6 @@ jobs:
&& startsWith(github.head_ref, 'chore/prepare_release_')
&& contains(github.event.pull_request.title, 'Prepare release')
)
|| (
github.event_name == 'pull_request'
&& "${BRANCH_IS_RELEASE}" == 'true'
)
runs-on: ubuntu-20.04
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
Expand Down Expand Up @@ -107,6 +102,18 @@ jobs:
release_branch_name: ${{ steps.get-release-version.outputs.release_branch_name }}

steps:
# Make sure that the target branch is:
# - main, for release candidates or major/minor releases
# - a release branch, for 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
# Replace default archive.ubuntu.com from docker image with fr mirror
# original archive showed performance issues and is farther away
- name: Docker container related setup and git installation
Expand All @@ -125,18 +132,6 @@ jobs:
ref: ${{ github.ref }}
token: ${{ secrets.BOT_TOKEN }}

# Make sure that the target branch is:
# - main, for release-candidates or major/minor releases
# - a release branch, for patch releases
- name: Stop if branch is not main or release
id: check-branch-is-main
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"
exit 1
fi
- name: Install dependencies
run: |
./script/make_utils/setup_os_deps.sh --linux-install-python
Expand Down Expand Up @@ -177,12 +172,27 @@ jobs:
echo "release_branch_name=${RELEASE_BRANCH_NAME}" >> "$GITHUB_OUTPUT"
# Make sure that the workflow has been triggered from a release branch if this is a patch
# release. Otherwise, the release process is stopped
- name: Check patch release is from release branch
if: env.IS_PATCH == 'true'
run: |
if [[ "${BRANCH_IS_RELEASE}" == "false" ]]; then
echo "Patch release cannot be done: target branch is not a release branch"
# release or from main otherwise. If not, the release preparation process is stopped
# Additionally, for 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: |
if [[ "${{ env.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
elif [[ "${RELEASE_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 ${PROJECT_VERSION}"
exit 1
fi
elif [[ "${{ env.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
Expand Down

0 comments on commit 4e21965

Please sign in to comment.