Skip to content

Commit f0bcdac

Browse files
committed
Refactor release workflow helpers
1 parent 26061f3 commit f0bcdac

7 files changed

Lines changed: 119 additions & 40 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
python -m pip install -U build twine setuptools
5+
python -m build --sdist
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
dist_dir="${1:-dist}"
5+
6+
ls -ahl "$dist_dir"
7+
pkg="$(ls -t "$dist_dir"/*.tar.gz | head -n 1 | xargs basename)"
8+
echo "PKG_NAME=$pkg" >> "$GITHUB_ENV"
9+
twine check "$dist_dir/$pkg"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
pkg_name="${1:?package filename is required}"
5+
venv_dir="${2:-local_uv_env}"
6+
7+
uv venv "$venv_dir"
8+
source "$venv_dir/bin/activate"
9+
uv pip install "dist/$pkg_name" torch
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
pkg_name="${1:?package filename is required}"
5+
run_id="${2:?run_id is required}"
6+
7+
sha256sum "dist/$pkg_name"
8+
target_dir="/opt/dist/$run_id"
9+
mkdir -p "$target_dir"
10+
cp "dist/$pkg_name" "$target_dir/"
11+
echo "UPLOADED=1" >> "$GITHUB_ENV"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
mode="${1:?mode is required}"
5+
6+
case "$mode" in
7+
sleep)
8+
for _ in {1..5}; do sleep 5; done
9+
;;
10+
manual)
11+
runner_host="${RUNNER:?RUNNER is required}"
12+
run_id="${GITHUB_RUN_ID:?GITHUB_RUN_ID is required}"
13+
timestamp="$(date +%s%3N)"
14+
echo "open http://${runner_host}/gpu/ci/confirm?id=${run_id}&timestamp=$timestamp&confirmed=1 to confirm releasing to pypi"
15+
for _ in {1..5}; do echo "."; done
16+
echo "click http://${runner_host}/gpu/ci/confirm?id=${run_id}&timestamp=$timestamp&denied=1 to DENY"
17+
18+
status=-1
19+
while [[ "$status" -lt 0 ]]; do
20+
status="$(curl -s "http://${runner_host}/gpu/ci/confirm?id=${run_id}&timestamp=$timestamp")"
21+
if [[ "$status" == "2" ]]; then
22+
echo "PYPI_RELEASE_CONFIRMATION=$status" >> "$GITHUB_ENV"
23+
elif [[ "$status" -lt 0 ]]; then
24+
sleep 5
25+
else
26+
echo "release has been confirmed"
27+
echo "PYPI_RELEASE_CONFIRMATION=$status" >> "$GITHUB_ENV"
28+
fi
29+
done
30+
;;
31+
*)
32+
echo "Unsupported confirmation mode: $mode" >&2
33+
exit 1
34+
;;
35+
esac

.github/workflows/release.yml

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,20 @@ jobs:
116116
117117
- name: Build sdist
118118
run: |
119-
python -m pip install -U build twine setuptools
120-
python -m build --sdist
119+
.github/scripts/ci_release_build_sdist.sh
121120
122121
- name: Check dist
123122
run: |
124-
ls -ahl dist
125-
pkg=$(ls -t dist/*.tar.gz | head -n 1 | xargs basename)
126-
echo "PKG_NAME=$pkg" >> "$GITHUB_ENV"
127-
twine check "dist/$pkg"
123+
.github/scripts/ci_release_check_dist.sh
128124
129125
- name: test installation
130126
run: |
131-
uv venv local_uv_env
132-
source local_uv_env/bin/activate
133-
uv pip install "dist/${{ env.PKG_NAME }}" torch
127+
.github/scripts/ci_release_test_install.sh "${{ env.PKG_NAME }}"
134128
135129
- name: Upload to local
136130
continue-on-error: true
137131
run: |
138-
sha256sum "dist/${{ env.PKG_NAME }}"
139-
DIR=/opt/dist/${{ needs.check-vm.outputs.run_id }}
140-
[ -d "$DIR" ] || mkdir -p "$DIR"
141-
cp "dist/${{ env.PKG_NAME }}" "$DIR/"
142-
echo "UPLOADED=1" >> "$GITHUB_ENV"
132+
.github/scripts/ci_release_upload_local.sh "${{ env.PKG_NAME }}" "${{ needs.check-vm.outputs.run_id }}"
143133
144134
- name: Upload to artifact
145135
uses: actions/upload-artifact@v7
@@ -160,22 +150,7 @@ jobs:
160150
- name: Waiting for confirmation
161151
if: (github.event_name == 'release' || github.event.inputs.upload_pypi == 'true') && !cancelled()
162152
run: |
163-
timestamp=$(date +%s%3N)
164-
echo "open http://${RUNNER}/gpu/ci/confirm?id=${{ github.run_id }}&timestamp=$timestamp&confirmed=1 to confirm releasing to pypi"
165-
for i in {1..5}; do echo "."; done
166-
echo "click http://${RUNNER}/gpu/ci/confirm?id=${{ github.run_id }}&timestamp=$timestamp&denied=1 to DENY"
167-
status=-1
168-
while [ "$status" -lt 0 ]; do
169-
status=$(curl -s "http://${RUNNER}/gpu/ci/confirm?id=${{ github.run_id }}&timestamp=$timestamp")
170-
if [ "$status" == "2" ]; then
171-
echo "PYPI_RELEASE_CONFIRMATION=$status" >> "$GITHUB_ENV"
172-
elif [ "$status" -lt 0 ]; then
173-
sleep 5
174-
else
175-
echo "release has been confirmed"
176-
echo "PYPI_RELEASE_CONFIRMATION=$status" >> "$GITHUB_ENV"
177-
fi
178-
done
153+
.github/scripts/ci_release_wait_for_confirmation.sh manual
179154
180155
- name: Upload sdist to pypi
181156
if: (github.event_name == 'release' || github.event.inputs.upload_pypi == 'true') && env.PYPI_RELEASE_CONFIRMATION == '1' && !cancelled()
@@ -204,20 +179,13 @@ jobs:
204179
python-version: '3.14'
205180
cache: 'pip'
206181

207-
- name: Install requirements
208-
run: |
209-
python -m pip install -U build twine setuptools
210-
211182
- name: Build sdist
212183
run: |
213-
python -m build --sdist
184+
.github/scripts/ci_release_build_sdist.sh
214185
215186
- name: Check dist
216187
run: |
217-
ls -ahl dist
218-
pkg=$(ls -t dist/*.tar.gz | head -n 1 | xargs basename)
219-
echo "PKG_NAME=$pkg" >> "$GITHUB_ENV"
220-
twine check "dist/$pkg"
188+
.github/scripts/ci_release_check_dist.sh
221189
222190
- name: Upload to artifact
223191
uses: actions/upload-artifact@v7
@@ -237,7 +205,7 @@ jobs:
237205
- name: Waiting for confirmation
238206
if: (github.event_name == 'release' || github.event.inputs.upload_pypi == 'true') && !cancelled()
239207
run: |
240-
for i in {1..5}; do sleep 5; done
208+
.github/scripts/ci_release_wait_for_confirmation.sh sleep
241209
242210
- name: Upload sdist to pypi
243211
if: (github.event_name == 'release' || github.event.inputs.upload_pypi == 'true') && !cancelled()

tests/test_ci_workflow_scripts.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from __future__ import annotations
66

77
import importlib.util
8+
import os
89
import subprocess
910
import sys
1011
import tarfile
12+
import time
1113
from pathlib import Path
1214

1315
import pytest
@@ -77,6 +79,11 @@ def test_build_test_matrix_marks_model_entries():
7779
"script_name",
7880
[
7981
"ci_prepare_checkout.sh",
82+
"ci_release_build_sdist.sh",
83+
"ci_release_check_dist.sh",
84+
"ci_release_test_install.sh",
85+
"ci_release_upload_local.sh",
86+
"ci_release_wait_for_confirmation.sh",
8087
"ci_restore_uv_cache.sh",
8188
"ci_install_modelcloud_git_deps.sh",
8289
],
@@ -109,3 +116,38 @@ def test_ci_restore_uv_cache_script_skips_unchanged_archive(tmp_path: Path):
109116
check=True,
110117
)
111118
assert restored_file.read_text(encoding="utf-8") == "mutated-cache"
119+
120+
121+
def test_ci_release_check_dist_script_sets_latest_package(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
122+
dist_dir = tmp_path / "dist"
123+
dist_dir.mkdir()
124+
older = dist_dir / "pkg-old.tar.gz"
125+
newer = dist_dir / "pkg-new.tar.gz"
126+
older.write_text("old", encoding="utf-8")
127+
time.sleep(0.01)
128+
newer.write_text("new", encoding="utf-8")
129+
130+
fake_bin = tmp_path / "bin"
131+
fake_bin.mkdir()
132+
fake_twine = fake_bin / "twine"
133+
fake_twine.write_text(
134+
"#!/usr/bin/env bash\n"
135+
"set -euo pipefail\n"
136+
"echo \"$@\" > \"$TWINE_LOG\"\n",
137+
encoding="utf-8",
138+
)
139+
fake_twine.chmod(0o755)
140+
141+
github_env = tmp_path / "github_env"
142+
twine_log = tmp_path / "twine.log"
143+
monkeypatch.setenv("GITHUB_ENV", str(github_env))
144+
monkeypatch.setenv("TWINE_LOG", str(twine_log))
145+
monkeypatch.setenv("PATH", f"{fake_bin}:{os.environ['PATH']}")
146+
147+
subprocess.run(
148+
["bash", str(SCRIPT_DIR / "ci_release_check_dist.sh"), str(dist_dir)],
149+
check=True,
150+
)
151+
152+
assert "PKG_NAME=pkg-new.tar.gz" in github_env.read_text(encoding="utf-8")
153+
assert twine_log.read_text(encoding="utf-8").strip() == f"check {newer}"

0 commit comments

Comments
 (0)