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 6e88f08
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
56 changes: 26 additions & 30 deletions .github/workflows/prepare_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: false

env:
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 @@ -34,15 +38,14 @@ jobs:
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
# 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() }}
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"
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
Expand All @@ -57,6 +60,20 @@ jobs:
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
- name: Check release preparation is from right branch
run: |
IS_PATCH="$(poetry run python ./script/make_utils/version_utils.py is_patch_release --version "$PROJECT_VERSION")"
if [[ "${IS_PATH}" == 'true' && "${BRANCH_IS_RELEASE}" == "false" ]]; then
echo "Patch release cannot be done: target branch is not a release branch"
exit 1
elif [[ "${IS_PATH}" == 'false' && "${BRANCH_IS_MAIN}" == "false" ]]; then
echo "Release cannot be done: target branch is not main"
exit 1
fi
- name: Set version
run: |
make set_version
Expand All @@ -65,36 +82,15 @@ jobs:
run: |
make apidocs
# 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 }})"
BRANCH_PATCH_STRING=""
TITLE_PATCH_STRING=""
if [[ "${IS_PATCH}" == "true" ]]; then
BRANCH_PATCH_STRING="patch_"
TITLE_PATCH_STRING="patch "
fi
BRANCH_NAME="chore/prepare_${BRANCH_PATCH_STRING}release_${{ env.VERSION }}"
PR_TITLE="Prepare ${TITLE_PATCH_STRING}release ${{ env.VERSION }}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV"
echo "PR_TITLE=${PR_TITLE}" >> "$GITHUB_ENV"
# 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
27 changes: 11 additions & 16 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 Down Expand Up @@ -46,10 +44,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 @@ -126,10 +120,9 @@ jobs:
token: ${{ secrets.BOT_TOKEN }}

# Make sure that the target branch is:
# - main, for release-candidates or major/minor releases
# - 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
Expand Down Expand Up @@ -177,13 +170,15 @@ 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'
# release or from main otherwise. If not, the release preparation process is stopped
- name: Check release preparation is from right branch
run: |
if [[ "${BRANCH_IS_RELEASE}" == "false" ]]; then
if [[ "${{ env.IS_PATCH }}" == 'true' && "${BRANCH_IS_RELEASE}" == "false" ]]; then
echo "Patch release cannot be done: target branch is not a release branch"
exit 1
elif [[ "${{ env.IS_PATCH }}" == 'false' && "${BRANCH_IS_MAIN}" == "false" ]]; then
echo "Release cannot be done: target branch is not main"
exit 1
fi
# Make sure that the tag related to the current version does not already exist in the
Expand Down

0 comments on commit 6e88f08

Please sign in to comment.