Repository navigation
56 lines (48 loc) · 1.69 KB
/
Copy pathpython-publish.yml
File metadata and controls
56 lines (48 loc) · 1.69 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
name: python-publish
# Publishes to PyPI via OIDC trusted publishing — no long-lived tokens.
#
# Prerequisites (one-time):
# 1. PyPI account exists at https://pypi.org/.
# 2. On PyPI: Publishing → Add a new pending publisher:
# Project name: missioninbox
# Owner: MissionInbox
# Repository name: sdk
# Workflow name: python-publish.yml
# Environment name: pypi
# 3. In this repo: Settings → Environments → New environment → `pypi`
# (no protection rules required for a first release).
on:
push:
tags:
- 'python-v*'
jobs:
publish:
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # required for PyPI OIDC trusted publishing
contents: read
defaults:
run:
working-directory: packages/python
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Verify tag matches package version
run: |
TAG_VERSION="${GITHUB_REF_NAME#python-v}"
PKG_VERSION=$(python -c "import re, pathlib; text = pathlib.Path('pyproject.toml').read_text(); print(re.search(r'^version *= *\"([^\"]+)\"', text, re.M).group(1))")
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match pyproject.toml version $PKG_VERSION"
exit 1
fi
- name: Install build tools
run: python -m pip install --upgrade build
- name: Build sdist and wheel
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: packages/python/dist/