forked from Billingegroup/release-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (143 loc) · 5.52 KB
/
_build-wheel-release-upload.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
name: Build Wheel, Release, Upload
on:
workflow_call:
inputs:
project:
description: 'Name of the project to test'
default: 'PROJECT_NAME'
required: false
type: string
c_extension:
description: 'Whether the project has a C extension'
default: false
required: false
type: boolean
secrets:
PYPI_TOKEN:
description: 'PyPI token'
required: true
PAT_TOKEN:
description: 'GitHub Personal Access Token'
required: true
jobs:
tag-privilege-check:
uses: ./.github/workflows/_release_tag_privilege_check.yml
build-pure-python-package:
needs: [tag-privilege-check]
if: inputs.c_extension == false
uses: ./.github/workflows/_build-pure-python-package.yml
build-non-pure-python-package:
needs: [tag-privilege-check]
if: inputs.c_extension == true
uses: ./.github/workflows/_build-non-pure-python-package.yml
update-changelog:
needs: [build-pure-python-package, build-non-pure-python-package]
# The always() function is necessary to ensure that we wait for both build jobs to complete, even if one of them is skipped.
# Without always(), if one of the needed jobs is skipped, the `update-changelog` job will not be executed.
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail update-changelog job if building failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package }}" == 'success' ]; then
echo "Ready to update CHANGELOG.rst..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.PAT_TOKEN }}
- name: Update CHANGELOG.rst with the latest news
run: |
wget https://raw.githubusercontent.com/Billingegroup/release-scripts/v0/.github/workflows/update-changelog.py
python update-changelog.py "${{ github.ref_name }}"
rm update-changelog.py
- name: Commit the changes in CHANGELOG.rst
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: update changelog
branch: main
github-pre-release:
needs: [build-pure-python-package, build-non-pure-python-package]
if: "always() && contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-pre-release job if building job failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package }}" == 'success' ]; then
echo "Ready to pre-release on GitHub..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi
- name: Generate GH release notes for pre-release
uses: softprops/action-gh-release@v2
with:
draft: true # FIXME: remove after testing
prerelease: true
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
github-release:
needs: [update-changelog]
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-release job if CHANGELOG udpate failed
run: |
if [ "${{ needs.update-changelog.result }}" == 'success' ]; then
echo "Ready to release on GitHub..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Generate GH release notes for release
run: |
wget https://raw.githubusercontent.com/Billingegroup/release-scripts/v0/.github/workflows/get-latest-changelog.py
python get-latest-changelog.py "${{ github.ref_name }}"
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
draft: true # FIXME: remove after testing
token: ${{ secrets.GITHUB_TOKEN }}
pypi-publish:
needs: [github-pre-release, github-release]
runs-on: ubuntu-latest
if: always() # This job will always initiate regardless of the success or failure of the needed jobs
steps:
- name: Fail pypi-publish step if github-(pre)-release step failed
run: |
if [ "${{ needs.github-pre-release.result }}" == 'success' ] || [ "${{ needs.github-release.result }}" == 'success' ]; then
echo "Ready for PyPI release..."
else
echo "Previous github-(pre)-release step failed; exiting..."
exit 1
fi
- uses: actions/download-artifact@v4
with:
pattern: '**/*' # Make sure all files are downloaded, including wheels
path: dist
merge-multiple: true
- name: Setup Python for PyPI upload
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Twine
run: |
python -m pip install --upgrade pip
pip install twine
- name: Publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
# TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
# twine upload dist/* --verbose
run: |
twine upload --repository testpypi dist/* --verbose