-
Notifications
You must be signed in to change notification settings - Fork 4
203 lines (193 loc) · 5.95 KB
/
reusable-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
# This is a reusable workflow for building source distributions (sdist) and wheels of a given target package.
# The target package must be coupled with a Makefile with the following recipes: version, setup-dev, package, publish, publish-test
name: Build and Publish
on:
workflow_call:
inputs:
package-path:
type: string
description: Path to the package root directory.
required: false
default: "."
version-increment:
type: boolean
description: Increment patch version number.
required: false
default: true
package-wheels:
type: boolean
description: Package wheels.
required: false
default: true
publish-test:
type: boolean
description: Publish to PyPI test.
required: false
default: true
publish:
type: boolean
description: Publish to PyPI.
required: false
default: true
pypi-api-token-secret:
type: string
description: Name of the PyPI API token secret.
required: false
default: "PYPI_API_TOKEN_DATASCOPE"
pypi-test-api-token-secret:
type: string
description: Name of the PyPI Test API token secret.
required: false
default: "PYPI_TEST_API_TOKEN_DATASCOPE"
workflow_dispatch:
inputs:
package-path:
type: string
description: Path to the package root directory.
required: false
default: "."
version-increment:
type: boolean
description: Increment patch version number.
required: false
default: true
package-wheels:
type: boolean
description: Package wheels.
required: false
default: true
publish-test:
type: boolean
description: Publish to PyPI test.
required: false
default: true
publish:
type: boolean
description: Publish to PyPI.
required: false
default: true
pypi-api-token-secret:
type: string
description: Name of the PyPI API token secret.
required: false
default: "PYPI_API_TOKEN_DATASCOPE"
pypi-test-api-token-secret:
type: string
description: Name of the PyPI Test API token secret.
required: false
default: "PYPI_TEST_API_TOKEN_DATASCOPE"
env:
python-version: "3.9"
jobs:
version:
name: Increment Patch Version Number
runs-on: ubuntu-latest
if: inputs.version-increment == true
outputs:
sha: ${{ steps.sha.outputs.SHA }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.python-version }}
- name: Increment Version
working-directory: ${{ inputs.package-path }}
run: |
make version
- name: Commit Version File
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Increment Patch Version Number
file_pattern: "*version.py"
- name: Get SHA of the Latest Commit
id: sha
run: |
sha_new=$(git rev-parse HEAD)
echo $sha_new
echo "SHA=$sha_new" >> $GITHUB_OUTPUT
package_sdist:
name: Package Python Source Distribution
needs: version
if: ${{ always() && !contains(join(needs.*.result, ','), 'failure') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.version.outputs.sha }}
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make setup-dev
- name: Package sdist
working-directory: ${{ inputs.package-path }}
run: |
make package
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: ${{ inputs.package-path }}/dist/*.tar.gz
package_wheels:
name: Package wheels on ${{ matrix.os }}
needs: version
if: ${{ always() && inputs.package-wheels == true && !contains(join(needs.*.result, ','), 'failure') }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.version.outputs.sha }}
- uses: actions/setup-python@v3
name: Install Python
with:
python-version: ${{ env.python-version }}
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_SKIP: cp36-* pp*
with:
package-dir: ${{ inputs.package-path }}
output-dir: ${{ inputs.package-path }}/dist
- uses: actions/upload-artifact@v3
with:
path: ${{ inputs.package-path }}/dist/*.whl
publish:
name: Publish to PyPi
needs: [package_sdist, package_wheels]
runs-on: ubuntu-latest
if: (inputs.publish-test == true || inputs.publish == true) && always() && contains(join(needs.*.result, ','), 'success')
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- uses: actions/download-artifact@v3
with:
name: artifact
path: ${{ inputs.package-path }}/dist
- name: Publish to PyPI Test
if: inputs.publish-test == true
working-directory: ${{ inputs.package-path }}
env:
TWINE_PASSWORD: ${{ secrets[inputs.pypi-test-api-token-secret] }}
run: |
make publish-test
- name: Publish to PyPI
if: inputs.publish == true
working-directory: ${{ inputs.package-path }}
env:
TWINE_PASSWORD: ${{ secrets[inputs.pypi-api-token-secret] }}
run: |
make publish