Skip to content

Commit 5711a36

Browse files
committed
[build] Add job to publish package to PyPI
1 parent fd652a0 commit 5711a36

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Publish PyPI Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag To Publish'
8+
required: true
9+
environment:
10+
description: 'PyPI Environment'
11+
required: true
12+
type: choice
13+
options:
14+
- test
15+
- release
16+
default: 'test'
17+
18+
jobs:
19+
verify:
20+
name: Verify Build
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check workflows
24+
uses: actions/github-script@v6
25+
with:
26+
script: |
27+
const { owner, repo } = context.repo;
28+
const tag = "${{ github.event.inputs.tag }}";
29+
const requiredWorkflows = ['Windows Distribution', 'Python Distribution'];
30+
let workflowConclusions = {};
31+
32+
console.log(`Checking for successful workflow runs for tag: ${tag}`);
33+
34+
const { data: response } = await github.rest.actions.listWorkflowRunsForRepo({
35+
owner,
36+
repo,
37+
event: 'push',
38+
});
39+
40+
const runsForTag = response.workflow_runs.filter(run => run.head_branch === tag);
41+
42+
for (const run of runsForTag) {
43+
if (requiredWorkflows.includes(run.name)) {
44+
if (!workflowConclusions[run.name] || new Date(run.created_at) > new Date(workflowConclusions[run.name].created_at)) {
45+
workflowConclusions[run.name] = {
46+
conclusion: run.conclusion,
47+
created_at: run.created_at,
48+
html_url: run.html_url,
49+
};
50+
}
51+
}
52+
}
53+
54+
let allSuccess = true;
55+
for (const workflowName of requiredWorkflows) {
56+
if (!workflowConclusions[workflowName]) {
57+
core.setFailed(`Workflow "${workflowName}" was not found for tag ${tag}.`);
58+
allSuccess = false;
59+
} else if (workflowConclusions[workflowName].conclusion !== 'success') {
60+
core.setFailed(`Workflow "${workflowName}" did not succeed for tag ${tag}. Conclusion was "${workflowConclusions[workflowName].conclusion}". See: ${workflowConclusions[workflowName].html_url}`);
61+
allSuccess = false;
62+
} else {
63+
console.log(`✅ Workflow "${workflowName}" succeeded for tag ${tag}.`);
64+
}
65+
}
66+
67+
if (!allSuccess) {
68+
throw new Error("One or more required build workflows did not succeed.");
69+
}
70+
71+
publish:
72+
env:
73+
UV_SYSTEM_PYTHON: 1
74+
75+
name: Publishing DVR-Scan to ${{ github.event.inputs.environment }} PyPI
76+
runs-on: ubuntu-latest
77+
needs: verify
78+
79+
environment:
80+
name: ${{ github.event.inputs.environment == 'test' && 'test' || 'release' }}
81+
82+
permissions:
83+
id-token: write # IMPORTANT: mandatory for trusted publishing
84+
85+
steps:
86+
- name: Checkout ${{ github.event.inputs.tag }}
87+
uses: actions/checkout@v3
88+
with:
89+
ref: ${{ github.event.inputs.tag }}
90+
91+
- name: Set up Python
92+
uses: actions/setup-python@v3
93+
with:
94+
python-version: 3.13
95+
96+
- name: Install uv and set the python version
97+
uses: astral-sh/setup-uv@v4
98+
with:
99+
version: "0.5.11"
100+
python-version: 3.13
101+
102+
- name: Install Dependencies
103+
run: |
104+
uv pip install --upgrade build wheel virtualenv
105+
uv pip install opencv-python-headless opencv-contrib-python-headless --only-binary :all:
106+
uv pip install -r requirements_headless.txt -r docs/requirements.txt
107+
108+
- name: Build Package
109+
run: |
110+
python dist/pre_release.py
111+
python -m build
112+
python dist/tweak_setup_cfg_for_headless.py
113+
python -m build
114+
mkdir pkg
115+
mv dist/*.tar.gz pkg/
116+
mv dist/*.whl pkg/
117+
118+
- name: Upload Package
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: dvr-scan-dist
122+
path: |
123+
pkg/*.tar.gz
124+
pkg/*.whl
125+
126+
- name: Publish Package
127+
uses: pypa/gh-action-pypi-publish@release/v1
128+
with:
129+
repository-url: ${{ github.event.inputs.environment == 'test' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
130+
packages-dir: pkg/
131+
print-hash: true
132+

0 commit comments

Comments
 (0)