forked from NVIDIA/cccl
-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (143 loc) · 5.69 KB
/
update-branch-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: "Release: 0. Update version in target branch"
# The target branch when starting this workflow should be:
# 1. "branch/{major}.{minor}.x" if it exists, or
# 2. "main"
on:
workflow_dispatch:
inputs:
new_version:
description: "Version 'X.Y.Z' for the release branch."
type: string
required: true
default: "0.0.0"
target_branch:
description: "Target branch for the version update"
type: string
required: false
default: "main"
force:
description: "Enable overwriting existing PR branches (this does not force overwrite the target branch or skip creating a PR)"
type: boolean
required: true
default: false
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
jobs:
update-version:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.target_branch }}
- name: Verify run from main
id: verify-main
run: |
# This action can only be run from main.
# if [[ $GITHUB_REF != refs/heads/main ]]; then
# echo " This action may only be run fom main" | tee -a $GITHUB_STEP_SUMMARY
# exit 1
# fi
- name: Prepare environment
id: prepare-env
run: |
log_and_export_vars() {
for var in "$@"; do
printf "%-15s %s\n" "$var:" "${!var}" | tee -a $GITHUB_STEP_SUMMARY
echo "${var}=${!var}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
done
}
full_version=${{ inputs.new_version }}
major_version=$(echo ${full_version} | cut -d. -f1)
minor_version=$(echo ${full_version} | cut -d. -f2)
patch_version=$(echo ${full_version} | cut -d. -f3)
branch_name=${{ inputs.target_branch }}
enable_force_push="${{ inputs.force }}"
pr_title="[Version] Update ${branch_name} to v${full_version}"
pr_body="Bump ${branch_name} to ${full_version}."
pr_branch="pr/ver/${branch_name}-v${full_version}"
log_and_export_vars \
full_version major_version minor_version patch_version \
branch_name pr_title pr_branch pr_body enable_force_push
echo "Branch ref: $GITHUB_REF" | tee -a $GITHUB_STEP_SUMMARY
echo "Branch SHA: $GITHUB_SHA" | tee -a $GITHUB_STEP_SUMMARY
echo "Branch commit: $(git show --oneline --no-patch ${GITHUB_SHA})" | tee -a $GITHUB_STEP_SUMMARY
- name: Verify environment
id: verify-env
run: |
# Target branch must already exist
if ! git ls-remote --exit-code origin ${branch_name}; then
echo " Target branch must already exist" | tee -a $GITHUB_STEP_SUMMARY
exit 1
fi
#Ensure that target branch version is compatible.
if [[ "${branch_name}" =~ ^branch/[0-9]+\.[0-9]+\.x$ ]]; then
branch_version=$(echo ${branch_name} | cut -d/ -f1 --complement)
branch_major=$(echo ${branch_version} | cut -d. -f1)
branch_minor=$(echo ${branch_version} | cut -d. -f2)
if [ "${branch_major}" != "${major_version}" ]; then
echo " Target branch major version mismatch"
exit 1
fi;
if [ "${branch_minor}" != "${minor_version}" ]; then
echo " Target branch minor version mismatch"
exit 1
fi
fi
# PR branch must *not* exist
if [ "${enable_force_push}" == "false" ]; then
if git ls-remote --exit-code origin ${pr_branch}; then
echo " PR branch cannot already exist - Delete branch and retry workflow or enable 'force'" | tee -a $GITHUB_STEP_SUMMARY
exit 1
fi
fi
if [[ ! $full_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version number: $full_version"
exit 1
fi
- name: Update version numbers in target branch
id: create-pr-branch
run: |
git checkout -b ${pr_branch}
echo "::group::Running update_version.sh"
./ci/update_version.sh ${major_version} ${minor_version} ${patch_version}
echo "::endgroup::"
if ! git diff --quiet; then
echo "::group::Diff"
git diff
echo "::endgroup::"
git add .
git config user.name github-actions
git config user.email [email protected]
git commit -m "${pr_body}"
# Push the changes to the release branch:
git push --force origin ${pr_branch}
fi
- name: Create pull request for target branch
id: create-pr
run: |
gh pr create \
-B "${branch_name}" \
-b "${pr_body}" \
-t "${pr_title}" \
-H "${pr_branch}"