-
Notifications
You must be signed in to change notification settings - Fork 111
233 lines (210 loc) · 7.87 KB
/
Copy pathrelease.yml
File metadata and controls
233 lines (210 loc) · 7.87 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
# Copyright 2021 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# 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
on:
workflow_dispatch:
inputs:
stable_version:
description: "Stable version number, e.g. 0.32.3. Mandatory if a stable release is being created."
type: string
test_release:
description: "Test the workflow but don't create the release. Uncheck this box to create a release."
required: true
type: boolean
default: true
workflow_call:
inputs:
prerelease:
description: "true: Create a prerelease. false: Create a stable release."
required: true
type: boolean
default: true
permissions:
id-token: write
contents: read
env:
PAUL_BLART: >
'['
'"AlejandroEsquivel",'
'"FyzHsn",'
'"wjcunningham7",'
'"kessler-frost",'
'"santoshkumarradha"]'
jobs:
github:
runs-on: ubuntu-latest
outputs:
release: ${{ env.RELEASE }}
steps:
- name: Check out stable release tag
uses: actions/checkout@v4
if: github.event.inputs.stable_version
with:
persist-credentials: false
fetch-depth: 0
ref: "v${{ github.event.inputs.stable_version }}"
- name: Check out master branch for prerelease
uses: actions/checkout@v4
if: inputs.prerelease
with:
persist-credentials: false
fetch-depth: 0
ref: "master"
- name: Read version
run: |
if [ -z ${{ inputs.prerelease }} ] && \
[ -z ${{ github.event.inputs.stable_version }} ] ; then
echo "You can't create a stable release without specifying the stable version number."
exit 1
fi
VERSION="$(cat ./VERSION)"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE=v$VERSION" >> $GITHUB_ENV
- name: Tag commit for prerelease
if: inputs.prerelease
id: push
run: |
git config user.name "CovalentOpsBot"
git config user.email "covalentopsbot@users.noreply.github.com"
git tag -a $RELEASE -m "Release $RELEASE"
git remote set-url origin https://${{ secrets.COVALENT_OPS_BOT_TOKEN }}@github.com/AgnostiqHQ/covalent.git
git push origin $RELEASE
- name: Generate stable release message
if: >
github.event.inputs.stable_version
&& contains(env.PAUL_BLART, github.actor)
id: stable-changelog
uses: AgnostiqHQ/covalent/.github/actions/stable-changelog@develop
with:
changelog-path: CHANGELOG.md
version-path: VERSION
- name: Generate prerelease message
if: inputs.prerelease
id: message
run: |
begin=$(grep -n "\b${VERSION}\b" ./CHANGELOG.md | cut -d ':' -f 1)
previous_version=$(git describe --abbrev=0 $RELEASE^ | cut -c2-)
end=$(tail -n +$((begin+1)) ./CHANGELOG.md | grep -n -m 1 "\b${previous_version}\b" | cut -d ':' -f 1)
echo 'MESSAGE<<EOF' >> $GITHUB_ENV
tail +$begin ./CHANGELOG.md | head -$end >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Create prerelease
if: >-
inputs.prerelease
&& ${{ steps.push.outcome == 'success'
&& steps.message.outcome == 'success'
&& (!github.event.inputs.test_release || github.event.inputs.test_release == 'false') }}
uses: ncipollo/release-action@v1
with:
body: ${{ env.MESSAGE }}
token: ${{ secrets.COVALENT_OPS_BOT_TOKEN }}
tag: ${{ env.RELEASE }}
prerelease: ${{ inputs.prerelease }}
- name: Create stable release
if: >-
github.event.inputs.stable_version
&& contains(env.PAUL_BLART, github.actor)
&& steps.stable-changelog.outcome == 'success'
&& (!github.event.inputs.test_release || github.event.inputs.test_release == 'false')
uses: ncipollo/release-action@v1
with:
body: ${{ steps.stable-changelog.outputs.message }}
token: ${{ secrets.COVALENT_OPS_BOT_TOKEN }}
tag: ${{ env.RELEASE }}
- name: Alert Slack
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: "covalent-ci"
SLACK_USERNAME: "CovalentOpsBot"
SLACK_MESSAGE: "The release.yml workflow is failing in ${{ github.ref }}!"
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ":warning: Attention Required :warning:"
SLACK_WEBHOOK: ${{ secrets.SLACK_ALERT_WEBHOOK }}
pypi:
runs-on: ubuntu-latest
needs: github
outputs:
version: ${{ steps.validate.outputs.version }}
steps:
- name: Check out release tag
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ needs.github.outputs.release }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.13"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 20
- name: Build Webapp
run: |
cd ./covalent_ui/webapp
yarn install
yarn build
- name: Build Stable or Pre-Release Distribution
id: pre-or-stable-build
run: python setup.py sdist
- name: Transform semver version to pep440
id: version-transform
uses: ./.github/actions/version-transform
with:
version-path: VERSION
- name: Validate Distribution
id: validate
run: |
if [ -z ${{ inputs.prerelease }} ] && \
[ -z ${{ github.event.inputs.stable_version }} ] ; then
echo "You can't create a stable release without specifying the stable version number."
exit 1
fi
VERSION="${{ steps.version-transform.outputs.version }}"
cd dist
tar xzf covalent-${VERSION}.tar.gz
diff -x .gitignore -r covalent-${VERSION}/covalent ../covalent
diff -x .gitignore -r covalent-${VERSION}/covalent_dispatcher ../covalent_dispatcher
diff -x README.md -r covalent-${VERSION}/covalent_migrations ../covalent_migrations
diff -x .gitignore -x README.md -x webapp covalent-${VERSION}/covalent_ui ../covalent_ui
diff -r covalent-${VERSION}/covalent_ui/webapp/build ../covalent_ui/webapp/build
rm -rf covalent-${VERSION}/
echo "::set-output name=version::$VERSION"
- name: Upload Distribution
if: >
steps.pre-or-stable-build.outcome == 'success'
&& steps.validate.outcome == 'success'
&& ${{ !github.event.inputs.test_release }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
- name: Alert Slack
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: "covalent-ci"
SLACK_USERNAME: "CovalentOpsBot"
SLACK_MESSAGE: "The release.yml workflow is failing in ${{ github.ref }}!"
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ":warning: Attention Required :warning:"
SLACK_WEBHOOK: ${{ secrets.SLACK_ALERT_WEBHOOK }}