-
Notifications
You must be signed in to change notification settings - Fork 82
99 lines (84 loc) · 3.33 KB
/
rust-sdk-release.yml
File metadata and controls
99 lines (84 loc) · 3.33 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
# SPDX-FileCopyrightText: © 2026 Phala Network <dstack@phala.network>
#
# SPDX-License-Identifier: Apache-2.0
name: Publish SDK to crates.io
on:
push:
tags: ['dstack-sdk-v*']
jobs:
publish:
runs-on: ubuntu-latest
environment: sdk-release
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v5
- name: Extract version from tag
id: ver
run: |
tag="${GITHUB_REF_NAME}"
version="${tag#dstack-sdk-v}"
if [[ -z "$version" || "$version" == "$tag" ]]; then
echo "::error::tag '$tag' does not start with 'dstack-sdk-v'"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Publishing version: $version"
- name: Verify Cargo.toml versions match tag
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
python3 <<'PY'
import os, sys, tomllib
want = os.environ["VERSION"]
def pkg_version(path):
with open(path, "rb") as f:
return tomllib.load(f)["package"]["version"]
def ws_dep_version(path, name):
with open(path, "rb") as f:
dep = tomllib.load(f)["workspace"]["dependencies"][name]
return dep["version"] if isinstance(dep, dict) else dep
checks = [
("sdk/rust/types/Cargo.toml [package.version]",
pkg_version("sdk/rust/types/Cargo.toml")),
("sdk/rust/Cargo.toml [package.version]",
pkg_version("sdk/rust/Cargo.toml")),
("Cargo.toml [workspace.dependencies.dstack-sdk-types.version]",
ws_dep_version("Cargo.toml", "dstack-sdk-types")),
]
fail = False
for label, got in checks:
ok = got == want
fail = fail or not ok
print(f" {'OK ' if ok else 'BAD'} {label}: {got}")
if fail:
print(f"\ntag is dstack-sdk-v{want}; bump all three to {want} before tagging.",
file=sys.stderr)
sys.exit(1)
PY
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish dstack-sdk-types
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
VERSION: ${{ steps.ver.outputs.version }}
run: .github/scripts/cargo-publish-idempotent.sh dstack-sdk-types
- name: Publish dstack-sdk
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
VERSION: ${{ steps.ver.outputs.version }}
run: .github/scripts/cargo-publish-idempotent.sh dstack-sdk
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.ver.outputs.version }}
run: |
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "::notice::GitHub Release $GITHUB_REF_NAME already exists; skipping"
exit 0
fi
gh release create "$GITHUB_REF_NAME" \
--title "dstack-sdk $VERSION" \
--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)" \
--verify-tag