-
-
Notifications
You must be signed in to change notification settings - Fork 126
92 lines (76 loc) · 2.59 KB
/
publish-pypi.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
name: Publish tagged releases to PyPI
on:
release:
types:
- created
jobs:
build:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: python3 -m pip install --upgrade build
- name: Build
run: python3 -m build
- name: Upload source distribution artifact
uses: actions/upload-artifact@v4
with:
name: artifact
path: dist/*
test:
name: Upload release to test PyPI
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Download source distribution artifact
uses: actions/download-artifact@v4
with:
name: artifact
path: dist
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install twine
run: python3 -m pip install --upgrade twine
- name: Publish library
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: python3 -m twine upload --skip-existing --repository testpypi dist/*
- name: Test pip install from test.pypi
run: |
python -m venv venv-test-pypi
venv-test-pypi/bin/python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple bambi
venv-test-pypi/bin/python -c "import bambi; assert bambi.__version__ == '${{ github.ref_name }}'"
publish:
name: Upload release to PyPI
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download source distribution artifact
uses: actions/download-artifact@v4
with:
name: artifact
path: dist
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install twine
run: python3 -m pip install --upgrade twine
- name: Publish library
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: python3 -m twine upload dist/*
# See documentation on accesing the tag from the release
# Look for 'github.ref' and 'github.ref_name' in https://docs.github.com/en/actions/learn-github-actions/contexts
# On October, 2023 it says "For workflows triggered by release, this is the release tag created"
# So 'github.ref_name' should be the version number of the release we're making.