This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (166 loc) · 5.72 KB
/
build_pypi.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: "Build PYPI"
on:
workflow_call:
inputs:
version:
description: 'Version'
type: string
required: true
ref:
description: 'Ref'
type: string
required: true
upload_to_pypi:
description: "Upload to PyPi"
type: boolean
required: false
release-id:
description: "Attach Artifact to Release"
type: string
required: false
outputs:
pipy-artifact-url:
description: "PyPI Artifact URL"
value: ${{ jobs.pypi.outputs.pipy-artifact-url }}
pipy-artifact-digests-sha256:
description: "PyPI Artifact SHA256"
value: ${{ jobs.pypi.outputs.pipy-artifact-digests-sha256 }}
workflow_dispatch:
inputs:
version:
description: 'Version'
type: string
required: true
ref:
description: 'Ref'
type: string
required: true
upload_to_pypi:
description: "Upload to PyPi"
type: boolean
default: false
required: false
release-id:
description: "Attach Artifact to Release"
type: string
required: false
jobs:
pypi:
name: "PyPI"
runs-on: ubuntu-latest
outputs:
pipy-artifact-url: ${{ steps.pypi-package-details.outputs.pipy-artifact-url }}
pipy-artifact-digests-sha256: ${{ steps.pypi-package-details.outputs.pipy-artifact-digests-sha256 }}
steps:
- uses: hmarr/[email protected]
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Manage version
env:
PROVIDED_VERSION: ${{ inputs.version }}
run: |
set -x
version=$(sed "s/^v//g" <<< ${PROVIDED_VERSION})
sed -i "s/^__version__[ ]*=.*/__version__ = '${version}'/g" label_studio/__init__.py
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Configure pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pypi-${{ hashFiles('deploy/requirements-mw.txt') }}-${{ hashFiles('deploy/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pypi-
- name: Install dependencies
run: |
pip install -r deploy/requirements-mw.txt
pip install -r deploy/requirements.txt
pip install -e .
pip install twine
- name: Collect static
run: |
python label_studio/manage.py collectstatic
- name: Download feature flags
env:
LAUNCHDARKLY_COMMUNITY_SDK_KEY: ${{ secrets.LAUNCHDARKLY_COMMUNITY_SDK_KEY }}
LAUNCHDARKLY_DOWNLOAD_PATH: "label_studio/feature_flags.json"
run: |
set -xeuo pipefail
curl \
--connect-timeout 30 \
--retry 5 \
--retry-delay 10 \
-H "Authorization: $LAUNCHDARKLY_COMMUNITY_SDK_KEY" \
"https://sdk.launchdarkly.com/sdk/latest-all" >"$LAUNCHDARKLY_DOWNLOAD_PATH"
if [ "$(jq 'has("flags")' <<< cat $LAUNCHDARKLY_DOWNLOAD_PATH)" = "true" ]; then
echo "feature_flags.json is valid"
else
echo "feature_flags.json is invalid"
cat $LAUNCHDARKLY_DOWNLOAD_PATH
exit 1
fi
- name: Package
run: python setup.py sdist bdist_wheel
- name: Upload to PYPI
if: inputs.upload_to_pypi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
run: twine upload dist/*
- name: Get PyPI package details
id: pypi-package-details
if: inputs.upload_to_pypi
uses: actions/github-script@v6
env:
VERSION: ${{ inputs.version }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const version = process.env.VERSION
const MAX_ATTEMPTS = 10
let currentAttempt = 0
const intervalId = setInterval(async () => {
currentAttempt++
console.log(`Attempt ${currentAttempt}`)
const {data: pypiPackage} = await github.request('https://pypi.org/pypi/label-studio/json')
if ('releases' in pypiPackage && version in pypiPackage.releases) {
const release = pypiPackage.releases[version]
const artifact = release.find(e => e.packagetype === 'bdist_wheel')
console.log(artifact);
core.setOutput("pipy-artifact-url", artifact.url);
core.setOutput("pipy-artifact-digests-sha256", artifact.digests.sha256);
clearInterval(intervalId)
} else if (currentAttempt >= MAX_ATTEMPTS) {
clearInterval(intervalId)
throw Error('Max attempts exceeded')
}
}, 60 * 1000 )
- name: Attach artifacts to release
if: inputs.release-id
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const fs = require('fs');
const release_id = '${{ inputs.release-id }}';
for (let file of await fs.readdirSync('./dist/')) {
console.log('uploadReleaseAsset', file);
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: release_id,
name: file,
data: await fs.readFileSync(`./dist/${file}`)
});
}
- name: Upload to artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: Dist
path: dist/