Skip to content

Commit b218e3a

Browse files
Split workflow into parts
Unable to use reusable workflow with trusted publishing pypi/warehouse#11096 Using trusted publishing in a composite action is also not supported https://github.com/marketplace/actions/pypi-publish#non-goals
1 parent b8cdba7 commit b218e3a

File tree

3 files changed

+66
-36
lines changed

3 files changed

+66
-36
lines changed

.github/workflows/release_python_package.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,39 @@ on:
3535
- main
3636

3737
jobs:
38-
release:
39-
name: Release to PyPI
40-
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
38+
release-part1:
39+
name: Release to PyPI (part 1)
40+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
41+
42+
# Separate job is workaround for https://github.com/pypi/warehouse/issues/11096
43+
release-trusted-publishing:
44+
name: Release to PyPI (trusted publishing)
45+
needs:
46+
- release-part1
47+
runs-on: ubuntu-latest
48+
timeout-minutes: 5
49+
environment: production
50+
steps:
51+
- name: Download all the dists
52+
uses: actions/download-artifact@v4
53+
with:
54+
name: ${{ needs.release-part1.outputs.artifact-name }}
55+
path: dist/
56+
- name: Publish to PyPI
57+
uses: pypa/gh-action-pypi-publish@release/v1
4158
permissions:
42-
contents: write # Needed to create GitHub release
4359
id-token: write # Needed for PyPI trusted publishing
60+
61+
release-part2:
62+
name: Release to PyPI (part 2)
63+
needs:
64+
- release-part1
65+
- release-trusted-publishing
66+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
67+
with:
68+
git-tag: ${{ needs.release-part1.outputs.git-tag }}
69+
permissions:
70+
contents: write # Needed to create GitHub release
4471
```
4572
4673
### Step 3: Add `check_pr.yaml` file to `.github/workflows/`
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
on:
22
workflow_call:
3-
4-
concurrency:
5-
# Prevent race conditions
6-
# (If multiple commits have been pushed since the last release, this workflow may get triggered
7-
# on multiple commits. Without this, if the)
8-
group: dpw-release-python-package-${{ github.ref }}
9-
cancel-in-progress: true
3+
outputs:
4+
git-tag:
5+
description: Semantic version git tag
6+
value: ${{ jobs.tag.outputs.tag }}
7+
artifact-name:
8+
description: Python package distributions are uploaded to this GitHub artifact name
9+
value: python-package-distributions
1010

1111
jobs:
1212
tag:
1313
name: Tag release
1414
runs-on: ubuntu-latest
15+
concurrency:
16+
# Prevent race conditions
17+
# (If multiple commits have been pushed since the last release, this workflow may get triggered
18+
# on multiple commits. Without this, if the) TODO
19+
group: dpw-release-python-package-${{ github.ref }}
20+
cancel-in-progress: true
1521
timeout-minutes: 5
1622
steps:
1723
- name: Get workflow version
1824
id: workflow-version
1925
uses: canonical/get-workflow-version-action@v1
2026
with:
2127
repository-name: canonical/data-platform-workflows
22-
file-name: release_python_package.yaml
28+
file-name: release_python_package_part1.yaml
2329
github-token: ${{ secrets.GITHUB_TOKEN }}
2430
- name: Install CLI
2531
run: pipx install git+https://github.com/canonical/data-platform-workflows@'${{ steps.workflow-version.outputs.sha }}'#subdirectory=python/cli
@@ -59,28 +65,5 @@ jobs:
5965
- name: Store the distribution packages
6066
uses: actions/upload-artifact@v4
6167
with:
62-
name: python-package-distributions
63-
path: dist/
64-
65-
release:
66-
name: Release to PyPI
67-
needs:
68-
- tag
69-
- build
70-
runs-on: ubuntu-latest
71-
timeout-minutes: 5
72-
environment: production
73-
steps:
74-
- name: Download all the dists
75-
uses: actions/download-artifact@v4
76-
with:
77-
name: python-package-distributions
68+
name: python-package-distributions # Keep in sync with `artifact-name` output
7869
path: dist/
79-
- name: Publish to PyPI
80-
# Use trusted publishing
81-
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
82-
uses: pypa/gh-action-pypi-publish@release/v1
83-
- name: Create GitHub release
84-
run: gh release create '${{ needs.tag.outputs.tag }}' --verify-tag --generate-notes
85-
env:
86-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
workflow_call:
3+
git-tag:
4+
description: |
5+
Semantic version git tag
6+
7+
Use output from canonical/data-platform-workflows release_python_package_part1.yaml
8+
required: true
9+
type: string
10+
11+
jobs:
12+
release:
13+
name: Create GitHub release
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
steps:
17+
- name: Create GitHub release
18+
run: gh release create '${{ inputs.git-tag }}' --verify-tag --generate-notes
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)