Skip to content

Commit a75e376

Browse files
authored
Improve release action (#68)
1 parent fd35e12 commit a75e376

7 files changed

Lines changed: 130 additions & 22 deletions

File tree

.github/workflows/release.yml

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,71 @@ name: Release
22

33
permissions:
44
contents: write
5+
pull-requests: write
56

67
on:
7-
push:
8-
tags:
9-
- v*
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: Release version (e.g., 1.2.3)
12+
required: true
13+
type: string
14+
pull_request:
15+
types: [closed]
16+
branches:
17+
- main
1018

1119
jobs:
12-
release:
20+
create-release-pr:
21+
if: github.event_name == 'workflow_dispatch'
22+
runs-on: ubuntu-latest
23+
environment: release
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
- name: Setup python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version-file: .python-version
34+
- name: Install uv
35+
uses: astral-sh/setup-uv@v6
36+
with:
37+
version-file: pyproject.toml
38+
- name: Install dependencies
39+
run: uv sync --all-groups --all-extras
40+
- name: Configure Git
41+
run: |
42+
git config user.name "github-actions[bot]"
43+
git config user.email "github-actions[bot]@users.noreply.github.com"
44+
- name: Create release branch
45+
run: |
46+
git checkout -b release/${{ inputs.version }}
47+
- name: Build Changelog
48+
run: uv run towncrier build --yes --version ${{ inputs.version }}
49+
- name: Commit Changelog
50+
run: |
51+
git add CHANGELOG.md
52+
git add news/ || true
53+
git commit -m "Release ${{ inputs.version }}"
54+
- name: Push release branch
55+
run: git push origin release/${{ inputs.version }}
56+
- name: Create Pull Request
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
run: |
60+
gh pr create \
61+
--base main \
62+
--head release/${{ inputs.version }} \
63+
--title "Release ${{ inputs.version }}" \
64+
--body "This PR contains the changelog for version ${{ inputs.version }}.
65+
66+
Once merged, a tag \`v${{ inputs.version }}\` will be automatically created and a GitHub release will be published."
67+
create-tag-and-release:
68+
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') && github.event.pull_request.user.login
69+
== 'github-actions[bot]'
1370
runs-on: ubuntu-latest
1471
environment: release
1572
permissions:
@@ -26,19 +83,25 @@ jobs:
2683
uses: astral-sh/setup-uv@v6
2784
with:
2885
version-file: pyproject.toml
29-
- name: Install project
30-
run: uv sync --all-groups
86+
- name: Extract version from branch name
87+
id: extract_version
88+
run: |
89+
VERSION="${{ github.head_ref }}"
90+
VERSION="${VERSION#release/}"
91+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
92+
- name: Create and Push Tag
93+
run: |
94+
git config user.name "github-actions[bot]"
95+
git config user.email "github-actions[bot]@users.noreply.github.com"
96+
git tag -a "v${{ steps.extract_version.outputs.version }}" -m "Version ${{ steps.extract_version.outputs.version }}"
97+
git push origin "v${{ steps.extract_version.outputs.version }}"
3198
- name: Create wheel
32-
run: uv build -o dist/
99+
run: uv build -o dist/ .
33100
- name: Publish package distributions to PyPI
34101
uses: pypa/gh-action-pypi-publish@release/v1
35-
- name: Determine version
36-
run: |
37-
tag="${GITHUB_REF#refs/*/}"
38-
version="${tag:1}"
39-
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
40102
- name: Release on GitHub
41103
uses: softprops/action-gh-release@v2
42104
with:
43105
files: dist/*
44-
name: Version ${{ env.RELEASE_VERSION }}
106+
tag_name: v${{ inputs.version }}
107+
name: Version ${{ inputs.version }}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
<!-- towncrier release notes start -->
4+
35
## 3.1.0
46
- Support pylint 4.x
57

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ To setup a venv for development use
7575
Then use `source .venv/bin/activate` to activate your venv.
7676

7777
## Build and Publish
78-
79-
This project uses `setuptools` as the dependency management and build tool.
80-
To publish a new release, follow these steps:
81-
* Update the version in the `pyproject.toml`
82-
* Add an entry in the changelog
83-
* Push a new tag like `vX.X.X` to trigger the release
78+
Execute the release action with the proper version.
8479

8580
## Support, Feedback, Contributing
8681

news/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.gitignore

news/news/+9002ce43.change.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated the release actions

pyproject.toml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
build-backend = "setuptools.build_meta"
3-
requires = ["setuptools>=61"]
3+
requires = ["setuptools>=61", "setuptools-scm~=9.2"]
44

55
[project]
66
authors = [
@@ -27,6 +27,7 @@ dependencies = [
2727
"pylint>=3.3,<5",
2828
]
2929
description = "A pylint plugin to ignore error codes per file."
30+
dynamic = ["version"]
3031
keywords = ["pylint", "plugin", "quality", "linter"]
3132
license = "MIT"
3233
license-files = ["LICENSE"]
@@ -36,7 +37,6 @@ maintainers = [
3637
name = "pylint-per-file-ignores"
3738
readme = "README.md"
3839
requires-python = ">=3.10,<4"
39-
version = "3.1.0"
4040

4141
[dependency-groups]
4242
dev = [
@@ -51,6 +51,7 @@ dev = [
5151
"pyupgrade==3.21.2",
5252
"toml-sort==0.24.3",
5353
"uv==0.9.11",
54+
"towncrier==25.8.0",
5455
]
5556
test = [
5657
"pytest==9.0.1",
@@ -170,11 +171,41 @@ swagger_plugin_for_sphinx = ["py.typed"]
170171
[tool.setuptools.packages.find]
171172
include = ["pylint_per_file_ignores"]
172173

174+
[tool.setuptools_scm]
175+
version_file = ""
176+
173177
[tool.tomlsort]
174178
sort_first = ["build-system", "project", "dependency-groups"]
175179
sort_table_keys = true
176180
spaces_indent_inline_array = 4
177181
trailing_comma_inline_array = true
178182

183+
[tool.towncrier]
184+
directory = "news"
185+
filename = "CHANGELOG.md"
186+
start_string = "<!-- towncrier release notes start -->\n"
187+
title_format = "## {version} ({project_date})"
188+
underlines = ["", "", ""]
189+
190+
[[tool.towncrier.type]]
191+
directory = "removal"
192+
name = "Removals"
193+
194+
[[tool.towncrier.type]]
195+
directory = "deprecation"
196+
name = "Deprecations"
197+
198+
[[tool.towncrier.type]]
199+
directory = "feature"
200+
name = "Features"
201+
202+
[[tool.towncrier.type]]
203+
directory = "change"
204+
name = "Changes"
205+
206+
[[tool.towncrier.type]]
207+
directory = "fix"
208+
name = "Fixes"
209+
179210
[tool.uv]
180211
default-groups = []

uv.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)