Skip to content

Commit 6542bc7

Browse files
committed
feat(ci): add trusted publisher release workflows for JS and Python SDKs
Add GitHub Actions workflows that publish to npm and PyPI using OIDC trusted publishers (no long-lived secrets). - js-sdk-release.yml: triggered by js-sdk-v* tags, publishes to npm with provenance. Includes npm upgrade, OIDC verification, and repository consistency checks. - python-sdk-release.yml: triggered by python-sdk-v* tags, builds with PDM and publishes via pypa/gh-action-pypi-publish. - Add repository field to sdk/js/package.json (required for npm Trusted Publishers / Sigstore provenance verification).
1 parent ae43fb5 commit 6542bc7

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Publish JS SDK to npm
6+
on:
7+
push:
8+
tags: ['js-sdk-v*']
9+
workflow_dispatch:
10+
inputs:
11+
npm_tag:
12+
description: 'npm dist-tag (latest, beta, canary)'
13+
required: true
14+
default: 'latest'
15+
type: choice
16+
options:
17+
- latest
18+
- beta
19+
- canary
20+
21+
permissions:
22+
id-token: write
23+
contents: read
24+
25+
jobs:
26+
publish:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: '20'
34+
registry-url: 'https://registry.npmjs.org'
35+
36+
- name: Upgrade npm for OIDC support
37+
run: |
38+
npm install -g npm@latest
39+
echo "npm version: $(npm --version)"
40+
41+
- name: Verify OIDC token availability
42+
run: |
43+
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ] && [ -n "${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" ]; then
44+
echo "OIDC token available"
45+
else
46+
echo "OIDC token NOT available"
47+
echo "Check workflow permissions include 'id-token: write'"
48+
exit 1
49+
fi
50+
51+
- name: Verify repository configuration
52+
working-directory: sdk/js
53+
run: |
54+
echo "Checking repository consistency..."
55+
GIT_REPO=$(git remote get-url origin | sed 's/.*github.com[/:]//; s/.git$//')
56+
PKG_REPO=$(node -e "console.log(require('./package.json').repository?.url || '')" | sed 's|https://github.com/||; s|git+||; s|.git$||')
57+
echo "Git remote: $GIT_REPO"
58+
echo "package.json: $PKG_REPO"
59+
if [ "$GIT_REPO" != "$PKG_REPO" ]; then
60+
echo "Repository mismatch!"
61+
echo "This will cause 422 error during publish"
62+
exit 1
63+
fi
64+
echo "Repositories match"
65+
66+
- name: Install dependencies
67+
working-directory: sdk/js
68+
run: npm ci
69+
70+
- name: Build
71+
working-directory: sdk/js
72+
run: npm run build
73+
74+
- name: Determine npm dist-tag
75+
id: tag
76+
run: |
77+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
78+
echo "tag=${{ github.event.inputs.npm_tag }}" >> "$GITHUB_OUTPUT"
79+
else
80+
# auto-detect from git tag: js-sdk-v0.5.8-beta.1 -> beta
81+
RAW_TAG="${GITHUB_REF_NAME}"
82+
if echo "$RAW_TAG" | grep -qiE '(beta|alpha|rc|preview)'; then
83+
echo "tag=beta" >> "$GITHUB_OUTPUT"
84+
else
85+
echo "tag=latest" >> "$GITHUB_OUTPUT"
86+
fi
87+
fi
88+
89+
- name: Publish to npm
90+
working-directory: sdk/js
91+
run: |
92+
NPM_TAG="${{ steps.tag.outputs.tag }}"
93+
echo "Publishing with dist-tag: $NPM_TAG"
94+
npm publish --access public --provenance --tag "$NPM_TAG"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Publish Python SDK to PyPI
6+
on:
7+
push:
8+
tags: ['python-sdk-v*']
9+
workflow_dispatch:
10+
inputs:
11+
target:
12+
description: 'Publish target'
13+
required: true
14+
default: 'pypi'
15+
type: choice
16+
options:
17+
- pypi
18+
- testpypi
19+
20+
permissions:
21+
id-token: write
22+
contents: read
23+
24+
jobs:
25+
publish:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.11'
33+
34+
- name: Install PDM
35+
run: pip install pdm
36+
37+
- name: Build distribution
38+
working-directory: sdk/python
39+
run: pdm build
40+
41+
- name: Publish to PyPI
42+
if: github.event_name == 'push' || github.event.inputs.target == 'pypi'
43+
uses: pypa/gh-action-pypi-publish@release/v1
44+
with:
45+
packages-dir: sdk/python/dist
46+
47+
- name: Publish to TestPyPI
48+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi'
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
52+
packages-dir: sdk/python/dist

sdk/js/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
"dstack",
9393
"Phala"
9494
],
95+
"repository": {
96+
"type": "git",
97+
"url": "https://github.com/Dstack-TEE/dstack",
98+
"directory": "sdk/js"
99+
},
95100
"author": "Leechael Yim",
96101
"license": "Apache-2.0",
97102
"dependencies": {

0 commit comments

Comments
 (0)