Skip to content

Commit 166c0c6

Browse files
signekblwjohnst86
andauthored
ci: 💚 apply suggestions from code review
Co-authored-by: Luke W. Johnston <lwjohnst86@users.noreply.github.com>
1 parent d01212a commit 166c0c6

File tree

1 file changed

+11
-76
lines changed

1 file changed

+11
-76
lines changed

.github/workflows/reusable-release-package.yml

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ on:
77
app-id:
88
type: "string"
99
required: true
10+
publish:
11+
description: "Whether to publish to PyPI or not."
12+
type: "boolean"
13+
required: false
14+
default: false
1015
secrets:
1116
# Needs read and write contents permission to push to main.
1217
update-version-gh-token:
1318
required: true
1419

1520
jobs:
16-
update-version-and-changelog:
21+
release:
1722
if: "!startsWith(github.event.head_commit.message, 'build(version): ')"
1823
runs-on: ubuntu-latest
19-
name: "Update project's version and changelog"
24+
name: "Update project's version and changelog, then release to PyPI"
2025
steps:
2126
- name: Harden the runner (Audit all outbound calls)
2227
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
@@ -55,92 +60,22 @@ jobs:
5560
# env variable containing the new version, created by the Commitizen action
5661
tag_name : ${{ env.REVISION }}
5762

58-
build:
5963
# This workflow and the publish workflows are based on:
6064
# - https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
6165
# - https://www.andrlik.org/dispatches/til-use-uv-for-build-and-publish-github-actions/
6266
# - https://github.com/astral-sh/trusted-publishing-examples
63-
name: Build Python 🐍 distribution 📦
64-
runs-on: ubuntu-latest
65-
needs:
66-
- update-version-and-changelog
67-
steps:
68-
- name: Checkout
69-
uses: actions/checkout@v4
70-
7167
- name: Set up uv
7268
uses: astral-sh/setup-uv@445689ea25e0de0a23313031f5fe577c74ae45a1 # v6.3.0
7369
with:
7470
enable-cache: true
7571
cache-dependency-glob: "uv.lock"
76-
7772
- name: Build
7873
# Builds dists from source and stores them in the dist/ directory.
7974
run: uv build
8075

81-
- name: Upload Python package distributions
82-
# Uploads the built distributions so that they can be used in the next steps.
83-
# This is necessary because the next steps needs to run on different environments
84-
# (e.g. publish to TestPyPI and PyPI), and the dist/ directory is not persisted
85-
# between jobs.
86-
uses: actions/upload-artifact@v4
87-
with:
88-
name: python-package-distributions
89-
path: dist/
90-
91-
publish-to-testpypi:
92-
name: Publish Python 🐍 distribution 📦 to TestPyPI
93-
runs-on: ubuntu-latest
94-
environment: testpypi
95-
needs:
96-
- build
97-
permissions:
98-
id-token: write # IMPORTANT: mandatory for trusted publishing.
99-
steps:
100-
- name: Checkout
101-
uses: actions/checkout@v4
102-
103-
- name: Download dists
104-
uses: actions/download-artifact@v4
105-
with:
106-
name: python-package-distributions
107-
path: dist/
108-
109-
- name: Set up uv
110-
uses: astral-sh/setup-uv@445689ea25e0de0a23313031f5fe577c74ae45a1
111-
with:
112-
enable-cache: true
113-
cache-dependency-glob: "uv.lock"
114-
115-
- name: Publish distribution 📦 to TestPyPI
116-
# This requires an []
117-
run: uv publish --index testpypi --trusted-publishing always
118-
119-
# publish-to-pypi:
120-
# name: Publish Python 🐍 distribution 📦 to PyPI
121-
# # Only publish to PyPI on tag pushes.
122-
# if: startsWith(github.ref, 'refs/tags/')
123-
# needs:
124-
# - build
125-
# runs-on: ubuntu-latest
126-
# environment: pypi
127-
# permissions:
128-
# id-token: write # IMPORTANT: mandatory for trusted publishing
129-
# steps:
130-
# - name: Checkout
131-
# uses: actions/checkout@v4
132-
133-
# - name: Download dists
134-
# uses: actions/download-artifact@v4
135-
# with:
136-
# name: python-package-distributions
137-
# path: dist/
13876

139-
# - name: Set up uv
140-
# uses: astral-sh/setup-uv@445689ea25e0de0a23313031f5fe577c74ae45a1
141-
# with:
142-
# enable-cache: true
143-
# cache-dependency-glob: "uv.lock"
14477

145-
# - name: Publish distribution 📦 to PyPI
146-
# run: uv publish --trusted-publishing always
78+
- name: Publish distribution 📦 to PyPI
79+
# Only publish if the option is explicitly set in the calling workflow.
80+
if: ${{ inputs.publish }}
81+
run: uv publish --trusted-publishing always

0 commit comments

Comments
 (0)