-
Notifications
You must be signed in to change notification settings - Fork 163
192 lines (162 loc) · 7.17 KB
/
release-finalize.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
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
# 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:
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 }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- 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 full_version major_version minor_version patch_version rc release_tag rc_tag repo_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=$(echo "${release_tag}" | sed 's/\./\\./g')
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}" >> $GITHUB_ENV
echo "source_zipfile=${source_zipfile}" >> $GITHUB_ENV
echo "package_tarball=${package_tarball}" >> $GITHUB_ENV
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
run: |
git config user.name github-actions
git config user.email [email protected]
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: |
gh release create ${release_tag} \
--draft \
--generate-notes \
--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/[email protected]
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/[email protected]
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 }}