-
-
Notifications
You must be signed in to change notification settings - Fork 21
82 lines (67 loc) · 2.3 KB
/
release.yml
File metadata and controls
82 lines (67 loc) · 2.3 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
name: Publish to PyPI and Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
if: github.repository == 'jmrplens/PyOctaveBand'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Validate tag version
id: version
run: |
PACKAGE_VERSION=$(python - <<'PY'
import ast
from pathlib import Path
version_file = Path("src/pyoctaveband/_version.py")
module = ast.parse(version_file.read_text(encoding="utf-8"))
for node in module.body:
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id == "__version__":
print(ast.literal_eval(node.value))
raise SystemExit(0)
raise SystemExit("Unable to find __version__ in src/pyoctaveband/_version.py")
PY
)
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match package version ${PACKAGE_VERSION}"
exit 1
fi
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
- name: Build package
run: python -m build
- name: Check package
run: python -m twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: python -m twine upload dist/*
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: |
Automated release for version ${{ steps.version.outputs.version }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}