-
Notifications
You must be signed in to change notification settings - Fork 0
388 lines (322 loc) · 13 KB
/
Copy pathrelease.yml
File metadata and controls
388 lines (322 loc) · 13 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
name: Release
on:
push:
tags:
- "v[0-9]*.[0-9]*.[0-9]*"
permissions:
contents: read
jobs:
build:
name: Validate, test, and build
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag_name: ${{ steps.version.outputs.tag_name }}
version: ${{ steps.version.outputs.version }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
has_python_package: ${{ steps.detect.outputs.has_python_package }}
steps:
- name: Check out tag
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Validate release tag
id: version
shell: bash
run: |
set -euo pipefail
tag="$GITHUB_REF_NAME"
scripts/validate-version-tag.sh "$tag"
- name: Detect project type
id: detect
shell: bash
run: |
set -euo pipefail
has_python_package="false"
has_python_tests="false"
has_npm="false"
has_elixir="false"
has_shell_scripts="false"
if find . -maxdepth 2 -name pyproject.toml -print -quit | grep -q .; then
has_python_package="true"
fi
if [[ -f pytest.ini || -f requirements.txt ]] || find . -path './.git' -prune -o -name 'test_*.py' -print -quit | grep -q .; then
has_python_tests="true"
fi
if [[ -f package.json ]]; then
has_npm="true"
fi
if [[ -f mix.exs ]]; then
has_elixir="true"
fi
if find . -path './.git' -prune -o -name '*.sh' -print -quit | grep -q .; then
has_shell_scripts="true"
fi
{
echo "has_python_package=$has_python_package"
echo "has_python_tests=$has_python_tests"
echo "has_npm=$has_npm"
echo "has_elixir=$has_elixir"
echo "has_shell_scripts=$has_shell_scripts"
} >> "$GITHUB_OUTPUT"
- name: Set up Python
if: steps.detect.outputs.has_python_package == 'true' || steps.detect.outputs.has_python_tests == 'true'
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
- name: Set up Node.js
if: steps.detect.outputs.has_npm == 'true'
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- name: Set up Elixir
if: steps.detect.outputs.has_elixir == 'true'
uses: erlef/setup-beam@v1
with:
elixir-version: "1.16"
otp-version: "26"
- name: Install Python dependencies
if: steps.detect.outputs.has_python_package == 'true' || steps.detect.outputs.has_python_tests == 'true'
shell: bash
env:
MN_GITHUB_TOKEN: ${{ secrets.MN_GITHUB_TOKEN || secrets.GH_TOKEN || github.token }}
run: |
set -euo pipefail
python -m pip install --upgrade pip
python -m pip install build twine pytest packaging
token="${MN_GITHUB_TOKEN:-${GH_TOKEN:-${GITHUB_TOKEN:-}}}"
if [[ -n "$token" ]]; then
git config --global url."https://x-access-token:${token}@github.com/".insteadOf "https://github.com/"
fi
if [[ "$GITHUB_REPOSITORY" == "MirrorNeuronLab/mn-api" || "$GITHUB_REPOSITORY" == "MirrorNeuronLab/mn-cli" ]]; then
python -m pip install "mirrorneuron-python-sdk @ git+https://github.com/MirrorNeuronLab/mn-python-sdk.git"
fi
if [[ "$GITHUB_REPOSITORY" == "MirrorNeuronLab/mn-blueprints" ]]; then
python -m pip install "mirrorneuron-python-sdk @ git+https://github.com/MirrorNeuronLab/mn-python-sdk.git"
python -m pip install "mirrorneuron-blueprint-support-skill @ git+https://github.com/MirrorNeuronLab/mn-skills.git#subdirectory=blueprint_support_skill"
fi
if [[ "$GITHUB_REPOSITORY" == "MirrorNeuronLab/mn-system-tests" ]]; then
python -m pip install pytest pytest-cov requests
python -m pip install "mirrorneuron-python-sdk @ git+https://github.com/MirrorNeuronLab/mn-python-sdk.git"
python -m pip install "mirrorneuron-cli @ git+https://github.com/MirrorNeuronLab/mn-cli.git"
elif [[ -f requirements.txt && "${{ steps.detect.outputs.has_python_package }}" != "true" ]]; then
python -m pip install -r requirements.txt
fi
mapfile -t pyprojects < <(find . -maxdepth 2 -name pyproject.toml | sort)
for pyproject in "${pyprojects[@]}"; do
package_dir="$(dirname "$pyproject")"
if grep -q '^\[project\.optional-dependencies\]' "$pyproject" && grep -q '^dev[[:space:]]*=' "$pyproject"; then
python -m pip install -e "$package_dir[dev]"
else
python -m pip install -e "$package_dir"
fi
done
- name: Run configured Python checks
if: steps.detect.outputs.has_python_package == 'true'
shell: bash
run: |
set -euo pipefail
if grep -R --include pyproject.toml -q '^\[tool\.ruff\]' .; then
python -m pip install ruff
python -m ruff check .
fi
if grep -R --include pyproject.toml -q '^\[tool\.mypy\]' .; then
python -m pip install mypy
python -m mypy .
fi
- name: Run Python tests
if: steps.detect.outputs.has_python_tests == 'true'
run: python -m pytest
- name: Build Python distributions
if: steps.detect.outputs.has_python_package == 'true'
shell: bash
run: |
set -euo pipefail
rm -rf dist
mkdir -p dist
mapfile -t pyprojects < <(find . -maxdepth 2 -name pyproject.toml | sort)
for pyproject in "${pyprojects[@]}"; do
package_dir="$(dirname "$pyproject")"
python -m build "$package_dir" --outdir dist
done
python -m twine check dist/*
- name: Verify Python distribution versions
if: steps.detect.outputs.has_python_package == 'true'
shell: bash
run: |
set -euo pipefail
python - "$VERSION" <<'PY'
import email.parser
import glob
import pathlib
import sys
import tarfile
import zipfile
from packaging.version import Version
expected = str(Version(sys.argv[1]))
versions = {}
for wheel in glob.glob("dist/*.whl"):
with zipfile.ZipFile(wheel) as archive:
metadata_name = next(name for name in archive.namelist() if name.endswith(".dist-info/METADATA"))
metadata = email.parser.Parser().parsestr(archive.read(metadata_name).decode("utf-8"))
versions[pathlib.Path(wheel).name] = metadata["Version"]
for sdist in glob.glob("dist/*.tar.gz"):
with tarfile.open(sdist) as archive:
metadata_member = next(member for member in archive.getmembers() if member.name.endswith("/PKG-INFO"))
metadata_file = archive.extractfile(metadata_member)
if metadata_file is None:
raise SystemExit(f"Could not read PKG-INFO from {sdist}")
metadata = email.parser.Parser().parsestr(metadata_file.read().decode("utf-8"))
versions[pathlib.Path(sdist).name] = metadata["Version"]
if not versions:
raise SystemExit("No Python distributions were found in dist/.")
mismatches = {
name: version
for name, version in versions.items()
if str(Version(version)) != expected
}
if mismatches:
for name, version in mismatches.items():
print(f"{name}: expected {expected}, found {version}", file=sys.stderr)
raise SystemExit(1)
print(f"Python distribution versions match {expected}.")
PY
- name: Install npm dependencies
if: steps.detect.outputs.has_npm == 'true'
run: npm ci
- name: Apply tag version to npm metadata
if: steps.detect.outputs.has_npm == 'true'
run: npm version "$VERSION" --no-git-tag-version --allow-same-version
- name: Run npm lint
if: steps.detect.outputs.has_npm == 'true'
run: npm run lint --if-present
- name: Run npm tests
if: steps.detect.outputs.has_npm == 'true'
run: npm test --if-present
- name: Build npm project
if: steps.detect.outputs.has_npm == 'true'
run: npm run build --if-present
- name: Install Elixir dependencies
if: steps.detect.outputs.has_elixir == 'true'
run: mix deps.get
- name: Check Elixir formatting
if: steps.detect.outputs.has_elixir == 'true'
run: mix format --check-formatted
- name: Run Elixir tests
if: steps.detect.outputs.has_elixir == 'true'
run: mix test
- name: Build Elixir project
if: steps.detect.outputs.has_elixir == 'true'
env:
MIX_PROJECT_VERSION: ${{ steps.version.outputs.version }}
run: mix compile --warnings-as-errors
- name: Check shell scripts
if: steps.detect.outputs.has_shell_scripts == 'true'
shell: bash
run: |
set -euo pipefail
while IFS= read -r -d '' script; do
bash -n "$script"
done < <(find . -path './.git' -prune -o -name '*.sh' -print0)
- name: Create release ZIP
shell: bash
run: |
set -euo pipefail
mkdir -p dist/release-assets
scripts/make-release-zip.sh "$TAG_NAME" dist/release-assets
- name: Create SHA256 checksums
shell: bash
run: |
set -euo pipefail
mapfile -t artifacts < <(find dist dist/release-assets -maxdepth 1 -type f \( -name '*.zip' -o -name '*.whl' -o -name '*.tar.gz' \) | LC_ALL=C sort)
if [[ "${#artifacts[@]}" -eq 0 ]]; then
echo "No release artifacts found for checksums." >&2
exit 1
fi
sha256sum "${artifacts[@]}" > dist/SHA256SUMS.txt
- name: Validate release artifacts
shell: bash
run: |
set -euo pipefail
mapfile -t artifacts < <(find dist dist/release-assets -maxdepth 1 -type f \( -name '*.zip' -o -name '*.whl' -o -name '*.tar.gz' -o -name 'SHA256SUMS.txt' \) | LC_ALL=C sort)
scripts/check-release-artifacts.sh "${artifacts[@]}"
- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets
path: |
dist/release-assets/*.zip
dist/SHA256SUMS.txt
dist/*.whl
dist/*.tar.gz
if-no-files-found: error
- name: Upload Python distributions
if: steps.detect.outputs.has_python_package == 'true'
uses: actions/upload-artifact@v4
with:
name: python-dist
path: |
dist/*.whl
dist/*.tar.gz
if-no-files-found: error
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-assets
path: release-assets
- name: Create GitHub Release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
TAG_NAME: ${{ needs.build.outputs.tag_name }}
IS_PRERELEASE: ${{ needs.build.outputs.is_prerelease }}
run: |
set -euo pipefail
if gh release view "$TAG_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Release $TAG_NAME already exists; refusing to overwrite it." >&2
exit 1
fi
mapfile -t assets < <(find release-assets -type f | LC_ALL=C sort)
if [[ "${#assets[@]}" -eq 0 ]]; then
echo "No release assets were downloaded." >&2
exit 1
fi
release_args=(release create "$TAG_NAME" --repo "$GITHUB_REPOSITORY")
release_args+=("${assets[@]}")
release_args+=(--title "$TAG_NAME" --verify-tag --generate-notes)
if [[ "$IS_PRERELEASE" == "true" ]]; then
release_args+=(--prerelease)
fi
gh "${release_args[@]}"
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs:
- build
- github-release
if: needs.build.outputs.has_python_package == 'true' && (needs.build.outputs.is_prerelease == 'false' || vars.PUBLISH_PRERELEASES_TO_PYPI == 'true')
permissions:
contents: read
id-token: write
environment:
name: pypi
steps:
- name: Download Python distributions
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist
- name: Publish Python distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1