@@ -2,14 +2,71 @@ name: Release
22
33permissions :
44 contents : write
5+ pull-requests : write
56
67on :
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
1119jobs :
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 }}
0 commit comments