Skip to content

Commit 8ed404d

Browse files
ci: PLT-690: Add PyPi build
1 parent e4ecd5c commit 8ed404d

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

.github/workflows/build-pypi.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: "Build PYPI"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: 'Version'
8+
type: string
9+
required: true
10+
ref:
11+
description: 'Ref'
12+
type: string
13+
required: true
14+
upload_to_pypi:
15+
description: "Upload to PyPi"
16+
type: boolean
17+
required: false
18+
default: false
19+
release-id:
20+
description: "Attach Artifact to Release"
21+
type: string
22+
required: false
23+
workflow_dispatch:
24+
inputs:
25+
version:
26+
description: 'Version'
27+
type: string
28+
required: true
29+
ref:
30+
description: 'Ref'
31+
type: string
32+
required: true
33+
upload_to_pypi:
34+
description: "Upload to PyPi"
35+
type: boolean
36+
required: false
37+
default: false
38+
release-id:
39+
description: "Attach Artifact to Release"
40+
type: string
41+
required: false
42+
43+
jobs:
44+
pypi:
45+
name: "PyPI"
46+
runs-on: ubuntu-latest
47+
outputs:
48+
pipy-artifact-url: ${{ steps.pypi-package-details.outputs.pipy-artifact-url }}
49+
pipy-artifact-digests-sha256: ${{ steps.pypi-package-details.outputs.pipy-artifact-digests-sha256 }}
50+
steps:
51+
- uses: hmarr/[email protected]
52+
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ inputs.ref }}
57+
58+
- name: "Set up Python"
59+
id: setup_python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: '3.12'
63+
cache: 'pip'
64+
65+
- name: Install Build dependencies
66+
run: pip install --upgrade setuptools wheel twine
67+
68+
- name: Install dependencies
69+
run: pip install -r requirements.txt
70+
71+
- name: Build
72+
env:
73+
VERSION_OVERRIDE: ${{ inputs.version }}
74+
run: python setup.py sdist bdist_wheel
75+
76+
- name: Attach artifacts to release
77+
if: inputs.release-id
78+
uses: actions/github-script@v7
79+
with:
80+
github-token: ${{ secrets.GIT_PAT }}
81+
script: |
82+
const { repo, owner } = context.repo;
83+
const fs = require('fs');
84+
const release_id = '${{ inputs.release-id }}';
85+
for (let file of await fs.readdirSync('./dist/')) {
86+
console.log('uploadReleaseAsset', file);
87+
await github.rest.repos.uploadReleaseAsset({
88+
owner,
89+
repo,
90+
release_id: release_id,
91+
name: file,
92+
data: await fs.readFileSync(`./dist/${file}`)
93+
});
94+
}
95+
96+
- name: Upload to PYPI
97+
if: inputs.upload_to_pypi
98+
env:
99+
TWINE_USERNAME: __token__
100+
TWINE_PASSWORD: ${{ inputs.upload_to_pypi && secrets.PYPI_APIKEY || secrets.PYPI_APIKEY_TEST }}
101+
TWINE_REPOSITORY_URL: ${{ inputs.upload_to_pypi && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }}
102+
run: twine upload dist/*
103+
104+
- name: Upload to artifact
105+
if: always() && inputs.release_type == 'release'
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: Dist
109+
path: dist/

label_studio_ml/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Package name
2+
import os
3+
24
package_name = 'label-studio-ml'
35

46
# Package version
5-
__version__ = '2.0.1dev0'
7+
__version__ = os.environ.get("VERSION_OVERRIDE", '2.0.1dev0')

0 commit comments

Comments
 (0)