Skip to content

Commit bbc05bf

Browse files
committed
feat: change release-python.yml to operate on push to main or master while also creating a tag and publishing files to the github release draft
1 parent b3e8970 commit bbc05bf

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

{{cookiecutter.project_name}}/.github/workflows/release-python.yml

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@ name: Release Python Package
55

66
on:
77
push:
8-
tags:
9-
- "v[0-9]+.[0-9]+.[0-9]+"
10-
- "v[0-9]+.[0-9]+.[0-9]+-*" # Include pre-release tags
8+
branches:
9+
- main
10+
- master
1111

1212
workflow_dispatch:
13-
inputs:
14-
tag:
15-
description: "Git tag to build and release (e.g., v1.2.3). Must already exist."
16-
required: true
1713

1814
jobs:
15+
get_tag:
16+
name: Get Tag
17+
runs-on: ubuntu-latest
18+
outputs:
19+
tag: {{ "${{ steps.current_version.outputs.CURRENT_VERSION }}" }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up uv
25+
uses: astral-sh/setup-uv@v6
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version-file: ".github/workflows/.python-version"
31+
32+
- name: Get Current Version
33+
id: current_version
34+
run: echo "CURRENT_VERSION=$(uvx --from commitizen cz version -p)" >> $GITHUB_OUTPUT
35+
36+
1937
build_and_testpypi:
2038
name: Build & Publish to TestPyPI
2139
runs-on: ubuntu-latest
22-
40+
needs: get_tag
41+
outputs:
42+
tag: {{ "${{ needs.get_tag.outputs.tag }}" }}
2343
steps:
2444
- name: Checkout code
2545
uses: actions/checkout@v4
@@ -44,7 +64,7 @@ jobs:
4464
- name: Download built package artifacts
4565
uses: actions/download-artifact@v4
4666
with:
47-
name: distribution-packages-{{"${{ github.event.inputs.tag }}"}}
67+
name: distribution-packages-{{ "${{ needs.get_tag.outputs.tag }}" }}
4868
path: dist/
4969

5070
- name: Publish to TestPyPI
@@ -58,7 +78,6 @@ jobs:
5878
runs-on: ubuntu-latest
5979
needs: build_and_testpypi
6080

61-
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')"
6281
steps:
6382
- name: Download package artifacts
6483
uses: actions/download-artifact@v4
@@ -74,6 +93,11 @@ jobs:
7493
- name: Set up uv
7594
uses: astral-sh/setup-uv@v6
7695

96+
- name: Create Tag
97+
run: |
98+
git tag {{ "${{ needs.build_and_testpypi.outputs.tag }}" }}
99+
git push origin {{ "${{ needs.build_and_testpypi.outputs.tag }}" }}
100+
77101
- name: Publish to PyPI
78102
env:
79103
TWINE_USERNAME: __token__
@@ -83,4 +107,4 @@ jobs:
83107
- name: Publish to GitHub
84108
env:
85109
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
86-
run: gh release upload {{ "${{ github.event.inputs.tag }}" }} dist/
110+
run: gh release upload {{ "${{ needs.build_and_testpypi.outputs.tag }}" }} dist/

0 commit comments

Comments
 (0)