|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -name: Release-plz |
| 5 | +name: Publish SDK to crates.io |
6 | 6 |
|
7 | 7 | on: |
8 | 8 | push: |
9 | | - branches: |
10 | | - - master |
| 9 | + tags: ['dstack-sdk-v*'] |
11 | 10 |
|
12 | 11 | jobs: |
13 | | - release-plz-pr: |
14 | | - name: Release-plz PR |
| 12 | + publish: |
15 | 13 | runs-on: ubuntu-latest |
16 | | - if: ${{ github.repository_owner == 'Dstack-TEE' }} |
| 14 | + environment: sdk-release |
17 | 15 | permissions: |
| 16 | + id-token: write |
18 | 17 | contents: write |
19 | | - pull-requests: write |
20 | | - concurrency: |
21 | | - group: release-plz-${{ github.ref }} |
22 | | - cancel-in-progress: false |
23 | 18 | steps: |
24 | 19 | - 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 |
33 | 34 | env: |
34 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + VERSION: ${{ steps.ver.outputs.version }} |
| 36 | + run: | |
| 37 | + python3 <<'PY' |
| 38 | + import os, sys, tomllib |
35 | 39 |
|
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 |
55 | 88 | 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 |
0 commit comments