-
Notifications
You must be signed in to change notification settings - Fork 1
256 lines (225 loc) · 8.87 KB
/
publish.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
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
249
250
251
252
253
254
255
256
name: ODS-tools Release
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag to publish as [semvar]'
required: true
prev_release_tag:
description: 'The previous release version [semvar]'
required: true
pre_release:
description: 'Mark GitHub release as pre-release: [true, false]'
required: true
default: 'false'
env:
RELEASE_TAG: ${{ inputs.release_tag }}
PREV_RELEASE_TAG: ${{ inputs.prev_release_tag }}
PRE_RELEASE: ${{ inputs.pre_release }}
jobs:
update:
uses: ./.github/workflows/version.yml
secrets: inherit
with:
package_version: ${{ inputs.release_tag }}
package:
uses: ./.github/workflows/build.yml
secrets: inherit
needs: update
release:
runs-on: ubuntu-latest
needs: package
outputs:
heading: ${{ steps.slack_vars.outputs.heading }}
title: ${{ steps.slack_vars.outputs.title }}
build_branch: ${{ steps.slack_vars.outputs.branch }}
run_url: ${{ steps.slack_vars.outputs.run_url }}
run_id: ${{ steps.slack_vars.outputs.run_id }}
run_status: ${{ steps.slack_vars.outputs.run_status }}
run_date: ${{ steps.slack_vars.outputs.run_date }}
steps:
- name: is branch valid for release
if: ${{ !startsWith(github.ref_name , 'release/') }}
run: |
echo "Releases must be trigged on branch named 'release/x.x.x'"
exit 1
- name: Check tag is valid for release
if: env.PRE_RELEASE == 'false'
run: |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)$")
if [[ ! "$VALID" == 1 ]]; then
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid"
exit 1
fi
- name: Check tag is valid for pre-release
if: env.PRE_RELEASE == 'true'
run: |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)rc(\d+)$")
if [[ ! "$VALID" == 1 ]]; then
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid"
exit 1
fi
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Check tag matches version set
run: |
BUILD_VER=$(grep '__version__' ods_tools/__init__.py | awk -F"'" '{print $2}')
RELEASE_VER=${{ env.RELEASE_TAG }}
[[ "$RELEASE_VER" = "$BUILD_VER" ]] && ERROR_CODE=0 || ERROR_CODE=1
if [[ "$ERROR_CODE" == 1 ]]; then
echo "PACKAGE_VER: $BUILD_VER stored in 'ods_tools/__init__.py' dosn't match RELEASE_TAG: $RELEASE_VER" && exit $ERROR_CODE
fi
- name: Test package names
run: |
ERROR_CODE=0
SRC_VER=$(echo ${{ needs.package.outputs.src_filename }} | grep -oP "(\d+)\.(\d+)\.(\d+)rc(\d+)|(\d+)\.(\d+)\.(\d+)")
BIN_VER=$(echo ${{ needs.package.outputs.whl_filename }} | grep -oP "(\d+)\.(\d+)\.(\d+)rc(\d+)|(\d+)\.(\d+)\.(\d+)")
[[ "${{ env.RELEASE_TAG }}" = "$SRC_VER" ]] || ERROR_CODE=1
[[ "${{ env.RELEASE_TAG }}" = "$BIN_VER" ]] || ERROR_CODE=1
if [[ "$ERROR_CODE" == 1 ]]; then
echo "Package names don't match release tag."
echo " RELEASE_TAG: ${{ env.RELEASE_TAG }}"
echo " PACKAGES: ${{ needs.package.outputs.src_filename }}, ${{ needs.package.outputs.whl_filename }}"
exit $ERROR_CODE
fi
- name: Setup github user
run: |
git config --global user.email ${{ env.GIT_EMAIL }}
git config --global user.name ${{ env.GIT_USERNAME }}
git config --global pull.ff only
env:
GIT_EMAIL: ${{ secrets.BUILD_GIT_EMAIL }}
GIT_USERNAME: ${{ secrets.BUILD_GIT_USERNAME }}
- name: Tag Release
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
run: |
git checkout ${{ github.ref_name }}
git tag ${{ env.RELEASE_TAG }}
# --- Create Changelog --- #
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Setup Changelog builder
run: |
BRANCH='main'
BASE_URL="https://raw.githubusercontent.com/OasisLMF/OasisPlatform/$BRANCH/scripts"
pip install -r $BASE_URL/requirments-changelog.txt
wget $BASE_URL/update-changelog.py
chmod +x update-changelog.py
- name: Create changelog
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
run: |
${{ github.workspace }}/update-changelog.py build-changelog \
--repo ${{ github.event.repository.name }} \
--from-tag ${{ env.PREV_RELEASE_TAG }} \
--to-tag ${{ env.RELEASE_TAG }} \
--github-token ${{ secrets.BUILD_GIT_TOKEN }} \
--local-repo-path ./ \
--output-path ./CHANGELOG.rst \
--apply-milestone
git add ./CHANGELOG.rst
git commit -m 'Update changelog'
- name: Create Release notes
working-directory: ${{ env.WORKSPACE }}
run: |
${{ github.workspace }}/update-changelog.py build-release \
--repo ${{ github.event.repository.name }} \
--from-tag ${{ env.PREV_RELEASE_TAG }} \
--to-tag ${{ env.RELEASE_TAG }} \
--github-token ${{ secrets.BUILD_GIT_TOKEN }} \
--local-repo-path ./ \
--output-path ./RELEASE.md
# --- Sign packages --- #
- name: Download Source package
uses: actions/download-artifact@v4
with:
name: src_package
path: ${{ github.workspace }}/
- name: Download Linux package
uses: actions/download-artifact@v4
with:
name: bin_package
path: ${{ github.workspace }}/
# --- Create Release --- #
- name: Push changes
run: |
git push origin ${{ env.RELEASE_TAG }}
git push
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: Release ${{ env.RELEASE_TAG }}
body_path: ${{ github.workspace }}/RELEASE.md
draft: false
prerelease: ${{ env.PRE_RELEASE }}
# --- Attach build assest --- #
- name: Upload Source package
id: upload-source-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/${{ needs.package.outputs.src_filename }}
asset_name: ${{ needs.package.outputs.src_filename }}
asset_content_type: application/octet-stream
- name: Upload Wheel package
id: upload-linux-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/${{ needs.package.outputs.whl_filename }}
asset_name: ${{ needs.package.outputs.whl_filename }}
asset_content_type: application/octet-stream
# --- Publish to Pypi --- #
- name: Setup Twine
run: pip install twine
- name: PYPI - Source package
run: twine upload ${{ needs.package.outputs.src_filename }}
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
- name: PYPI - Linux package
run: twine upload ${{ needs.package.outputs.whl_filename }}
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
# --- Slack notify --- #
- name: slack message vars
id: slack_vars
run: |
HEAD=$(echo "*${{ github.event.repository.name}} Release* (${{ env.RELEASE_TAG }})")
DATE=$(date)
TITLE=$(echo "• <https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_TAG }}|${{ github.event.repository.name }} ${{ env.RELEASE_TAG }} - Release Notes>")
JOB_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
echo "heading=$HEAD" >> $GITHUB_OUTPUT
echo "run_date=$DATE" >> $GITHUB_OUTPUT
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "run_url=$JOB_URL" >> $GITHUB_OUTPUT
echo "run_id=${{ github.run_id }}" >> $GITHUB_OUTPUT
echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "run_status=${{ job.status }}" >> $GITHUB_OUTPUT
slack:
uses: OasisLMF/OasisLMF/.github/workflows/notify.yml@main
secrets: inherit
needs: release
with:
heading: ${{ needs.release.outputs.heading }}
title: ${{ needs.release.outputs.title }}
build_branch: ${{ needs.release.outputs.build_branch }}
run_url: ${{ needs.release.outputs.run_url }}
run_id: ${{ needs.release.outputs.run_id }}
run_status: ${{ needs.release.outputs.run_status }}
run_date: ${{ needs.release.outputs.run_date }}