Skip to content

Commit 2c20587

Browse files
committed
ci: support registry cleanup during publish
1 parent c7dcda7 commit 2c20587

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

.github/workflows/publish-crates.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
description: 'Compatible pd-host-function version. Defaults to 0.22.7.'
1616
required: false
1717
type: string
18+
yank_pd_host_function_version:
19+
description: 'Optional pd-host-function version to yank before publishing.'
20+
required: false
21+
type: string
1822

1923
concurrency:
2024
group: publish-crates-${{ github.ref }}
@@ -43,13 +47,19 @@ jobs:
4347
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
4448
INPUT_VERSION: ${{ inputs.version }}
4549
INPUT_HOST_VERSION: ${{ inputs.pd_host_function_version }}
50+
INPUT_YANK_HOST_VERSION: ${{ inputs.yank_pd_host_function_version }}
4651
run: |
4752
set -euo pipefail
4853
version="${INPUT_VERSION:-${GITHUB_REF_NAME#v}}"
4954
if [[ -z "$version" ]]; then
5055
echo "version is required" >&2
5156
exit 1
5257
fi
53-
python3 scripts/publish_crates.py \
54-
--version "$version" \
58+
args=(
59+
--version "$version"
5560
--host-version "${INPUT_HOST_VERSION:-0.22.7}"
61+
)
62+
if [[ -n "${INPUT_YANK_HOST_VERSION:-}" ]]; then
63+
args+=(--yank-host-version "$INPUT_YANK_HOST_VERSION")
64+
fi
65+
python3 scripts/publish_crates.py "${args[@]}"

scripts/publish_crates.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def publish_plan(release_version: str, host_version: str) -> list[tuple[str, str
2828
return [(package, versions[package]) for package in PACKAGE_ORDER]
2929

3030

31+
def yank_command(package: str, version: str) -> list[str]:
32+
return ["cargo", "yank", "--vers", version, package]
33+
34+
3135
def _rewrite_dependency_versions(text: str, versions: dict[str, str]) -> str:
3236
dependency_re = re.compile(r"^(\s*([A-Za-z0-9_-]+)\s*=\s*\{)(.*)(\}\s*)$")
3337
output = []
@@ -156,6 +160,7 @@ def main() -> None:
156160
parser.add_argument("--host-version", default="0.22.7")
157161
parser.add_argument("--root", type=Path, default=Path.cwd())
158162
parser.add_argument("--prepare-only", action="store_true")
163+
parser.add_argument("--yank-host-version")
159164
args = parser.parse_args()
160165

161166
root = args.root.resolve()
@@ -167,6 +172,13 @@ def main() -> None:
167172
if not os.environ.get("CARGO_REGISTRY_TOKEN"):
168173
raise SystemExit("CARGO_REGISTRY_TOKEN is required")
169174

175+
if args.yank_host_version:
176+
subprocess.run(
177+
yank_command("pd-host-function", args.yank_host_version),
178+
cwd=root,
179+
check=True,
180+
)
181+
170182
for package, version in plan:
171183
if crate_exists(package, version):
172184
print(f"{package} {version} already published; skipping", flush=True)

scripts/test_publish_crates.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def test_rewrite_manifests_applies_release_and_dependency_versions(self) -> None
5050
self.assertIn('vm = { package = "pd-vm", path = "..", version = "0.23.1" }', nostd_manifest)
5151
self.assertIn('version = "0.23.1"', alias_manifest)
5252

53+
def test_yank_command_targets_requested_host_version(self) -> None:
54+
self.assertEqual(
55+
publish_crates.yank_command("pd-host-function", "0.23.0"),
56+
["cargo", "yank", "--vers", "0.23.0", "pd-host-function"],
57+
)
58+
5359
def test_publish_plan_uses_dependency_order_and_per_package_versions(self) -> None:
5460
self.assertEqual(
5561
publish_crates.publish_plan("0.23.1", "0.22.7"),

0 commit comments

Comments
 (0)