Skip to content

Commit 1123fa8

Browse files
authored
Merge pull request #159 from ImperialCollegeLondon/158-add-trusted-publishing
Add publishing workflow and make CI workflow reusable - bypassing requirements
2 parents 006ae49 + eae9e13 commit 1123fa8

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Test and build
22

3-
on: [push, pull_request, release]
3+
# When does this run - new, reopened or updated PRs and when the workflow is called by
4+
# another workflow, such as the publishing actions.
5+
on:
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
workflow_call:
9+
410

511
jobs:
612

.github/workflows/sdv_publish.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Publishing
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
# First, run the standard test suite - for this to work correctly, the workflow needs
9+
# to inherit the organisation secrets used to authenticate to CodeCov.
10+
# https://github.com/actions/runner/issues/1413
11+
test:
12+
uses: ./.github/workflows/sdv_ci.yaml
13+
secrets: inherit
14+
15+
# Next, build the package wheel and source releases and add them to the release assets
16+
build-wheel:
17+
needs: test
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
# Build the package - this could use `poetry build` directly but pyproject.toml
23+
# already has the build-system configured to use poetry so `pip` should pick that
24+
# up automatically.
25+
- name: Build sdist
26+
run: |
27+
python -m pip install --upgrade build
28+
python -m build
29+
30+
# Upload the build outputs as job artifacts - these will be two files with x.y.z
31+
# version numbers:
32+
# - pyrealm-x.y.z-py3-none-any.whl
33+
# - pyrealm-x.y.z.tar.gz
34+
- uses: actions/upload-artifact@v4
35+
with:
36+
path: dist/safedata_validator*
37+
38+
# Add the built files to the release assets, alongside the repo archives
39+
# automatically added by GitHub. These files should then match exactly to the
40+
# published files on PyPI.
41+
- uses: softprops/action-gh-release@v1
42+
with:
43+
files: dist/safedata_validator*
44+
45+
# Now attempt to publish the package to the TestPyPI site, where the pyrealm project
46+
# has been configured to allow trusted publishing from this repo and workflow.
47+
#
48+
# The skip-existing option allows the publication step to pass even when the release
49+
# files already exists on PyPI. That suggests something has gone wrong with the
50+
# release or the build file staging and the release should not be allowed to continue
51+
# to publish on PyPI.
52+
53+
publish-TestPyPI:
54+
needs: build-wheel
55+
name: Publish safedata_validator to TestPyPI
56+
runs-on: ubuntu-latest
57+
permissions:
58+
id-token: write
59+
60+
steps:
61+
# Download the built package files from the job artifacts
62+
- name: Download sdist artifact
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: artifact
66+
path: dist
67+
68+
# Information step to show the contents of the job artifacts
69+
- name: Display structure of downloaded files
70+
run: ls -R dist
71+
72+
# Use trusted publishing to release the files downloaded into dist to TestPyPI
73+
- name: Publish package distributions to TestPyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1
75+
with:
76+
repository-url: https://test.pypi.org/legacy/
77+
# skip-existing: true
78+
79+
# The final job in the workflow is to publish to the real PyPI as long as the release
80+
# name does not contain the tag 'test-pypi-only'
81+
publish-PyPI:
82+
if: ${{ ! contains(github.event.release.name, 'test-pypi-only')}}
83+
needs: publish-TestPyPI
84+
name: Publish safedata_validator to PyPI
85+
runs-on: ubuntu-latest
86+
permissions:
87+
id-token: write
88+
89+
steps:
90+
# Download the built package files from the job artifacts
91+
- name: Download sdist artifact
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: artifact
95+
path: dist
96+
97+
# Information step to show the contents of the job artifacts
98+
- name: Display structure of downloaded files
99+
run: ls -R dist
100+
101+
# Use trusted publishing to release the files downloaded into dist to PyPI
102+
- name: Publish package distributions to PyPI
103+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)