Skip to content

Commit 1aaf787

Browse files
committed
feat: Add GitHub Actions workflow for automated release process
1 parent 2e8013f commit 1aaf787

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

.github/workflows/release.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # Triggers on version tags like v0.1.0, v1.0.0, etc.
7+
8+
permissions:
9+
contents: write # Required for creating releases
10+
11+
jobs:
12+
test:
13+
name: Run Tests
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ['3.10', '3.11', '3.12']
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -e .
30+
pip install pytest
31+
32+
- name: Run tests
33+
run: pytest tests/ -v
34+
35+
build:
36+
name: Build Package
37+
runs-on: ubuntu-latest
38+
needs: test
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Set up Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: '3.11'
46+
47+
- name: Install build dependencies
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install build
51+
52+
- name: Build package
53+
run: python -m build
54+
55+
- name: Upload artifacts
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: dist
59+
path: dist/
60+
61+
release:
62+
name: Create GitHub Release
63+
runs-on: ubuntu-latest
64+
needs: build
65+
steps:
66+
- uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0 # Fetch all history for changelog generation
69+
70+
- name: Download artifacts
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: dist
74+
path: dist/
75+
76+
- name: Extract version from tag
77+
id: version
78+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
79+
80+
- name: Generate changelog
81+
id: changelog
82+
run: |
83+
# Get the previous tag
84+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
85+
86+
# Generate changelog
87+
if [ -z "$PREV_TAG" ]; then
88+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
89+
else
90+
CHANGELOG=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
91+
fi
92+
93+
# Save to file for multiline output
94+
echo "$CHANGELOG" > changelog.txt
95+
echo "Generated changelog for release"
96+
97+
- name: Create Release
98+
uses: softprops/action-gh-release@v1
99+
with:
100+
name: Release ${{ steps.version.outputs.version }}
101+
body_path: changelog.txt
102+
files: |
103+
dist/*.tar.gz
104+
dist/*.whl
105+
draft: false
106+
prerelease: false
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
110+
# Uncomment this job when ready to publish to PyPI
111+
# publish-pypi:
112+
# name: Publish to PyPI
113+
# runs-on: ubuntu-latest
114+
# needs: release
115+
# environment: release # Requires manual approval
116+
# steps:
117+
# - name: Download artifacts
118+
# uses: actions/download-artifact@v4
119+
# with:
120+
# name: dist
121+
# path: dist/
122+
#
123+
# - name: Publish to PyPI
124+
# uses: pypa/gh-action-pypi-publish@release/v1
125+
# with:
126+
# password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)