Skip to content

Commit 9862359

Browse files
committed
Refactor publishing workflow
1 parent 2dde25a commit 9862359

3 files changed

Lines changed: 121 additions & 102 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: "Publish Python Package"
2+
# Uses:
3+
# https://github.com/actions/setup-python : a26af69be951a213d495a4c3e4e4022e16d87065
4+
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5+
# https://github.com/actions/download-artifact : d3f86a106a0bac45b974a628896c90dbdf5c8093
6+
# https://github.com/actions/upload-artifact : ea165f8d65b6e75b540449e92b4886f43607fa02
7+
# https://github.com/actions/pypa/gh-action-pypi-publish : 76f52bc884231f62b9a034ebfe128415bbaabdfc
8+
9+
on:
10+
workflow_call:
11+
inputs:
12+
runs-on:
13+
description: "The base runner to use."
14+
default: "ubuntu-latest"
15+
required: false
16+
type: "string"
17+
python-version:
18+
description: "Python version to use for all actions."
19+
default: "3.12"
20+
required: false
21+
type: "string"
22+
build-command:
23+
description: "Command line to trigger package build."
24+
default: "python -m pip install build; python -m build"
25+
required: false
26+
type: "string"
27+
build-directory:
28+
description: "Directory where build artifacts are located."
29+
default: "./dist"
30+
required: false
31+
type: "string"
32+
index-environment:
33+
description: "Environment of the packaging index."
34+
default: ""
35+
required: true
36+
type: "string"
37+
index-package-url:
38+
description: "URL of the package on the packaging index."
39+
default: ""
40+
required: true
41+
type: "string"
42+
index-publish-url:
43+
description: "URL of the packaging index publishing url."
44+
default: ""
45+
required: true
46+
type: "string"
47+
48+
jobs:
49+
build:
50+
name: "Build package"
51+
runs-on: "${{ inputs.runs-on }}"
52+
outputs:
53+
artifact-id: "${{ steps.upload-artifact.outputs.artifact-id }}"
54+
55+
steps:
56+
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
57+
with:
58+
persist-credentials: false
59+
60+
- name: "Set up Python"
61+
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
62+
with:
63+
python-version: "${{ inputs.python-version }}"
64+
65+
- name: "Build the package"
66+
run: "${{ inputs.build-command }}"
67+
68+
- name: "Store the distribution packages"
69+
id: "upload-artifact"
70+
uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02"
71+
with:
72+
path: "${{ inputs.build-directory }}"
73+
74+
publish-to-pypi:
75+
name: "Publish Python Distribution to PyPI"
76+
needs: ["build"]
77+
runs-on: "${{ inputs.runs-on }}"
78+
environment:
79+
name: "${{ inputs.index-environment }}"
80+
url: "${{ inputs.index-package-url }}"
81+
permissions:
82+
id-token: "write"
83+
84+
steps:
85+
- name: "Download all the dists"
86+
uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093"
87+
with:
88+
artifact-ids: "${{ needs.build.outputs.artifact-id }}"
89+
path: "${{ inputs.build-directory }}"
90+
merge-multiple: true
91+
92+
- name: "Show me"
93+
run: |
94+
echo "Environment: ${{ inputs.index-environment }}"
95+
echo "Package URL: ${{ inputs.index-package-url }}"
96+
echo "Publish URL: ${{ inputs.index-publish-url }}"
97+
98+
- name: "Publish distribution to PyPI"
99+
uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc"
100+
with:
101+
repository-url: "${{ inputs.index-publish-url }}"
102+
verbose: true

.github/workflows/pypi-publish.yml

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,16 @@
11
name: "Publish Python distribution to PyPI"
2-
# Uses:
3-
# https://github.com/actions/setup-python : 0b93645e9fea7318ecaed2b359559ac225c90a2b
4-
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5-
# https://github.com/actions/download-artifact : fa0a91b85d4f404e444e00e005971372dc801d16
6-
# https://github.com/actions/upload-artifact : 6f51ac03b9356f520e9adb1b1b7802705f340c2b
7-
# https://github.com/actions/pypa/gh-action-pypi-publish : 76f52bc884231f62b9a034ebfe128415bbaabdfc
82

93
on:
104
release:
115
types: [published]
126

137
jobs:
14-
build:
15-
name: "Build distribution"
16-
runs-on: "ubuntu-latest"
17-
18-
steps:
19-
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
20-
with:
21-
persist-credentials: false
22-
23-
- name: "Set up Python"
24-
uses: "actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b"
25-
with:
26-
python-version: "3.12"
27-
28-
- name: "Build the package"
29-
run: "python -m pip install nox; nox --session build"
30-
31-
- name: "Store the distribution packages"
32-
uses: "actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b"
33-
with:
34-
name: "python-package-distributions"
35-
path: "dist/"
36-
37-
publish-to-pypi:
38-
name: "Publish Python Distribution to PyPI"
39-
if: startsWith(github.ref, 'refs/tags/')
40-
needs: ["build"]
41-
runs-on: "ubuntu-latest"
42-
environment:
43-
name: "pypi"
44-
url: "https://pypi.org/p/commented-configparser"
45-
permissions:
46-
id-token: "write"
47-
48-
steps:
49-
- name: "Download all the dists"
50-
uses: "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16"
51-
with:
52-
name: "python-package-distributions"
53-
path: "dist/"
54-
55-
- name: "Publish distribution to PyPI"
56-
uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc"
8+
publish-test:
9+
name: "Publish package to PyPI"
10+
uses: "./.github/workflows/gha-publish-python-package.yml"
11+
with:
12+
python-version: "3.12"
13+
build-command: "python -m pip install nox; nox --session build"
14+
index-environment: "pypi"
15+
index-package-url: "https://test.pypi.org/p/commented-configparser"
16+
index-publish-url: "https://upload.pypi.org/legacy/"
Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,18 @@
11
name: "Publish Python distribution to PyPI Test"
2-
# Uses:
3-
# https://github.com/actions/setup-python : a26af69be951a213d495a4c3e4e4022e16d87065
4-
# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683
5-
# https://github.com/actions/download-artifact : d3f86a106a0bac45b974a628896c90dbdf5c8093
6-
# https://github.com/actions/upload-artifact : ea165f8d65b6e75b540449e92b4886f43607fa02
7-
# https://github.com/actions/pypa/gh-action-pypi-publish : 76f52bc884231f62b9a034ebfe128415bbaabdfc
82

93
on:
4+
pull_request:
105
push:
116
tags:
127
- "[0-9]+.[0-9]+.[a-z]+[0-9]+"
138

149
jobs:
15-
build:
16-
name: "Build test distribution"
17-
runs-on: "ubuntu-latest"
18-
outputs:
19-
artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }}
20-
21-
steps:
22-
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683"
23-
with:
24-
persist-credentials: false
25-
26-
- name: "Set up Python"
27-
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065"
28-
with:
29-
python-version: "3.12"
30-
31-
- name: "Build the package"
32-
run: "python -m pip install nox; nox --session build"
33-
34-
- name: "Store the distribution packages"
35-
id: "upload-artifact"
36-
uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02"
37-
with:
38-
path: "dist/"
39-
40-
publish-to-pypi:
41-
name: "Publish Python Distribution to PyPI Test"
42-
needs: ["build"]
43-
runs-on: "ubuntu-latest"
44-
environment:
45-
name: "testpypi"
46-
url: "https://pypi.org/p/commented-configparser"
47-
permissions:
48-
id-token: "write"
49-
50-
steps:
51-
- name: "Download all the dists"
52-
uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093"
53-
with:
54-
artifact-ids: ${{ needs.build.outputs.artifact-id }}
55-
path: "dist/"
56-
merge-multiple: true
57-
58-
- name: "Publish distribution to PyPI"
59-
uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc"
60-
with:
61-
repository-url: https://test.pypi.org/legacy/
10+
publish-test:
11+
name: "Publish package to PyPI Test"
12+
uses: "./.github/workflows/gha-publish-python-package.yml"
13+
with:
14+
python-version: "3.12"
15+
build-command: "python -m pip install nox; nox --session build"
16+
index-environment: "testpypi"
17+
index-package-url: "https://test.pypi.org/project/commented-configparser/"
18+
index-publish-url: "https://test.pypi.org/legacy/"

0 commit comments

Comments
 (0)