|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +name: "Release: 1. Begin Release Cycle" |
| 17 | + |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + new_version: |
| 22 | + description: "Semantic version string (eg. '2.3.0')" |
| 23 | + type: string |
| 24 | + required: true |
| 25 | + branch_point: |
| 26 | + description: "If the release branch doesn't exist yet, it will be branched from this ref." |
| 27 | + type: string |
| 28 | + required: true |
| 29 | + default: 'main' |
| 30 | + |
| 31 | +defaults: |
| 32 | + run: |
| 33 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 34 | + |
| 35 | +jobs: |
| 36 | + create-release-branch: |
| 37 | + permissions: |
| 38 | + contents: write |
| 39 | + pull-requests: write |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Prepare environment |
| 43 | + id: prepare-env |
| 44 | + run: | |
| 45 | + log_and_export_vars() { |
| 46 | + for var in "$@"; do |
| 47 | + var_name=${var^^} |
| 48 | + printf "%-15s %s\n" "$var_name:" "${!var}" | tee -a $GITHUB_STEP_SUMMARY |
| 49 | + echo "${var_name}=${!var}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT |
| 50 | + done |
| 51 | + } |
| 52 | +
|
| 53 | + full_version=${{ inputs.new_version }} |
| 54 | + major_version=$(echo ${full_version} | cut -d. -f1) |
| 55 | + minor_version=$(echo ${full_version} | cut -d. -f2) |
| 56 | + patch_version=$(echo ${full_version} | cut -d. -f3) |
| 57 | + branch_name="branch/${major_version}.${minor_version}.x" |
| 58 | +
|
| 59 | + log_and_export_vars full_version major_version minor_version patch_version branch_name |
| 60 | +
|
| 61 | + - name: Checkout the repository |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + persist-credentials: false |
| 65 | + |
| 66 | + - name: Create release branch if needed |
| 67 | + id: create_branch |
| 68 | + run: | |
| 69 | + # Create the release branch if it doesn't already exist: |
| 70 | + if git ls-remote --exit-code origin $BRANCH_NAME; then |
| 71 | + echo "Branch $BRANCH_NAME already exists." | tee -a $GITHUB_STEP_SUMMARY |
| 72 | + else |
| 73 | + git checkout ${{inputs.branch_point}} |
| 74 | + git checkout -b $BRANCH_NAME |
| 75 | + git push origin $BRANCH_NAME:$BRANCH_NAME |
| 76 | + echo "Created branch $BRANCH_NAME at:\n$(git show HEAD)" | tee -a $GITHUB_STEP_SUMMARY |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Update version numbers |
| 80 | + run: | |
| 81 | + git checkout main |
| 82 | + git checkout -b bump_version_${major_version}.${minor_version}.${patch_version} |
| 83 | +
|
| 84 | + echo "::group::Running update-version.sh" |
| 85 | + ./ci/update-version.sh ${MAJOR_VERSION} ${MINOR_VERSION} ${PATCH_VERSION} |
| 86 | + echo "::endgroup::" |
| 87 | +
|
| 88 | + echo "::group::Diff" |
| 89 | + git diff |
| 90 | + echo "::endgroup::" |
| 91 | +
|
| 92 | + git add . |
| 93 | + git commit -m "Bump version to ${FULL_VERSION}." |
| 94 | +
|
| 95 | + - name: Create a pull request |
| 96 | + id: create_pr |
| 97 | + uses: peter-evans/create-pull-request@v5 |
| 98 | + with: |
| 99 | + branch: ${{ steps.prepare-env.outputs.BRANCH_NAME }} |
| 100 | + title: 'Bump version to ${{ steps.prepare-env.outputs.FULL_VERSION }}' |
| 101 | + body: 'This PR was automatically generated by the release-create-new workflow.' |
| 102 | + base: main |
| 103 | + |
| 104 | + - name: Add backport comment |
| 105 | + run: | |
| 106 | + echo "/backport $BRANCH_NAME" | gh issue comment ${{ steps.create_pr.outputs.pull-request-number }} -F - |
0 commit comments