diff --git a/.github/workflows/prepare_release.yaml b/.github/workflows/prepare_release.yaml index 18b00a606d..b56706f24d 100644 --- a/.github/workflows/prepare_release.yaml +++ b/.github/workflows/prepare_release.yaml @@ -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 }} @@ -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: @@ -57,34 +62,38 @@ 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 @@ -92,9 +101,9 @@ jobs: 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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3a4f57ae00..67e42ce076 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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/**' @@ -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/') }} @@ -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 }} @@ -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 @@ -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 @@ -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