Repository navigation
106 lines (87 loc) · 2.34 KB
/
Copy pathpublish-python.yml
File metadata and controls
106 lines (87 loc) · 2.34 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Publish Python to PyPI
# Triggered when a release is published with a tag prefixed `python-v`
# (e.g. `python-v0.1.0`). The prefix is stripped by hatch-vcs so the
# package version remains a clean SemVer string.
on:
release:
types:
- published
permissions:
contents: read
defaults:
run:
working-directory: python
jobs:
check-tag:
name: Check tag is python-v*
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
steps:
- id: check
env:
TAG_NAME: ${{ github.event.release.tag_name }}
run: |
if [[ "$TAG_NAME" == python-v* ]]; then
echo "should_publish=true" >> "$GITHUB_OUTPUT"
else
echo "should_publish=false" >> "$GITHUB_OUTPUT"
fi
check:
name: Run checks
needs: check-tag
if: needs.check-tag.outputs.should_publish == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install hatch
run: pip install hatch
- name: Run checks
run: hatch run prepare
build:
name: Build distribution
needs: check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install hatch
run: pip install hatch twine
- name: Build package
run: hatch build
- name: Check distribution
run: twine check dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: python/dist/
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0