Skip to content

Commit d7f37f9

Browse files
committed
ci(sdk): replace release-plz with tag-driven idempotent publish
The release-plz setup hit a wall: the Dstack-TEE org disallows GitHub Actions from creating pull requests, which is the central mechanism release-plz relies on. Plus, the SDK release cadence is low and only involves two coupled crates, so PR-driven automation is overkill. Replace with a simple, explicit workflow: - Trigger: push of a tag matching `dstack-sdk-v*` (single tag covers both crates, which share a version). - Validate that all three version sources agree with the tag: - sdk/rust/types/Cargo.toml [package.version] - sdk/rust/Cargo.toml [package.version] - root Cargo.toml [workspace.dependencies.dstack-sdk-types.version] Fail fast with a clear message if they drift — avoiding the "tag rust-sdk-v0.5.9 but crate is 0.1.2" failure mode that broke the previous workflow. - Publish idempotently via .github/scripts/cargo-publish-idempotent.sh: "already exists on crates.io" is treated as success, so a partial failure can be retried by pushing the same tag without getting stuck on the first crate. - Auto-create a matching GitHub Release for visibility. Drop release-plz.toml. Release workflow for humans: cargo set-version -p dstack-sdk-types -p dstack-sdk <version> # also bump root Cargo.toml workspace.dependencies.dstack-sdk-types.version git commit -am "release: dstack-sdk <version>" git tag dstack-sdk-v<version> git push origin master "dstack-sdk-v<version>"
1 parent fb173c8 commit d7f37f9

3 files changed

Lines changed: 105 additions & 61 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: © 2026 Phala Network <dstack@phala.network>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Wraps `cargo publish -p $1` so that "already exists on crates.io" is treated
7+
# as success. Lets a partially-failed release be retried by pushing the same
8+
# tag, without getting stuck on the first crate.
9+
10+
set -euo pipefail
11+
12+
crate=${1:?missing crate name}
13+
14+
if output=$(cargo publish -p "$crate" 2>&1); then
15+
echo "$output"
16+
exit 0
17+
fi
18+
19+
echo "$output"
20+
21+
if grep -q "already exists on crates.io index" <<<"$output"; then
22+
echo "::notice::$crate is already published at this version; treating as success"
23+
exit 0
24+
fi
25+
26+
exit 1

.github/workflows/rust-sdk-release.yml

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,94 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
name: Release-plz
5+
name: Publish SDK to crates.io
66

77
on:
88
push:
9-
branches:
10-
- master
9+
tags: ['dstack-sdk-v*']
1110

1211
jobs:
13-
release-plz-pr:
14-
name: Release-plz PR
12+
publish:
1513
runs-on: ubuntu-latest
16-
if: ${{ github.repository_owner == 'Dstack-TEE' }}
17-
permissions:
18-
contents: write
19-
pull-requests: write
20-
concurrency:
21-
group: release-plz-${{ github.ref }}
22-
cancel-in-progress: false
23-
steps:
24-
- uses: actions/checkout@v5
25-
with:
26-
fetch-depth: 0
27-
persist-credentials: false
28-
- uses: dtolnay/rust-toolchain@stable
29-
- name: Run release-plz
30-
uses: release-plz/action@v0.5
31-
with:
32-
command: release-pr
33-
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
36-
release-plz-release:
37-
name: Release-plz release
38-
runs-on: ubuntu-latest
39-
if: ${{ github.repository_owner == 'Dstack-TEE' }}
4014
environment: sdk-release
4115
permissions:
42-
contents: write
43-
pull-requests: read
4416
id-token: write
17+
contents: read
4518
steps:
4619
- uses: actions/checkout@v5
47-
with:
48-
fetch-depth: 0
49-
persist-credentials: false
50-
- uses: dtolnay/rust-toolchain@stable
51-
- name: Run release-plz
52-
uses: release-plz/action@v0.5
53-
with:
54-
command: release
20+
21+
- name: Extract version from tag
22+
id: ver
23+
run: |
24+
tag="${GITHUB_REF_NAME}"
25+
version="${tag#dstack-sdk-v}"
26+
if [[ -z "$version" || "$version" == "$tag" ]]; then
27+
echo "::error::tag '$tag' does not start with 'dstack-sdk-v'"
28+
exit 1
29+
fi
30+
echo "version=$version" >> "$GITHUB_OUTPUT"
31+
echo "Publishing version: $version"
32+
33+
- name: Verify Cargo.toml versions match tag
34+
env:
35+
VERSION: ${{ steps.ver.outputs.version }}
36+
run: |
37+
python3 <<'PY'
38+
import os, sys, tomllib
39+
40+
want = os.environ["VERSION"]
41+
42+
def pkg_version(path):
43+
with open(path, "rb") as f:
44+
return tomllib.load(f)["package"]["version"]
45+
46+
def ws_dep_version(path, name):
47+
with open(path, "rb") as f:
48+
dep = tomllib.load(f)["workspace"]["dependencies"][name]
49+
return dep["version"] if isinstance(dep, dict) else dep
50+
51+
checks = [
52+
("sdk/rust/types/Cargo.toml [package.version]",
53+
pkg_version("sdk/rust/types/Cargo.toml")),
54+
("sdk/rust/Cargo.toml [package.version]",
55+
pkg_version("sdk/rust/Cargo.toml")),
56+
("Cargo.toml [workspace.dependencies.dstack-sdk-types.version]",
57+
ws_dep_version("Cargo.toml", "dstack-sdk-types")),
58+
]
59+
60+
fail = False
61+
for label, got in checks:
62+
ok = got == want
63+
fail = fail or not ok
64+
print(f" {'OK ' if ok else 'BAD'} {label}: {got}")
65+
66+
if fail:
67+
print(f"\ntag is dstack-sdk-v{want}; bump all three to {want} before tagging.",
68+
file=sys.stderr)
69+
sys.exit(1)
70+
PY
71+
72+
- uses: rust-lang/crates-io-auth-action@v1
73+
id: auth
74+
75+
- name: Publish dstack-sdk-types
76+
env:
77+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
78+
VERSION: ${{ steps.ver.outputs.version }}
79+
run: .github/scripts/cargo-publish-idempotent.sh dstack-sdk-types
80+
81+
- name: Publish dstack-sdk
82+
env:
83+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
84+
VERSION: ${{ steps.ver.outputs.version }}
85+
run: .github/scripts/cargo-publish-idempotent.sh dstack-sdk
86+
87+
- name: Create GitHub Release
5588
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
GH_TOKEN: ${{ github.token }}
90+
VERSION: ${{ steps.ver.outputs.version }}
91+
run: |
92+
gh release create "$GITHUB_REF_NAME" \
93+
--title "dstack-sdk $VERSION" \
94+
--notes "Published to crates.io: [dstack-sdk@$VERSION](https://crates.io/crates/dstack-sdk/$VERSION), [dstack-sdk-types@$VERSION](https://crates.io/crates/dstack-sdk-types/$VERSION)" \
95+
--verify-tag

release-plz.toml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)