-
Notifications
You must be signed in to change notification settings - Fork 85
93 lines (81 loc) · 3.27 KB
/
publish-package.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
name: publish distributions
on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
workflow_dispatch:
jobs:
build-and-publish:
name: Build and publish Python distro to (Test)PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install python-build, check-manifest, and twine
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install build check-manifest twine
python -m pip list
- name: Check MANIFEST
run: |
check-manifest
- name: Build a wheel and a sdist
run: |
python -m build --outdir dist/ .
- name: Verify untagged commits have dev versions
if: "!startsWith(github.ref, 'refs/tags/')"
run: |
latest_tag=$(git describe --tags)
latest_tag_revlist_SHA=$(git rev-list -n 1 ${latest_tag})
master_SHA="$(git rev-parse --verify origin/master)"
wheel_name=$(find dist/ -iname "*.whl" -printf "%f\n")
if [[ "${latest_tag_revlist_SHA}" != "${master_SHA}" ]]; then # don't check master push events coming from tags
if [[ "${wheel_name}" == *"pyhf-0.1.dev"* || "${wheel_name}" != *"dev"* ]]; then
echo "python-build incorrectly named built distribution: ${wheel_name}"
echo "python-build is lacking the history and tags required to determine version number"
echo "intentionally erroring with 'return 1' now"
return 1
fi
else
echo "Push event to origin/master was triggered by push of tag ${latest_tag}"
fi
echo "python-build named built distribution: ${wheel_name}"
- name: Verify tagged commits don't have dev versions
if: startsWith(github.ref, 'refs/tags')
run: |
wheel_name=$(find dist/ -iname "*.whl" -printf "%f\n")
if [[ "${wheel_name}" == *"dev"* ]]; then
echo "python-build incorrectly named built distribution: ${wheel_name}"
echo "this is incorrrectly being treated as a dev release"
echo "intentionally erroring with 'return 1' now"
return 1
fi
echo "python-build named built distribution: ${wheel_name}"
- name: Verify the distribution
run: twine check dist/*
- name: List contents of sdist
run: python -m tarfile --list dist/pyhf-*.tar.gz
- name: List contents of wheel
run: python -m zipfile --list dist/pyhf-*.whl
- name: Publish distribution 📦 to Test PyPI
# every PR will trigger a push event on master, so check the push event is actually coming from master
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'scikit-hep/pyhf'
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && github.repository == 'scikit-hep/pyhf'
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
password: ${{ secrets.pypi_password }}