Skip to content

Commit 528b009

Browse files
kratsgmatthewfeickert
authored andcommitted
fix: Correct reference check in GitHub Actions publish to TestPyPI step (#640)
* More fixes to workflow in #639, only push to testpypi on pushes on master * Only use scm if the current commit is not tagged * Protect forks from publishing
1 parent 6f50690 commit 528b009

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.github/workflows/publish-package.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ jobs:
2323
run: |
2424
python -m pip install pep517 --user
2525
- name: Build a binary wheel and a source tarball
26+
env:
27+
IS_COMMIT_TAGGED: >-
28+
${{ startsWith(github.ref, 'refs/tags') }}
2629
run: |
2730
python -m pep517.build --source --binary --out-dir dist/ .
2831
- name: Publish distribution 📦 to Test PyPI
29-
if: github.event_name == 'push'
32+
# every PR will trigger a push event on master, so check the push event is actually coming from master
33+
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'diana-hep/pyhf'
3034
uses: pypa/[email protected]
31-
env:
32-
IS_TESTPYPI: ${{ true }}
3335
with:
3436
password: ${{ secrets.test_pypi_password }}
3537
repository_url: https://test.pypi.org/legacy/
3638
- name: Publish distribution 📦 to PyPI
37-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
39+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && github.repository == 'diana-hep/pyhf'
3840
uses: pypa/[email protected]
3941
with:
4042
password: ${{ secrets.pypi_password }}

setup.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
long_description = readme_md.read()
1010

1111
extras_require = {
12-
'tensorflow': ['tensorflow~=1.15', 'tensorflow-probability~=0.8', 'numpy~=1.16',],
12+
'tensorflow': ['tensorflow~=1.15', 'tensorflow-probability~=0.8', 'numpy~=1.16'],
1313
'torch': ['torch~=1.2'],
1414
'xmlio': ['uproot'],
1515
'minuit': ['iminuit'],
@@ -50,22 +50,20 @@
5050

5151
def _is_test_pypi():
5252
"""
53-
Determine if the CI environment has IS_TESTPYPI defined and
54-
set to true (c.f. .github/workflows/publish-package.yml)
55-
53+
Determine if the CI environment has IS_COMMIT_TAGGED defined and
54+
set to true (c.f. .github/workflows/publish-package-to-pypi.yml)
5655
The use_scm_version kwarg accepts a callable for the local_scheme
5756
configuration parameter with argument "version". This can be replaced
5857
with a lambda as the desired version structure is {next_version}.dev{distance}
5958
c.f. https://github.com/pypa/setuptools_scm/#importing-in-setuppy
60-
6159
As the scm versioning is only desired for TestPyPI, for depolyment to PyPI the version
6260
controlled through bumpversion is used.
6361
"""
6462
from os import getenv
6563

6664
return (
6765
{'local_scheme': lambda version: ''}
68-
if getenv('IS_TESTPYPI') == 'true'
66+
if getenv('IS_COMMIT_TAGGED') == 'false'
6967
else False
7068
)
7169

0 commit comments

Comments
 (0)