Skip to content

Commit bdbc581

Browse files
Merge pull request #13 from astrofrog/upload-to-pypi-update
Update how upload_to_pypi is defined
2 parents 5f6561c + 8c24e1d commit bdbc581

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

.github/workflows/publish.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ on:
3232
default: ''
3333
type: string
3434
upload_to_pypi:
35-
description: Always upload to PyPI after successful builds - if false, only upload when pushing tags
35+
description: A condition specifying whether to upload to PyPI
3636
required: false
37-
default: false
38-
type: boolean
37+
default: 'refs/tags/v'
38+
type: string
3939
repository_url:
4040
description: The PyPI repository URL to use
4141
required: false
@@ -58,6 +58,7 @@ jobs:
5858
runs-on: ubuntu-latest
5959
outputs:
6060
matrix: ${{ steps.set-outputs.outputs.matrix }}
61+
upload_to_pypi: ${{ steps.set-upload.outputs.upload_to_pypi }}
6162
steps:
6263
- uses: actions/checkout@v2
6364
with:
@@ -69,6 +70,17 @@ jobs:
6970
- id: set-outputs
7071
run: python tools/load_build_targets.py --targets "${{ inputs.targets }}"
7172
shell: sh
73+
- id: set-upload
74+
run: |
75+
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];
76+
then
77+
echo "::set-output name=upload_to_pypi::true"
78+
else
79+
echo "::set-output name=upload_to_pypi::false"
80+
fi
81+
env:
82+
UPLOAD_TO_PYPI: ${{ inputs.upload_to_pypi }}
83+
UPLOAD_TAG: ${{ startsWith(inputs.upload_to_pypi, 'refs/tags/') && github.event_name == 'push' && startsWith(github.event.ref, inputs.upload_to_pypi) }}
7284

7385
build_wheels:
7486
name: Build ${{ matrix.target }} wheels
@@ -127,11 +139,14 @@ jobs:
127139

128140
upload_pypi:
129141
name: Upload to PyPI
130-
needs: [build_wheels, build_sdist]
142+
needs: [targets, build_wheels, build_sdist]
131143
runs-on: ubuntu-latest
132144
if: |
133-
(( github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')) || inputs.upload_to_pypi ) &&
134-
needs.build_wheels.result != 'failure' && needs.build_sdist.result != 'failure'
145+
always() &&
146+
needs.targets.result == 'success' &&
147+
needs.targets.outputs.upload_to_pypi == 'true' &&
148+
needs.build_wheels.result != 'failure' &&
149+
needs.build_sdist.result != 'failure'
135150
steps:
136151
- uses: actions/download-artifact@v2
137152
with:

.github/workflows/publish_pure_python.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ on:
1919
default: ''
2020
type: string
2121
upload_to_pypi:
22-
description: Always upload to PyPI after successful builds - if false, only upload when pushing tags
22+
description: A condition specifying whether to upload to PyPI
2323
required: false
24-
default: false
25-
type: boolean
24+
default: 'refs/tags/v'
25+
type: string
2626
repository_url:
2727
description: The PyPI repository URL to use
2828
required: false
@@ -59,9 +59,20 @@ jobs:
5959
test_extras: ${{ inputs.test_extras }}
6060
test_command: ${{ inputs.test_command }}
6161
pure_python_wheel: true
62+
- id: set-upload
63+
run: |
64+
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];
65+
then
66+
echo "::set-output name=upload_to_pypi::true"
67+
else
68+
echo "::set-output name=upload_to_pypi::false"
69+
fi
70+
env:
71+
UPLOAD_TO_PYPI: ${{ inputs.upload_to_pypi }}
72+
UPLOAD_TAG: ${{ startsWith(inputs.upload_to_pypi, 'refs/tags/') && github.event_name == 'push' && startsWith(github.event.ref, inputs.upload_to_pypi) }}
6273
- uses: pypa/gh-action-pypi-publish@master
6374
name: Upload to PyPI
64-
if: (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')) || inputs.upload_to_pypi
75+
if: ${{ steps.set-upload.outputs.upload_to_pypi == 'true' }}
6576
with:
6677
user: __token__
6778
password: ${{ secrets.pypi_token }}

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,14 @@ Packages needed to build the source distribution for testing. Must be a string o
262262
Default is install nothing extra.
263263

264264
#### upload_to_pypi
265-
Whether to always upload to PyPI after successful builds.
266-
If `false`, successful builds are only uploaded when tags are pushed.
267-
Default is `false`.
265+
Whether to upload to PyPI after successful builds.
266+
The default is to upload to PyPI when tags that start with `v` are pushed.
267+
A boolean can be passed as `true` (always upload) or `false` (never upload)
268+
either explicitly or as a boolean expression (`${{ <expression> }}`).
269+
270+
Alternatively, a string can be passed to match the start of a tag ref.
271+
For example, `'refs/tags/v'` (default) will upload tags that begin with `v`,
272+
and `'refs/tags/'` will upload on all pushed tags.
268273

269274
#### repository_url
270275
The PyPI repository URL to use.
@@ -310,9 +315,14 @@ Packages needed to build the source distribution for testing. Must be a string o
310315
Default is install nothing extra.
311316

312317
#### upload_to_pypi
313-
Whether to always upload to PyPI after successful builds.
314-
If `false`, successful builds are only uploaded when tags are pushed.
315-
Default is `false`.
318+
Whether to upload to PyPI after successful builds.
319+
The default is to upload to PyPI when tags that start with `v` are pushed.
320+
A boolean can be passed as `true` (always upload) or `false` (never upload)
321+
either explicitly or as a boolean expression (`${{ <expression> }}`).
322+
323+
Alternatively, a string can be passed to match the start of a tag ref.
324+
For example, `'refs/tags/v'` (default) will upload tags that begin with `v`,
325+
and `'refs/tags/'` will upload on all pushed tags.
316326

317327
#### repository_url
318328
The PyPI repository URL to use.

0 commit comments

Comments
 (0)