Skip to content

Agent Mesh

release: parallelize SDK publishing into separate jobs with retry support

Antonio Ojea10b9555ca2dc
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 165d9c47..6f58a9ba 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -6,13 +6,22 @@ on:
tags:
- "v*"
# Publish the SDKs of a tag whose release already exists (a failed
- # publish-sdks run). goreleaser does not run again.
+ # publish-sdk-* run). goreleaser does not run again.
workflow_dispatch:
inputs:
tag:
description: "Existing release tag, e.g. v0.1.0-rc.4"
required: true
type: string
+ sdk:
+ description: "SDK to publish"
+ required: false
+ default: "all"
+ type: choice
+ options:
+ - all
+ - js
+ - python
permissions:
contents: read
@@ -45,10 +54,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- publish-sdks:
+ publish-sdk-js:
runs-on: ubuntu-latest
needs: goreleaser
- if: always() && (github.event_name == 'workflow_dispatch' || needs.goreleaser.result == 'success')
+ if: always() && (github.event_name == 'workflow_dispatch' || needs.goreleaser.result == 'success') && (github.event_name != 'workflow_dispatch' || inputs.sdk == 'all' || inputs.sdk == 'js' || inputs.sdk == '')
permissions:
contents: read
id-token: write
@@ -66,25 +75,49 @@ jobs:
registry-url: "https://registry.npmjs.org"
cache: npm
cache-dependency-path: sdk/js/package-lock.json
- - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
- with:
- python-version: "3.12"
- name: Stamp the release version on both SDKs
run: ./hack/sdk-version.sh "${SDK_VERSION#v}"
- name: Build and publish @sam-mesh/sdk
# npm's trusted publishing needs npm 11.5 or later; Node 22 ships 10.
# npm 11 refuses to publish a prerelease without an explicit dist-tag,
# and "latest" must stay on stable versions.
+ # If this version is already published, skip so the job can be safely retried.
working-directory: sdk/js
run: |
+ ver="${SDK_VERSION#v}"
+ if npm view "@sam-mesh/sdk@${ver}" version >/dev/null 2>&1; then
+ echo "@sam-mesh/sdk@${ver} is already published on npm; skipping."
+ exit 0
+ fi
npm install -g npm@latest
npm ci
npm run build
- case "${SDK_VERSION#v}" in
+ case "$ver" in
*-*) tag=next ;;
*) tag=latest ;;
esac
npm publish --provenance --access public --tag "$tag"
+
+ publish-sdk-python:
+ runs-on: ubuntu-latest
+ needs: goreleaser
+ if: always() && (github.event_name == 'workflow_dispatch' || needs.goreleaser.result == 'success') && (github.event_name != 'workflow_dispatch' || inputs.sdk == 'all' || inputs.sdk == 'python' || inputs.sdk == '')
+ permissions:
+ contents: read
+ id-token: write
+ env:
+ SDK_VERSION: ${{ inputs.tag || github.ref_name }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ inputs.tag || github.ref }}
+ persist-credentials: false
+ - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
+ with:
+ python-version: "3.12"
+ - name: Stamp the release version on both SDKs
+ run: ./hack/sdk-version.sh "${SDK_VERSION#v}"
- name: Build sam-mesh
working-directory: sdk/python
run: |
@@ -94,3 +127,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
packages-dir: sdk/python/dist/
+ skip-existing: true
diff --git a/hack/sdk-version.sh b/hack/sdk-version.sh
index b84a70db..bd7e2e2f 100755
--- a/hack/sdk-version.sh
+++ b/hack/sdk-version.sh
@@ -23,8 +23,14 @@ set -o errexit
set -o nounset
set -o pipefail
+target="all"
+case "${1:-}" in
+ --js) target="js"; shift ;;
+ --python) target="python"; shift ;;
+esac
+
if [[ $# -ne 1 || ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
- echo "usage: $0 <semver, e.g. 1.2.3>" >&2
+ echo "usage: $0 [--js|--python] <semver, e.g. 1.2.3>" >&2
exit 2
fi
VERSION="$1"
@@ -32,16 +38,28 @@ VERSION="$1"
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"
-# package.json and package-lock.json together; the client identity the SDK
-# presents to MCP peers follows.
-(cd sdk/js && npm version --no-git-tag-version --allow-same-version "${VERSION}" >/dev/null)
-sed -i -E "s/^(export const MCP_CLIENT_INFO = \{ name: \"agent-mesh-sdk\", version: \")[^\"]+(\" \};)$/\1${VERSION}\2/" sdk/js/src/mcp.ts
+if [[ "${target}" == "all" || "${target}" == "js" ]]; then
+ # package.json and package-lock.json together; the client identity the SDK
+ # presents to MCP peers follows.
+ (cd sdk/js && npm version --no-git-tag-version --allow-same-version "${VERSION}" >/dev/null)
+ sed -i -E "s/^(export const MCP_CLIENT_INFO = \{ name: \"agent-mesh-sdk\", version: \")[^\"]+(\" \};)$/\1${VERSION}\2/" sdk/js/src/mcp.ts
+fi
+
+if [[ "${target}" == "all" || "${target}" == "python" ]]; then
+ sed -i -E "s/^version = \"[^\"]+\"$/version = \"${VERSION}\"/" sdk/python/pyproject.toml
+ sed -i -E "s/^__version__ = \"[^\"]+\"$/__version__ = \"${VERSION}\"/" sdk/python/src/agent_mesh/__init__.py
+ sed -i -E "s/^(MCP_CLIENT_INFO = mcp_types.Implementation\(name=\"agent-mesh-sdk\", version=\")[^\"]+(\"\))$/\1${VERSION}\2/" sdk/python/src/agent_mesh/mcp_client.py
+fi
-sed -i -E "s/^version = \"[^\"]+\"$/version = \"${VERSION}\"/" sdk/python/pyproject.toml
-sed -i -E "s/^__version__ = \"[^\"]+\"$/__version__ = \"${VERSION}\"/" sdk/python/src/agent_mesh/__init__.py
-sed -i -E "s/^(MCP_CLIENT_INFO = mcp_types.Implementation\(name=\"agent-mesh-sdk\", version=\")[^\"]+(\"\))$/\1${VERSION}\2/" sdk/python/src/agent_mesh/mcp_client.py
+files=()
+if [[ "${target}" == "all" || "${target}" == "js" ]]; then
+ files+=(sdk/js/package.json sdk/js/src/mcp.ts)
+fi
+if [[ "${target}" == "all" || "${target}" == "python" ]]; then
+ files+=(sdk/python/pyproject.toml sdk/python/src/agent_mesh/__init__.py sdk/python/src/agent_mesh/mcp_client.py)
+fi
-for f in sdk/js/package.json sdk/python/pyproject.toml sdk/python/src/agent_mesh/__init__.py sdk/js/src/mcp.ts sdk/python/src/agent_mesh/mcp_client.py; do
+for f in "${files[@]}"; do
if ! grep -q "\"${VERSION}\"" "$f"; then
echo "ERROR: ${f} does not carry ${VERSION} after stamping" >&2
exit 1
diff --git a/sdk/README.md b/sdk/README.md
index 6f2d9cb7..e5b5ff33 100644
--- a/sdk/README.md
+++ b/sdk/README.md
@@ -432,10 +432,11 @@ holds against the control plane's records.
`@sam-mesh/sdk` to npm and `sam-mesh` to PyPI through trusted
publishing. A prerelease tag (`v0.1.0-rc.4`) publishes under the npm
dist-tag `next`, a stable tag under `latest`; PyPI needs no tag, `pip`
- skips prereleases on its own. When `publish-sdks` fails after the
- GitHub release exists, run the workflow by hand from the Actions tab
- with the tag as input; it checks out that tag and publishes only the
- SDKs. One-time setup by a package owner: on npmjs.com, create the
+ skips prereleases on its own. When a publish job (`publish-sdk-js`
+ or `publish-sdk-python`) fails after the GitHub release exists, re-run
+ the failed job, or run the workflow by hand from the Actions tab with
+ the tag and target SDK as input; it checks out that tag and publishes
+ the selected SDK. One-time setup by a package owner: on npmjs.com, create the
`sam-mesh` organization, publish `@sam-mesh/sdk` 0.1.0 once by hand
(`cd sdk/js && npm publish --access public`; the trusted-publisher
settings live on the package page, which exists only after that), then