generated from jenskeiner/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (89 loc) · 3.33 KB
/
publish.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 Python distributions to PyPI
on:
release:
types: [published]
env:
PACKAGE_NAME: exchange_calendars_extensions_api
MODULE_NAME: exchange_calendars_extensions.api
jobs:
build-and-publish:
name: Build and publish Python distributions to TestPyPI and PyPI.
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install poetry.
run: pipx install poetry
- name: Set up Python.
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'poetry'
- name: Determine version number.
run: |
export VERSION=${{ github.ref_name }}
echo "Version is $VERSION."
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set poetry package version.
run: poetry version ${{ env.VERSION }}
- name: Determine path to version.py from module name.
run: |
export VERSION_PATH=$(echo ${{ env.MODULE_NAME }} | sed 's/\./\//g')/version.py
echo "VERSION_PATH is $VERSION_PATH."
echo "VERSION_PATH=$VERSION_PATH" >> $GITHUB_ENV
- name: Generate version.py
run: |
echo "version = '${{ env.VERSION }}'" > ${{ env.VERSION_PATH }}
- name: Generate requirements.txt.
run: poetry export -f requirements.txt --without-hashes > requirements.txt
- name: Build package with poetry.
run: poetry build
- name: Publish package to Test PyPI.
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Install from testpypi and import.
run: |
i=0
n=60
exists=0
while [ $i -lt $n ] && [ $exists -eq 0 ]; do
i=$(expr $i + 1)
if curl -f -s https://test.pypi.org/pypi/${{ env.PACKAGE_NAME }}/json | jq -e ".releases | has(\"${{ env.VERSION }}\")" &> /dev/null; then
echo "$i/$n Package exists in index."
exists=1
else
echo "$i/$n Package has not appeared in index yet. Sleeping 5s."
sleep 5s
fi
done
sleep 5s
pip install --no-cache-dir --index-url https://test.pypi.org/simple ${{ env.PACKAGE_NAME }}==${{ env.VERSION }} --no-deps
pip install -r requirements.txt
python -c 'import ${{ env.MODULE_NAME }};print(${{ env.MODULE_NAME }}.__version__)'
- name: Clean pip
run: |
pip uninstall -y ${{ env.PACKAGE_NAME }}
pip cache purge
- name: Publish package to PyPI.
uses: pypa/gh-action-pypi-publish@release/v1
- name: Install and import.
run: |
i=0
n=60
exists=0
while [ $i -lt $n ] && [ $exists -eq 0 ]; do
i=$(expr $i + 1)
if curl -f -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json | jq -e ".releases | has(\"${{ env.VERSION }}\")" &> /dev/null; then
echo "$i/$n Package exists in index."
exists=1
else
echo "$i/$n Package has not appeared in index yet. Sleeping 5s."
sleep 5s
fi
done
sleep 5s
pip install --no-cache-dir --index-url https://pypi.org/simple ${{ env.PACKAGE_NAME }}==${{ env.VERSION }}
python -c 'import ${{ env.MODULE_NAME }};print(${{ env.MODULE_NAME }}.__version__)'