-
Notifications
You must be signed in to change notification settings - Fork 150
77 lines (70 loc) · 2.4 KB
/
Copy pathpublish.yml
File metadata and controls
77 lines (70 loc) · 2.4 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
name: Publish
on:
release:
types: [published]
env:
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}
jobs:
test:
name: Test - Python ${{ matrix.python-version }}
runs-on: ${{ github.repository_owner == 'twilio' && 'ubuntu-x64' || 'ubuntu-latest' }}
if: github.repository_owner == 'twilio'
permissions:
contents: read
id-token: write
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Authenticate with Artifactory
uses: ./.github/actions/artifactory-oidc
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install uv
- run: uv sync --frozen --all-extras
- run: uv run pytest
deploy:
name: Publish to PyPI
needs: [test]
runs-on: ${{ github.repository_owner == 'twilio' && 'ubuntu-x64' || 'ubuntu-latest' }}
if: github.repository_owner == 'twilio'
environment: production
permissions:
contents: read
id-token: write
attestations: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Authenticate with Artifactory
uses: ./.github/actions/artifactory-oidc
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.12"
- run: pip install uv
- name: Validate tag format and version match
run: |
TAG="${GITHUB_REF#refs/tags/}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "::error::Release tag must be in the form v1.2.3 (got '$TAG')"
exit 1
fi
VERSION="${TAG#v}"
PKG_VERSION=$(python -c "
import tomllib
with open('pyproject.toml', 'rb') as f:
print(tomllib.load(f)['project']['version'])
")
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag $TAG does not match pyproject.toml version $PKG_VERSION"
exit 1
fi
- name: Build package
run: uv build
- name: Publish to PyPI
run: |
pip install "twine>=5.0"
twine upload --repository pypi --trusted-publishing=always dist/*