11name : Release
22
33on :
4- push :
5- branches : [main]
6- workflow_dispatch :
4+ release :
5+ types : [published]
76
87permissions :
9- contents : write
8+ contents : read
109 id-token : write
1110
1211jobs :
13- test-and-build :
14- name : Test and Build
12+ release :
13+ name : Build and Publish
1514 runs-on : ubuntu-latest
1615
1716 steps :
1817 - name : Checkout code
1918 uses : actions/checkout@v4
20- with :
21- fetch-depth : 0
19+
20+ - name : Get version from tag
21+ id : version
22+ run : echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
2223
2324 - name : Set up Python
2425 uses : actions/setup-python@v5
@@ -32,68 +33,19 @@ jobs:
3233 pip install -e ".[dev]"
3334 pip install build
3435
35- - name : Run tests
36- run : python -m pytest tests/ -v
37-
38- - name : Build package
39- run : python -m build
40-
41- - name : Upload build artifacts
42- uses : actions/upload-artifact@v4
43- with :
44- name : release-artifacts
45- path : |
46- dist/
47- pyproject.toml
48- README.md
49- LICENSE
50- retention-days : 30
51-
52- release :
53- name : Release
54- runs-on : ubuntu-latest
55- needs : test-and-build
56- if : github.ref == 'refs/heads/main'
57-
58- steps :
59- - name : Checkout code
60- uses : actions/checkout@v4
61- with :
62- fetch-depth : 0
63- token : ${{ secrets.GITHUB_TOKEN }}
64-
65- - name : Set up Python
66- uses : actions/setup-python@v5
67- with :
68- python-version : ' 3.12'
69- cache : ' pip'
70-
71- - name : Install dependencies
36+ - name : Update version in pyproject.toml
7237 run : |
73- python -m pip install --upgrade pip
74- pip install python-semantic-release build
38+ sed -i "s/^version = .*/version = \"${{ steps.version.outputs.version }}\"/" pyproject.toml
7539
76- - name : Configure Git
40+ - name : Update version in __init__.py
7741 run : |
78- git config user.name "github-actions[bot]"
79- git config user.email "github-actions[bot]@users.noreply.github.com"
42+ sed -i "s/^__version__ = .*/__version__ = \"${{ steps.version.outputs.version }}\"/" src/lettermint/__init__.py
8043
81- - name : Python Semantic Release
82- id : release
83- env :
84- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
85- run : |
86- semantic-release version
87- semantic-release publish
44+ - name : Run tests
45+ run : python -m pytest tests/ -v
8846
89- - name : Download build artifacts
90- uses : actions/download-artifact@v4
91- with :
92- name : release-artifacts
93- path : artifacts/
47+ - name : Build package
48+ run : python -m build
9449
9550 - name : Publish to PyPI
96- if : steps.release.outputs.released == 'true'
9751 uses : pypa/gh-action-pypi-publish@release/v1
98- with :
99- packages-dir : artifacts/dist/
0 commit comments