Skip to content

Commit c19ef02

Browse files
committed
feat: auto version
1 parent 0a1142c commit c19ef02

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed
Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,103 @@
1-
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
1+
name: Release & Publish 🚀
22

33
on:
44
push:
55
branches:
66
- main
77

8+
permissions:
9+
contents: write
10+
id-token: write
11+
812
jobs:
13+
release:
14+
name: Semantic Release 📦
15+
runs-on: ubuntu-latest
16+
concurrency: release
17+
outputs:
18+
released: ${{ steps.release.outputs.released }}
19+
version: ${{ steps.release.outputs.version }}
20+
tag: ${{ steps.release.outputs.tag }}
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.12"
31+
32+
- name: Python Semantic Release
33+
id: release
34+
uses: python-semantic-release/python-semantic-release@v9.21.0
35+
with:
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
938
build:
1039
name: Build distribution 📦
40+
needs: release
41+
if: needs.release.outputs.released == 'true'
1142
runs-on: ubuntu-latest
1243

1344
steps:
14-
- uses: actions/checkout@v6
45+
- uses: actions/checkout@v4
46+
with:
47+
ref: ${{ needs.release.outputs.tag }}
48+
fetch-depth: 0
1549

16-
- uses: actions/setup-python@v6
50+
- uses: actions/setup-python@v5
1751
with:
18-
python-version: "3.10"
52+
python-version: "3.12"
1953

20-
- name: Install pypa/build
21-
run: pip install build
54+
- name: Install build dependencies
55+
run: pip install build setuptools-scm
2256

2357
- name: Build a binary wheel and a source tarball
2458
run: python -m build
2559

26-
- uses: actions/upload-artifact@v5
60+
- uses: actions/upload-artifact@v4
2761
with:
2862
name: python-package-distributions
2963
path: dist/
3064

3165
publish-to-pypi:
32-
name: Publish Python 🐍 distribution 📦 to PyPI
33-
if: startsWith(github.ref, 'refs/tags/')
34-
needs: build
66+
name: Publish to PyPI 🐍
67+
needs: [release, build]
68+
if: needs.release.outputs.released == 'true'
3569
runs-on: ubuntu-latest
3670
environment:
3771
name: pypi
3872
url: https://pypi.org/p/cssinj
3973
permissions:
4074
id-token: write
75+
4176
steps:
42-
- uses: actions/download-artifact@v6
77+
- uses: actions/download-artifact@v4
4378
with:
4479
name: python-package-distributions
4580
path: dist/
81+
4682
- uses: pypa/gh-action-pypi-publish@release/v1
4783

48-
publish-to-testpypi:
49-
name: Publish Python 🐍 distribution 📦 to TestPyPI
50-
if: github.ref == 'refs/heads/main'
51-
needs: build
84+
github-release:
85+
name: GitHub Release 🏷️
86+
needs: [release, build]
87+
if: needs.release.outputs.released == 'true'
5288
runs-on: ubuntu-latest
53-
environment:
54-
name: testpypi
55-
url: https://test.pypi.org/p/cssinj
5689
permissions:
57-
id-token: write
90+
contents: write
91+
5892
steps:
59-
- uses: actions/download-artifact@v6
93+
- uses: actions/download-artifact@v4
6094
with:
6195
name: python-package-distributions
6296
path: dist/
63-
- uses: pypa/gh-action-pypi-publish@release/v1
97+
98+
- name: Upload to GitHub Release
99+
uses: softprops/action-gh-release@v2
64100
with:
65-
repository-url: https://test.pypi.org/legacy/
101+
tag_name: ${{ needs.release.outputs.tag }}
102+
files: dist/*
103+
generate_release_notes: true

cssinj/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

pyproject.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools"]
2+
requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -24,3 +24,20 @@ dependencies = [
2424
[project.urls]
2525
Homepage = "https://github.com/DonAsako/CSSinj"
2626
Issues = "https://github.com/DonAsako/CSSinj/issues"
27+
28+
[tool.semantic_release]
29+
version_toml = ["pyproject.toml:project.version"]
30+
version_variables = ["cssinj/__init__.py:__version__"]
31+
tag_format = "v{version}"
32+
branch = "main"
33+
upload_to_pypi = false
34+
build_command = "pip install build && python -m build"
35+
commit_message = "chore(release): {version} [skip ci]"
36+
37+
[tool.semantic_release.changelog]
38+
changelog_file = "CHANGELOG.md"
39+
40+
[tool.semantic_release.commit_parser_options]
41+
allowed_tags = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
42+
minor_tags = ["feat"]
43+
patch_tags = ["fix", "perf"]

0 commit comments

Comments
 (0)