Skip to content

Commit ad629c9

Browse files
committed
Add github actions upload to PyPI action
1 parent e7443d1 commit ad629c9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

.github/workflows/release.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: PyPI release
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
build:
8+
name: Build source distribution
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- uses: actions/setup-python@v4
15+
with:
16+
python-version: 3.8
17+
- name: Build the sdist and the wheel
18+
run: |
19+
pip install build
20+
python -m build
21+
- name: Check the sdist installs and imports
22+
run: |
23+
mkdir -p test-sdist
24+
cd test-sdist
25+
python -m venv venv-sdist
26+
venv-sdist/bin/python -m pip install ../dist/CausalPy*.tar.gz
27+
# check import
28+
venv-sdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}'"
29+
- name: Check the bdist installs and imports
30+
run: |
31+
mkdir -p test-bdist
32+
cd test-bdist
33+
python -m venv venv-bdist
34+
venv-bdist/bin/python -m pip install ../dist/CausalPy*.whl
35+
# check import
36+
venv-bdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}'"
37+
- uses: actions/upload-artifact@v3
38+
with:
39+
name: artifact
40+
path: dist/*
41+
test:
42+
name: Upload to Test PyPI
43+
needs: [build]
44+
runs-on: ubuntu-latest
45+
if: github.event_name == 'release' && github.event.action == 'published'
46+
steps:
47+
- uses: actions/download-artifact@v3
48+
with:
49+
name: artifact
50+
path: dist
51+
- uses: pypa/gh-action-pypi-publish@release/v1
52+
with:
53+
skip_existing: true
54+
user: __token__
55+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
56+
repository_url: https://test.pypi.org/legacy/
57+
- uses: actions/setup-python@v4
58+
with:
59+
python-version: 3.8
60+
- name: Test pip install from test.pypi
61+
run: |
62+
python -m venv venv-test-pypi
63+
venv-test-pypi/bin/python -m pip install --index-url https://test.pypi.org/simple/ causalpy
64+
# check import
65+
venv-test-pypi/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}'"
66+
67+
publish:
68+
name: Upload release to PyPI
69+
needs: [build, test]
70+
runs-on: ubuntu-latest
71+
if: github.event_name == 'release' && github.event.action == 'published'
72+
steps:
73+
- uses: actions/download-artifact@v3
74+
with:
75+
name: artifact
76+
path: dist
77+
- uses: pypa/gh-action-pypi-publish@release/v1
78+
with:
79+
user: __token__
80+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)