-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (86 loc) · 2.91 KB
/
release.yml
File metadata and controls
108 lines (86 loc) · 2.91 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
name: Release
on:
push:
branches:
- releases
permissions:
contents: write
id-token: write
jobs:
release:
name: Build and publish
runs-on: ubuntu-latest
environment: pypi
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version
- name: Sync packages
run: uv sync --locked --all-packages
- name: Resolve release version
run: |
python - <<'PY'
import os
import re
import sys
import tomllib
from pathlib import Path
with open("pyproject.toml", "rb") as file:
version = tomllib.load(file)["project"]["version"]
if not re.fullmatch(r"\d+\.\d+\.\d+((a|b|rc)\d+)?", version):
print(f"Unsupported release version: {version!r}")
print("Expected X.Y.Z, X.Y.ZaN, X.Y.ZbN, or X.Y.ZrcN.")
sys.exit(1)
tag = f"v{version}"
github_env = Path(os.environ["GITHUB_ENV"])
with github_env.open("a") as env:
env.write(f"RELEASE_VERSION={version}\n")
env.write(f"TAG_NAME={tag}\n")
PY
- name: Verify release tag is new
run: |
if git rev-parse --verify --quiet "refs/tags/$TAG_NAME"; then
echo "Tag $TAG_NAME already exists."
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists on origin."
exit 1
fi
- name: Check import sorting
run: uv run ruff check --select I .
- name: Check formatting
run: uv run ruff format --check .
- name: Type check package
run: uv run basedpyright -p pyproject.toml
- name: Contract tests
run: uv run pytest tests/test_contracts.py -n auto
- name: Build distributions
run: uv build
- name: Check distributions
run: uv run twine check dist/*
- name: Create release tag
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME" "$GITHUB_SHA"
git push origin "$TAG_NAME"
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*
if-no-files-found: error
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$TAG_NAME" dist/* --generate-notes --title "$TAG_NAME"