Skip to content

Commit 2deeab7

Browse files
authored
Merge pull request #692 from Dstack-TEE/ci/sdk-tag-driven-release
ci(sdk): replace release-plz with tag-driven publish
2 parents fb173c8 + 261f2c6 commit 2deeab7

4 files changed

Lines changed: 109 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: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,98 @@
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' }}
14+
environment: sdk-release
1715
permissions:
16+
id-token: write
1817
contents: write
19-
pull-requests: write
20-
concurrency:
21-
group: release-plz-${{ github.ref }}
22-
cancel-in-progress: false
2318
steps:
2419
- 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
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
3334
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
VERSION: ${{ steps.ver.outputs.version }}
36+
run: |
37+
python3 <<'PY'
38+
import os, sys, tomllib
3539
36-
release-plz-release:
37-
name: Release-plz release
38-
runs-on: ubuntu-latest
39-
if: ${{ github.repository_owner == 'Dstack-TEE' }}
40-
environment: sdk-release
41-
permissions:
42-
contents: write
43-
pull-requests: read
44-
id-token: write
45-
steps:
46-
- 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
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+
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
93+
echo "::notice::GitHub Release $GITHUB_REF_NAME already exists; skipping"
94+
exit 0
95+
fi
96+
gh release create "$GITHUB_REF_NAME" \
97+
--title "dstack-sdk $VERSION" \
98+
--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)" \
99+
--verify-tag

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ resolver = "2"
6161
# Internal dependencies
6262
ra-rpc = { path = "ra-rpc", default-features = false }
6363
ra-tls = { path = "ra-tls" }
64-
dstack-sdk-types = { path = "sdk/rust/types", version = "0.1.1", default-features = false }
64+
dstack-sdk-types = { path = "sdk/rust/types", version = "0.1.2", default-features = false }
6565
dstack-gateway-rpc = { path = "gateway/rpc" }
6666
dstack-kms-rpc = { path = "kms/rpc" }
6767
dstack-guest-agent-rpc = { path = "guest-agent/rpc" }

release-plz.toml

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

0 commit comments

Comments
 (0)