|
| 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: Publish Release" |
| 17 | + |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + new_version: |
| 22 | + type: string |
| 23 | + description: "Semantic version string (eg. '2.3.0')" |
| 24 | + required: true |
| 25 | + |
| 26 | +defaults: |
| 27 | + run: |
| 28 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 29 | + |
| 30 | +jobs: |
| 31 | + tag-release: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + outputs: |
| 34 | + rc_tag: ${{ steps.prepare.outputs.rc_tag }} |
| 35 | + release_tag: ${{ steps.prepare.outputs.release_tag }} |
| 36 | + steps: |
| 37 | + - name: Checkout the repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + persist-credentials: false |
| 41 | + - name: Prepare environment |
| 42 | + id: prepare |
| 43 | + run: | |
| 44 | + log_and_export_vars() { |
| 45 | + for var in "$@"; do |
| 46 | + var_name=${var^^} |
| 47 | + printf "%-15s %s\n" "$var_name:" "${!var}" | tee -a $GITHUB_STEP_SUMMARY |
| 48 | + echo "${var_name}=${!var}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT |
| 49 | + done |
| 50 | + } |
| 51 | +
|
| 52 | + full_version=${{ inputs.new_version }} |
| 53 | + major_version=$(echo ${full_version} | cut -d. -f1) |
| 54 | + minor_version=$(echo ${full_version} | cut -d. -f2) |
| 55 | + patch_version=$(echo ${full_version} | cut -d. -f3) |
| 56 | + release_tag="v${full_version}" |
| 57 | + release_tag_escaped=$(echo "${release_tag}" | sed 's/\./\\./g') |
| 58 | +
|
| 59 | + log_and_export_vars full_version major_version minor_version patch_version release_tag |
| 60 | +
|
| 61 | + # Ensure that there is no final release tag (vX.Y.Z) for the requested version. |
| 62 | + if git ls-remote --tags origin | grep -q "refs/tags/${release_tag_escaped}$"; then |
| 63 | + echo "::error::Tag ${release_tag} already exists." |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + fi |
| 67 | +
|
| 68 | + # Look for previous release candidates: |
| 69 | + declare -i last_rc= |
| 70 | + for tag in $(git ls-remote --tags origin; do |
| 71 | + if [[ $tag =~ v${full_version}-rc([0-9]+)$ ]]; then |
| 72 | + rc=${BASH_REMATCH[1]} |
| 73 | + if (( rc > last_rc )); then |
| 74 | + last_rc=rc |
| 75 | + fi |
| 76 | + fi |
| 77 | + done |
| 78 | +
|
| 79 | + if [[ -z $last_rc ]]; then |
| 80 | + echo "::error::No release candidates found for version ${full_version}." |
| 81 | + fi |
| 82 | +
|
| 83 | + # Determine tag name |
| 84 | + rc_tag="v${full_version}-rc${last_rc}" |
| 85 | +
|
| 86 | + log_and_export_vars last_rc rc_tag |
| 87 | +
|
| 88 | + - name: Tag |
| 89 | + run: | |
| 90 | + git tag ${{ steps.prepare.outputs.release_tag }} ${{ steps.prepare.outputs.rc_tag }} |
| 91 | + git push origin ${{ steps.prepare.outputs.release_tag }} |
| 92 | + echo "Tagged release ${release_tag}." |
| 93 | + # TODO Notify team of results. |
0 commit comments