Skip to content

Commit cc44b78

Browse files
committed
chore: add automated release workflow with Trusted Publishing
1 parent faa2716 commit cc44b78

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test:
13+
name: Test before release
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
steps:
18+
- uses: actions/checkout@v7
19+
- uses: actions/setup-python@v7
20+
with:
21+
python-version: "3.12"
22+
- run: |
23+
python -m pip install --upgrade pip
24+
pip install -e .
25+
pip install pytest pytest-cov
26+
- run: pytest --cov=env_auditor --cov-fail-under=85
27+
28+
check-version:
29+
name: Tag must match pyproject.toml version
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
steps:
34+
- uses: actions/checkout@v7
35+
- run: |
36+
TAG_VERSION="${GITHUB_REF_NAME#v}"
37+
PYPROJECT_VERSION=$(grep -m1 '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
38+
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
39+
echo "Tag v$TAG_VERSION does not match pyproject.toml version $PYPROJECT_VERSION"
40+
exit 1
41+
fi
42+
43+
build:
44+
name: Build distribution
45+
needs: [test, check-version]
46+
runs-on: ubuntu-latest
47+
permissions:
48+
contents: read
49+
steps:
50+
- uses: actions/checkout@v7
51+
- uses: actions/setup-python@v7
52+
with:
53+
python-version: "3.12"
54+
- run: pip install build
55+
- run: python -m build
56+
- uses: actions/upload-artifact@v7
57+
with:
58+
name: dist
59+
path: dist/
60+
61+
publish:
62+
name: Publish to PyPI (Trusted Publishing, no stored token)
63+
needs: build
64+
runs-on: ubuntu-latest
65+
environment:
66+
name: pypi
67+
url: https://pypi.org/project/env-auditor/
68+
permissions:
69+
id-token: write
70+
steps:
71+
- uses: actions/download-artifact@v8
72+
with:
73+
name: dist
74+
path: dist/
75+
- uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)