Skip to content

Commit 28debba

Browse files
committed
use reusable workflows
1 parent 3cfc38a commit 28debba

File tree

2 files changed

+89
-73
lines changed

2 files changed

+89
-73
lines changed
Lines changed: 83 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,92 @@
1-
# This workflow will upload a Python Package to PyPI when a release is created
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
9-
name: Upload Python Package
10-
11-
on:
12-
release:
13-
types: [published]
14-
15-
permissions:
16-
contents: read
17-
1+
name: Publish Python distribution to PyPI
2+
on: push
183
jobs:
19-
release-build:
4+
lint-and-test:
5+
if: github.ref_type == 'tag'
6+
name: Run linter and tests
7+
uses: ./.github/workflows/Lint-and-test.yml
8+
build:
9+
needs: lint-and-test
10+
if: github.ref_type == 'tag'
11+
name: build distribution
2012
runs-on: ubuntu-latest
2113

2214
steps:
23-
- uses: actions/checkout@v4
24-
with:
25-
fetch-depth: 0
26-
27-
- uses: actions/setup-python@v5
28-
with:
29-
python-version: "3.x"
30-
31-
- name: Build release distributions
32-
run: |
33-
# NOTE: put your own distribution build steps here.
34-
python -m pip install build
35-
python -m build
36-
37-
- name: Upload distributions
38-
uses: actions/upload-artifact@v4
39-
with:
40-
name: release-dists
41-
path: dist/
42-
43-
pypi-publish:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
- name: Install pypa/build
21+
run: >-
22+
python3 -m
23+
pip install
24+
build
25+
--user
26+
- name: Build a binary wheel and a source tarball
27+
run: python3 -m build
28+
- name: Store the distribution packages
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: python-package-distributions
32+
path: dist/
33+
publish-to-pypi:
34+
name: >-
35+
Publish Python distribution to PyPI
36+
if: github.ref_type == 'tag'
37+
needs: [lint-and-test, build]
4438
runs-on: ubuntu-latest
45-
needs:
46-
- release-build
39+
environment:
40+
name: release
41+
url: https://pypi.org/p/lewis
4742
permissions:
48-
# IMPORTANT: this permission is mandatory for trusted publishing
49-
id-token: write
43+
id-token: write # IMPORTANT: mandatory for trusted publishing
44+
steps:
45+
- name: Download all the dists
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
- name: Publish distribution to PyPI
51+
uses: pypa/gh-action-pypi-publish@release/v1
52+
github-release:
53+
name: >-
54+
Sign the Python distribution with Sigstore
55+
and upload them to GitHub Release
56+
needs: [lint-and-test, build, publish-to-pypi]
57+
runs-on: ubuntu-latest
5058

51-
# Dedicated environments with protections for publishing are strongly recommended.
52-
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
53-
environment:
54-
name: pypi
55-
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
56-
# url: https://pypi.org/p/YOURPROJECT
57-
#
58-
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
59-
# ALTERNATIVE: exactly, uncomment the following line instead:
60-
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59+
permissions:
60+
contents: write # IMPORTANT: mandatory for making GitHub Releases
61+
id-token: write # IMPORTANT: mandatory for sigstore
6162

6263
steps:
63-
- name: Retrieve release distributions
64-
uses: actions/download-artifact@v4
65-
with:
66-
name: release-dists
67-
path: dist/
68-
69-
- name: Publish release distributions to PyPI
70-
uses: pypa/gh-action-pypi-publish@release/v1
71-
with:
72-
packages-dir: dist/
64+
- name: Download all the dists
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: python-package-distributions
68+
path: dist/
69+
- name: Sign the dists with Sigstore
70+
uses: sigstore/[email protected]
71+
with:
72+
inputs: >-
73+
./dist/*.tar.gz
74+
./dist/*.whl
75+
- name: Create GitHub Release
76+
env:
77+
GITHUB_TOKEN: ${{ github.token }}
78+
run: >-
79+
gh release create
80+
'${{ github.ref_name }}'
81+
--repo '${{ github.repository }}'
82+
--notes ""
83+
- name: Upload artifact signatures to GitHub Release
84+
env:
85+
GITHUB_TOKEN: ${{ github.token }}
86+
# Upload to GitHub Release using the `gh` CLI.
87+
# `dist/` contains the built packages, and the
88+
# sigstore-produced signatures and certificates.
89+
run: >-
90+
gh release upload
91+
'${{ github.ref_name }}' dist/**
92+
--repo '${{ github.repository }}'

.github/workflows/python.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ permissions:
1313
contents: read
1414

1515
jobs:
16-
build:
17-
16+
call-workflow:
17+
uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main
18+
with:
19+
compare-branch: origin/main
20+
python-ver: '3.12'
21+
tests:
1822
runs-on: ubuntu-latest
19-
2023
steps:
2124
- uses: actions/checkout@v4
2225
- name: Install uv and set the python version
@@ -25,12 +28,5 @@ jobs:
2528
python-version: "3.12"
2629
- name: Install dependencies
2730
run: uv sync --all-extras --dev
28-
- name: ruff format check
29-
run: uv run ruff format --check
30-
- name: ruff check
31-
run: uv run ruff check
32-
- name: pyright
33-
run: uv run pyright
3431
- name: Test with pytest
3532
run: uv run pytest tests
36-

0 commit comments

Comments
 (0)