Skip to content

Commit 914929c

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 914929c

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

.github/workflows/release_python_package.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,41 @@ 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+
permissions:
42+
contents: write # Needed to create git tag
43+
44+
# Separate job is workaround for https://github.com/pypi/warehouse/issues/11096
45+
release-trusted-publishing:
46+
name: Release to PyPI (trusted publishing)
47+
needs:
48+
- release-part1
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 5
51+
environment: production
52+
steps:
53+
- name: Download all the dists
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: ${{ needs.release-part1.outputs.artifact-name }}
57+
path: dist/
58+
- name: Publish to PyPI
59+
uses: pypa/gh-action-pypi-publish@release/v1
4160
permissions:
42-
contents: write # Needed to create GitHub release
4361
id-token: write # Needed for PyPI trusted publishing
62+
63+
release-part2:
64+
name: Release to PyPI (part 2)
65+
needs:
66+
- release-part1
67+
- release-trusted-publishing
68+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
69+
with:
70+
git-tag: ${{ needs.release-part1.outputs.git-tag }}
71+
permissions:
72+
contents: write # Needed to create GitHub release
4473
```
4574
4675
### 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
git-tag:
5+
description: |
6+
Semantic version git tag
7+
8+
Use output from canonical/data-platform-workflows release_python_package_part1.yaml
9+
required: true
10+
type: string
11+
12+
jobs:
13+
release:
14+
name: Create GitHub release
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 5
17+
steps:
18+
- name: Create GitHub release
19+
run: gh release create '${{ inputs.git-tag }}' --verify-tag --generate-notes
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)