Skip to content

Commit 5d69654

Browse files
committed
ci(release-python-package)🤖: Refactor GitHub Actions workflow for releasing Python package
- Simplify options syntax for version_name input. - Add permissions for contents read and id-token write. - Add extra newline for better readability in job defaults. - Combine Python setup and tool installation into one step. - Simplify bump2version dry run command to a single line. - Fix shell command for extracting new version number using sed with single quotes. - Simplify build package command to a single line. - Add trusted publishing flag to uv publish command.
1 parent 868cfe5 commit 5d69654

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

‎.github/workflows/release-python-package.yaml‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ on:
77
description: "One of major, minor, or patch"
88
required: true
99
type: choice
10-
options:
11-
- major
12-
- minor
13-
- patch
10+
options: [major, minor, patch]
1411
default: patch
1512
pull_request:
1613
branches:
1714
- '**'
1815

16+
permissions:
17+
contents: read
18+
id-token: write
19+
1920
env:
2021
UV_SYSTEM_PYTHON: 1
2122
DEFAULT_VERSION_NAME: patch
@@ -28,6 +29,7 @@ jobs:
2829
defaults:
2930
run:
3031
shell: bash -l {0}
32+
3133
steps:
3234
- name: Checkout repository
3335
uses: actions/checkout@v5
@@ -50,19 +52,17 @@ jobs:
5052
cache: true
5153
cache-write: ${{ github.event_name == 'push' }}
5254

53-
- name: Set up Python
54-
run: |
55-
uv tool install bump2version
55+
- name: Set up Python tools
56+
run: uv tool install bump2version
5657

5758
- name: Set version name
5859
run: echo "VERSION_NAME=${{ github.event.inputs.version_name || env.DEFAULT_VERSION_NAME }}" >> $GITHUB_ENV
5960

6061
- name: Dry run bump2version
61-
run: |
62-
bump2version --dry-run ${{ env.VERSION_NAME }} --allow-dirty --verbose
62+
run: bump2version --dry-run ${{ env.VERSION_NAME }} --allow-dirty --verbose
6363

6464
- name: Store new version number
65-
run: echo "version_number=`bump2version --dry-run --list ${{ env.VERSION_NAME }} | grep new_version | sed -r s,"^.*=",,`" >> $GITHUB_ENV
65+
run: echo "version_number=$(bump2version --dry-run --list ${{ env.VERSION_NAME }} | grep new_version | sed -r 's/^.*=//')" >> $GITHUB_ENV
6666

6767
- name: Display new version number
6868
run: |
@@ -104,12 +104,11 @@ jobs:
104104
git commit -m "Add release notes for ${{ env.version_number }}"
105105
106106
- name: Build package
107-
run: |
108-
uv build --sdist --wheel
107+
run: uv build --sdist --wheel
109108

110-
- name: Publish package
109+
- name: Publish package (trusted publishing)
111110
if: github.event_name != 'pull_request'
112-
run: uv publish
111+
run: uv publish --trusted-publishing always
113112

114113
- name: Push changes with tags
115114
if: github.event_name != 'pull_request'

0 commit comments

Comments
 (0)