-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (50 loc) · 1.53 KB
/
publish.yaml
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
name: Publish PyPi package
on:
workflow_run:
workflows: ["Release Workflow"]
types:
- completed
workflow_dispatch:
jobs:
build-and-publish:
name: Build and publish PyPi package
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --depth=1 --tags
- name: Get latest tag or set default
id: latest_tag
run: |
TAG=$(git tag -l --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$TAG" ]; then
TAG="latest"
fi
echo "::set-output name=tag::$TAG"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine toml build
- name: Update pyproject.toml
run: |
python -c "\
import toml; \
pyproject = toml.load('pyproject.toml'); \
pyproject['project']['version'] = '${{ steps.latest_tag.outputs.tag }}'; \
toml.dump(pyproject, open('pyproject.toml', 'w'))"
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*