Repository navigation
76 lines (67 loc) · 2.3 KB
/
Copy pathrelease.yml
File metadata and controls
76 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
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Read version from drowse/__init__.py
# Source of truth for the version is ``__version__`` in
# drowse/__init__.py; pyproject.toml resolves it dynamically via
# setuptools.dynamic.attr. Parse the literal directly here rather
# than ``pip install -e .`` just to read it.
id: ver
run: |
python - <<'EOF' >> "$GITHUB_OUTPUT"
import pathlib, re
text = pathlib.Path("drowse/__init__.py").read_text()
match = re.search(r'^__version__ = "([^"]+)"', text, re.M)
if match is None:
raise SystemExit("drowse/__init__.py has no __version__")
print(f"version={match.group(1)}")
EOF
- name: Check if tag already exists
id: check
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
if git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-python@v7
if: steps.check.outputs.exists == 'false'
with:
python-version: "3.12"
- name: Build
if: steps.check.outputs.exists == 'false'
run: |
pip install build
python -m build
- name: Create tag
if: steps.check.outputs.exists == 'false'
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v$VERSION"
git push origin "v$VERSION"
- name: Publish to PyPI
if: steps.check.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub release
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.ver.outputs.version }}
run: gh release create "v$VERSION" --generate-notes dist/*