Repository navigation
248 lines (213 loc) · 9.3 KB
/
Copy pathrelease-finalize.yml
File metadata and controls
248 lines (213 loc) · 9.3 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# 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: 3. Create Final Release"
# This workflow must be started on an release candidate tag.
on:
workflow_dispatch:
inputs:
create_patch_version:
description: "Optionally create a patch PR to update the branch."
type: boolean
required: true
default: false
skip_tag:
description: "Skip pushing release tag. Use in case of failure."
type: boolean
required: true
default: false
skip_generating_notes:
description: "Skip generating notes for release. Use in case of failure."
type: boolean
required: true
default: false
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
jobs:
create-release:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
permissions:
contents: write
outputs:
rc_tag: ${{ steps.prepare.outputs.rc_tag }}
release_tag: ${{ steps.prepare.outputs.release_tag }}
working_branch: ${{ steps.prepare.outputs.working_branch }}
next_full_version: ${{ steps.prepare.outputs.next_full_version }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6
- name: Prepare environment
id: prepare
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
}
# The ref must match a release candidate tag. Parse version info:
tag_regex="^refs/tags/v([0-9]+)\.([0-9]+)\.([0-9]+)-rc([0-9]+)$"
if [[ "${GITHUB_REF}" =~ ${tag_regex} ]]; then
major_version=${BASH_REMATCH[1]}
minor_version=${BASH_REMATCH[2]}
patch_version=${BASH_REMATCH[3]}
rc=${BASH_REMATCH[4]}
else
echo "::error::Invalid ref: ${GITHUB_REF}. Must be a release candidate tag (vX.Y.Z-rcN)."
exit 1
fi
full_version="${major_version}.${minor_version}.${patch_version}"
release_tag="v${full_version}"
rc_tag="${release_tag}-rc${rc}"
repo_version=$(jq -r .full cccl-version.json)
# log_and_export_vars reads these variables indirectly through ${!var}.
# shellcheck disable=SC2034
working_branch="branch/${major_version}.${minor_version}.x"
# Create next point release version number as this point release is finalized.
declare -i next_patch_version=$patch_version
# shellcheck disable=SC2034
next_full_version="${major_version}.${minor_version}.$((next_patch_version + 1))"
log_and_export_vars full_version major_version minor_version patch_version rc release_tag rc_tag repo_version working_branch next_full_version
if [[ "${repo_version}" != "${full_version}" ]]; then
echo "::error::cccl-version.json (${repo_version}) does not match release candidate tag (${rc_tag})."
exit 1
fi
# Ensure that there is no final release tag (vX.Y.Z) for the requested version.
release_tag_escaped=${release_tag//./\\.}
if git ls-remote --tags origin | grep -q "refs/tags/${release_tag_escaped}$"; then
echo "::error::Final release tag ${release_tag} already exists."
exit 1
fi
- name: Generate archives
id: archive
run: |
source_base=cccl-src-${release_tag}
package_base=cccl-${release_tag}
echo "::group::Preparing source"
declare -a source_exclude=(
.aws
.cache
.config
.local
.git
.vscode
build
archives
"${source_base}"
"${package_base}"
)
mkdir "${source_base}"
rsync -av "${source_exclude[@]/#/--exclude=}" . "${source_base}"
echo "::endgroup::"
ci/install_cccl.sh "${package_base}"
mkdir archives
source_tarball=${PWD}/archives/${source_base}.tar.gz
source_zipfile=${PWD}/archives/${source_base}.zip
package_tarball=${PWD}/archives/${package_base}.tar.gz
package_zipfile=${PWD}/archives/${package_base}.zip
{
echo "source_tarball=${source_tarball}"
echo "source_zipfile=${source_zipfile}"
echo "package_tarball=${package_tarball}"
echo "package_zipfile=${package_zipfile}"
} >> "$GITHUB_ENV"
echo "::group::Archiving: ${source_tarball}"
tar -cvzf "${source_tarball}" "${source_base}"
echo "::endgroup::"
echo "::group::Archiving: ${source_zipfile}"
zip -rv9 "${source_zipfile}" "${source_base}"
echo "::endgroup::"
echo "::group::Archiving: ${package_tarball}"
tar -cvzf "${package_tarball}" "${package_base}"
echo "::endgroup::"
echo "::group::Archiving: ${package_zipfile}"
zip -rv9 "${package_zipfile}" "${package_base}"
echo "::endgroup::"
echo "::group::Archive vs Source Sizes"
echo "Sources:" | tee -a "$GITHUB_STEP_SUMMARY"
du -sh "${source_base}" "${source_tarball}" "${source_zipfile}" | tee -a "$GITHUB_STEP_SUMMARY"
echo "Installation Packages:" | tee -a "$GITHUB_STEP_SUMMARY"
du -sh "${package_base}" "${package_tarball}" "${package_zipfile}" | tee -a "$GITHUB_STEP_SUMMARY"
echo "::endgroup::"
rm -rf "${source_base}" "${package_base}"
- name: Tag
if: ${{ !inputs.skip_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a -m "CCCL Release ${release_tag}" "${release_tag}" "${rc_tag}"
git push origin "${release_tag}"
echo "Tagged release ${release_tag} from ${rc_tag}." | tee -a "$GITHUB_STEP_SUMMARY"
- name: Draft Github Release
run: |
version_bump=$(git log -n 1 --pretty=format:%H --grep 'Bump [/A-Za-z]* to [0-9]*\.[0-9]*\.[0-9]*')
closest_tag=$(git describe --abbrev=0 "$version_bump")
note_gen=()
if [ "${{ github.event.inputs.skip_generating_notes }}" = "false" ]; then
note_gen=(--generate-notes)
fi
gh release create "${release_tag}" \
--draft \
"${note_gen[@]}" \
--notes-start-tag "${closest_tag}" \
--title "${release_tag}" \
"${source_zipfile}#Source Archive (zip)" \
"${source_tarball}#Source Archive (tar.gz)" \
"${package_zipfile}#Installation Archive (zip)" \
"${package_tarball}#Installation Archive (tar.gz)"
- name: Notify Slack
if: ${{ success() }}
uses: slackapi/slack-github-action@v1.26.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFIER_BOT_TOKEN }}
SUMMARY_URL: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
RC_TAG: ${{ steps.prepare.outputs.rc_tag }}
RELEASE_TAG: ${{ steps.prepare.outputs.release_tag }}
RELEASE_URL: https://github.com/${{github.repository}}/releases/tag/${{ steps.prepare.outputs.release_tag }}
with:
channel-id: ${{ secrets.SLACK_CHANNEL_RELEASE_LOG }}
slack-message: |
Release `${{ env.RELEASE_TAG }}` has been created from `${{ env.RC_TAG }}`.
A draft Github release has been prepared at ${{ env.RELEASE_URL }}.
Workflow summary: ${{ env.SUMMARY_URL }}
- name: Notify Slack (failure)
if: ${{ failure() }}
uses: slackapi/slack-github-action@v1.26.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFIER_BOT_TOKEN }}
SUMMARY_URL: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
with:
channel-id: ${{ secrets.SLACK_CHANNEL_RELEASE_LOG }}
slack-message: |
An error has occurred while creating a release from ${{ github.ref }}.
Details: ${{ env.SUMMARY_URL }}
create-point-version:
if: ${{ inputs.create_patch_version }}
runs-on: ubuntu-latest
needs: create-release
env:
GH_TOKEN: ${{ github.token }}
permissions:
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v6
- name: Create patch version PR
uses: ./.github/actions/version-update
with:
new_version: ${{ needs.create-release.outputs.next_full_version }}
target_branch: ${{ needs.create-release.outputs.working_branch }}