Repository navigation
111 lines (105 loc) · 3.84 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (105 loc) · 3.84 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
107
108
109
110
111
name: Publish release
# Manual-only while the guarded local publisher remains authoritative.
# Enabling release:published before registry trust is validated would create
# two competing publishers for the same immutable version.
on:
workflow_dispatch:
inputs:
version:
description: Existing release version without the v prefix
required: true
type: string
concurrency:
group: python-release-${{ inputs.version }}
cancel-in-progress: false
permissions:
contents: read
env:
# Keep the manual fallback aligned with the guarded local publisher. Twine
# 6.2.0 rejects Core Metadata 2.5 emitted by Hatchling 1.32, so constrain the
# isolated PEP 517 backend until a released uploader accepts that metadata.
IICP_PYTHON_BUILD_VERSION: "1.5.0"
IICP_TWINE_VERSION: "6.2.0"
IICP_HATCHLING_VERSION: "1.31.0"
IICP_UV_VERSION: "0.11.6"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: v${{ inputs.version }}
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.12"
cache: pip
- name: Resolve and verify version
shell: bash
run: |
set -euo pipefail
expected="${{ inputs.version }}"
expected="${expected#v}"
actual=$(python - <<'PY'
import tomllib
print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])
PY
)
test "$actual" = "$expected"
- name: Test and build
run: |
set -euo pipefail
constraints="$RUNNER_TEMP/iicp-python-release-constraints.txt"
printf 'hatchling==%s\n' "$IICP_HATCHLING_VERSION" > "$constraints"
python -m pip install --upgrade pip
python -m pip install \
"build==$IICP_PYTHON_BUILD_VERSION" \
"twine==$IICP_TWINE_VERSION" \
"uv==$IICP_UV_VERSION"
uv run --locked --extra dev ruff check src tests scripts
uv run --locked --extra dev pytest -q
PIP_CONSTRAINT="$constraints" python -m build
twine check dist/*
- name: Clean-install smoke
run: |
python -m venv /tmp/iicp-release-smoke
/tmp/iicp-release-smoke/bin/pip install dist/*.whl
/tmp/iicp-release-smoke/bin/python -c 'import iicp_client; print(iicp_client.__version__)'
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-dist-${{ inputs.version }}
path: dist/*
if-no-files-found: error
retention-days: 1
publish:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: python-dist-${{ inputs.version }}
path: dist
- name: Select publishing authentication
id: auth
shell: bash
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
if [ -n "$PYPI_API_TOKEN" ]; then
echo "scoped_token=true" >> "$GITHUB_OUTPUT"
else
echo "scoped_token=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to PyPI with OIDC
if: steps.auth.outputs.scoped_token == 'false'
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
- name: Publish to PyPI with scoped-token fallback
if: steps.auth.outputs.scoped_token == 'true'
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}