Repository navigation
67 lines (57 loc) · 1.95 KB
/
Copy pathrelease.yml
File metadata and controls
67 lines (57 loc) · 1.95 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
name: Release to PyPI
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
release:
name: Test, publish, and create GitHub release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
- name: Install
run: python -m pip install --upgrade pip && python -m pip install -e ".[dev]"
- name: Validate release version
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
VERSION="${GITHUB_REF_NAME#v}"
PROJECT_VERSION="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
if [[ "${VERSION}" != "${PROJECT_VERSION}" ]]; then
echo "Tag v${VERSION} does not match pyproject version ${PROJECT_VERSION}"
exit 1
fi
- name: Test
run: python -m pytest -q
- name: Build distributions
run: python -m build
- name: Publish distributions
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${GITHUB_REF_NAME#v}"
NOTES="$(awk -v ver="$VERSION" '
index($0, "## [" ver "]") == 1 { found = 1; next }
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md)"
gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1 || \
gh release create "${GITHUB_REF_NAME}" --verify-tag \
--title "${GITHUB_REF_NAME}" --notes "${NOTES}"
gh release upload "${GITHUB_REF_NAME}" dist/* --clobber