Skip to content

Commit 30ea1e9

Browse files
committed
Add semantic-release support
1 parent 38181e6 commit 30ea1e9

File tree

7 files changed

+78
-5
lines changed

7 files changed

+78
-5
lines changed

.github/workflows/format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: stefanzweifel/git-auto-commit-action@v5
3636
if: always()
3737
with:
38-
commit_message: Run format
38+
commit_message: 'ci: Format code'
3939
commit_user_name: ${{ secrets.GIT_USER_NAME }}
4040
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
4141
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>

.github/workflows/generate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Commit
3737
uses: stefanzweifel/git-auto-commit-action@v5
3838
with:
39-
commit_message: Generate code
39+
commit_message: 'ci: Generate code'
4040
commit_user_name: ${{ secrets.GIT_USER_NAME }}
4141
commit_user_email: ${{ secrets.GIT_USER_EMAIL }}
4242
commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}>

.github/workflows/publish.yml

+11
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,29 @@ jobs:
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
2527
- name: Download artifact
2628
uses: actions/download-artifact@v4
2729
with:
2830
name: ${{ needs.build.outputs.artifact_name }}
2931
path: dist/
32+
- name: Generate release notes
33+
id: changelog
34+
run: |
35+
mkdir tmp
36+
outfile=tmp/changelog.txt
37+
echo "outfile=${outfile}" >> $GITHUB_OUTPUT
38+
npx standard-changelog@^2.0.0 --release-count 2 --infile $outfile.tmp --outfile $outfile.tmp
39+
sed '1,3d' $outfile.tmp > $outfile
3040
- name: Create GitHub release
3141
uses: softprops/action-gh-release@v2
3242
with:
3343
token: ${{ secrets.GH_TOKEN }}
3444
fail_on_unmatched_files: true
3545
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
3646
files: dist/*
47+
body_path: ${{ github.workspace }}/${{ steps.changelog.outputs.outfile }}
3748
pypi:
3849
name: PyPI
3950
uses: ./.github/workflows/_publish.yml
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Semantic Release
3+
4+
run-name: Semantic Release from ${{ github.ref_name }}
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
semantic:
17+
name: Determine version
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 30
20+
outputs:
21+
new_release_published: ${{ steps.release.outputs.new_release_published }}
22+
new_release_version: ${{ steps.release.outputs.new_release_version }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
- name: Semantic release
29+
id: release
30+
uses: cycjimmy/semantic-release-action@v4
31+
with:
32+
dry_run: true
33+
release:
34+
name: Release version
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 30
37+
needs: semantic
38+
if: needs.semantic.outputs.new_release_published == 'true' && needs.semantic.outputs.new_release_version != '1.0.0'
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 1
44+
- name: Release version ${{ needs.semantic.outputs.new_release_version }} on ${{ github.ref_name }}
45+
run: gh workflow run version.yml --raw-field version=$VERSION --ref $BRANCH
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
48+
VERSION: ${{ needs.semantic.outputs.new_release_version }}
49+
BRANCH: ${{ github.ref_name }}

.releaserc.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"branches": [
3+
"+([0-9])?(.{+([0-9]),x}).x",
4+
"main",
5+
"next",
6+
"next-major",
7+
{ "name": "beta", "prerelease": true },
8+
{ "name": "alpha", "prerelease": true }
9+
],
10+
"plugins": ["@semantic-release/commit-analyzer"]
11+
}

README.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Features
2828
- Uncompromising code formatting with Black_.
2929
- pytest_ helps you write better programs.
3030
- Code coverage reporting with Codecov_.
31-
- Continuous testing and deployment with `GitHub Actions`__.
31+
- Fully automated version management and package publishing with semantic-release_.
32+
- Continuous checks and tests with `GitHub Actions`__.
3233
- `Keep a CHANGELOG`_.
3334
- Consistent coding with EditorConfig_.
3435
- Badges from Shields.io_.
@@ -37,13 +38,14 @@ Features
3738
.. _Black: https://black.readthedocs.io/en/stable/
3839
.. _Codecov: https://codecov.io/
3940
.. _EditorConfig: https://editorconfig.org/
40-
.. __: https://github.com/features/actions
4141
.. _GitHub Codespaces: https://github.com/features/codespaces
4242
.. _Keep a CHANGELOG: https://keepachangelog.com/
4343
.. _PyPI: https://pypi.python.org/pypi
4444
.. _Pylint: https://www.pylint.org/
4545
.. _Shields.io: https://shields.io/
46+
.. __: https://github.com/features/actions
4647
.. _pytest: https://docs.pytest.org/
48+
.. _semantic-release: https://semantic-release.gitbook.io/semantic-release/
4749

4850
Bootstrapping a New Project
4951
~~~~~~~~~~~~~~~~~~~~~~~~~~~

makenew.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ makenew () {
5959
read -p '> GitHub user or organization name (my-user): ' mk_user
6060
read -p '> GitHub repository name (my-repo): ' mk_repo
6161

62-
sed_delete README.rst '18,128d'
62+
sed_delete README.rst '18,130d'
6363
sed_insert README.rst '18i' 'TODO'
6464

6565
old_title="Python Package Skeleton"

0 commit comments

Comments
 (0)