Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 221 additions & 49 deletions .github/workflows/sdk-publish.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,253 @@
name: Automated SDK Build & Publish
name: SDK Publish

# Builds, verifies and publishes the JavaScript, Python and Go SDKs together.
# The OpenAPI 3.1 check and publish manifest come from scripts/publish-sdks.js.
#
# - Pull requests, pushes to main and manual runs are dry runs: every SDK is
# tested and packaged, nothing is published.
# - Pushing a tag `sdk-vX.Y.Z` that matches sdks/VERSION publishes all three,
# and only after all three verified. A re-run skips registries that already
# have the version.
#
# Runbook: sdks/docs/releasing.md

on:
push:
branches:
- main
branches: [main]
tags: ['sdk-v*']
paths:
- 'sdks/**'
- 'developer-portal/docs/openapi.json'
- 'scripts/publish-sdks.js'
- 'scripts/generate-sdks.js'
- '.github/workflows/sdk-publish.yml'
pull_request:
paths:
- 'sdks/**'
- 'developer-portal/docs/openapi.json'
- 'scripts/publish-sdks.js'
tags:
- 'sdk-v*'
- 'scripts/generate-sdks.js'
- '.github/workflows/sdk-publish.yml'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: sdk-publish-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}

jobs:
validate-and-build:
name: Build & Validate SDKs
prepare:
name: Plan release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.plan.outputs.version }}
python_version: ${{ steps.plan.outputs.python_version }}
npm_tag: ${{ steps.plan.outputs.npm_tag }}
go_module: ${{ steps.plan.outputs.go_module }}
go_tag: ${{ steps.plan.outputs.go_tag }}
publish: ${{ steps.plan.outputs.publish }}
npm_published: ${{ steps.registry.outputs.npm_published }}
pypi_published: ${{ steps.registry.outputs.pypi_published }}
go_published: ${{ steps.registry.outputs.go_published }}
steps:
- name: Checkout Code
uses: actions/checkout@v7

- name: Validate OpenAPI 3.1 Spec
- uses: actions/checkout@v7
- uses: actions/setup-node@v4
with:
node-version: '24'
- name: Test release tooling
run: node --test sdks/scripts/__tests__/release.test.mjs
- name: Check versions and changelog
run: node sdks/scripts/release.mjs check
- name: Plan
id: plan
run: node sdks/scripts/release.mjs plan
# OpenAPI 3.1 validation and publish manifest (scripts/publish-sdks.js, #2217).
# Always a dry run here: the publish-* jobs below do the registry uploads.
- name: Validate OpenAPI spec and write publish manifest
env:
VERSION: ${{ steps.plan.outputs.version }}
run: |
npx @redocly/cli lint developer-portal/docs/openapi.json
node scripts/generate-sdks.js
node scripts/publish-sdks.js --version "sdk-v$VERSION"
- uses: actions/upload-artifact@v4
with:
name: sdk-publish-manifest
path: sdks/generated/publish-manifest.json
if-no-files-found: error
- name: Check registries
id: registry
if: steps.plan.outputs.publish == 'true'
run: node sdks/scripts/release.mjs registry-status

- name: Setup Node.js
uses: pnpm/action-setup@v6
verify-javascript:
name: Verify JavaScript SDK
needs: prepare
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdks/javascript
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: npm
cache-dependency-path: sdks/javascript/package-lock.json
- run: npm ci
- name: Typecheck
run: npm test
- name: Build
run: npm run build
- name: Pack
run: npm pack
- uses: actions/upload-artifact@v4
with:
name: sdk-javascript
path: sdks/javascript/*.tgz
if-no-files-found: error

- name: Build JS SDK
run: |
cd sdks/javascript
pnpm install --frozen-lockfile
npm run build || true

- name: Setup Python
uses: actions/setup-python@v7
verify-python:
name: Verify Python SDK
needs: prepare
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdks/python
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.11'

- name: Validate Python SDK
run: |
cd sdks/python
python -m pip install --upgrade pip
pip install requests

- name: Setup Go
uses: actions/setup-go@v7
- name: Install
run: python -m pip install --upgrade pip build twine && python -m pip install -e .
- name: Test
run: python -m unittest discover tests
- name: Build sdist and wheel
run: python -m build
- name: Check distributions
run: python -m twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
go-version: '1.21'
name: sdk-python
path: sdks/python/dist/*
if-no-files-found: error

- name: Validate Go SDK
run: |
cd sdks/go
go test ./... || true

publish:
name: Publish SDKs
if: startsWith(github.ref, 'refs/tags/sdk-v')
needs: validate-and-build
verify-go:
name: Verify Go SDK
needs: prepare
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdks/go
steps:
- name: Checkout Code
uses: actions/checkout@v7
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: sdks/go/go.mod
- run: go vet ./...
- run: go test -race ./...

- uses: pnpm/action-setup@v6
publish-npm:
name: Publish to npm
needs: [prepare, verify-javascript, verify-python, verify-go]
if: needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.npm_published != 'true'
runs-on: ubuntu-latest
environment: npm
permissions:
contents: read
id-token: write # npm provenance
steps:
- uses: actions/setup-node@v4
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v4
with:
name: sdk-javascript
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TAG: ${{ needs.prepare.outputs.npm_tag }}
run: npm publish ./*.tgz --tag "$NPM_TAG" --access public --provenance

- name: Generate SDK metadata
run: npm run sdk:generate
publish-pypi:
name: Publish to PyPI
needs: [prepare, verify-javascript, verify-python, verify-go]
if: needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.pypi_published != 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write # PyPI trusted publishing
steps:
- uses: actions/download-artifact@v4
with:
name: sdk-python
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist

- name: Publish SDKs
run: node scripts/publish-sdks.js --version "${GITHUB_REF_NAME}" --publish
publish-go:
name: Publish Go module
needs: [prepare, verify-javascript, verify-python, verify-go]
if: needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.go_published != 'true'
runs-on: ubuntu-latest
permissions:
contents: write # push the sdks/go/vX.Y.Z tag
env:
GO_TAG: ${{ needs.prepare.outputs.go_tag }}
GO_MODULE: ${{ needs.prepare.outputs.go_module }}
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: sdks/go/go.mod
- name: Tag module
run: |
if git ls-remote --exit-code --tags origin "refs/tags/$GO_TAG" >/dev/null; then
echo "[sdk-release] $GO_TAG already exists; not re-tagging"
else
git tag "$GO_TAG" "$GITHUB_SHA"
git push origin "refs/tags/$GO_TAG"
echo "[sdk-release] pushed $GO_TAG at $GITHUB_SHA"
fi
- name: Register with the Go module proxy
run: |
cd "$(mktemp -d)"
for attempt in 1 2 3 4 5; do
if GOPROXY=https://proxy.golang.org GOFLAGS=-mod=mod go mod download -json "$GO_MODULE@v$VERSION"; then
echo "[sdk-release] $GO_MODULE@v$VERSION is available on proxy.golang.org"
exit 0
fi
echo "[sdk-release] proxy not ready (attempt $attempt); retrying"
sleep $((attempt * 15))
done
echo "::error::$GO_MODULE@v$VERSION did not become available on proxy.golang.org"
exit 1

summary:
name: Release summary
needs:
[prepare, verify-javascript, verify-python, verify-go, publish-npm, publish-pypi, publish-go]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v4
with:
node-version: '24'
- name: Summarise
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# When publishing, report the publish job unless the registry already
# had the version; otherwise report the verify job.
JAVASCRIPT_RESULT: ${{ (needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.npm_published != 'true') && needs.publish-npm.result || needs.verify-javascript.result }}
PYTHON_RESULT: ${{ (needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.pypi_published != 'true') && needs.publish-pypi.result || needs.verify-python.result }}
GO_RESULT: ${{ (needs.prepare.outputs.publish == 'true' && needs.prepare.outputs.go_published != 'true') && needs.publish-go.result || needs.verify-go.result }}
JAVASCRIPT_ALREADY_PUBLISHED: ${{ needs.prepare.outputs.npm_published }}
PYTHON_ALREADY_PUBLISHED: ${{ needs.prepare.outputs.pypi_published }}
GO_ALREADY_PUBLISHED: ${{ needs.prepare.outputs.go_published }}
run: node sdks/scripts/release.mjs summary
12 changes: 12 additions & 0 deletions scripts/__tests__/openapiSdkPublisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ describe('SDK publish plan', () => {
]);
});

it('accepts pre-release tags in the format sdks/scripts/release.mjs uses', () => {
expect(publisher.buildPublishPlan(spec, 'sdk-v2.1.0-rc.1').version).toBe('2.1.0-rc.1');
expect(() => publisher.buildPublishPlan(spec, 'sdk-v2.1.0-dev.1')).toThrow(
'Invalid version tag'
);
});

it('targets the /v2 Go module path', () => {
const plan = publisher.buildPublishPlan(spec, 'sdk-v2.0.0', ['go']);
expect(plan.targets[0].package).toBe('github.com/Smartdevs17/SubTrackr/sdks/go/v2');
});

it('rejects invalid tags and unknown targets', () => {
expect(() => publisher.buildPublishPlan(spec, 'v1.2.3')).toThrow('Invalid version tag');
expect(() => publisher.buildPublishPlan(spec, 'sdk-v1.2.3', [])).toThrow('No SDK targets');
Expand Down
11 changes: 8 additions & 3 deletions scripts/publish-sdks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ const TARGETS = {
javascript: { package: '@subtrackr/sdk', registry: 'npm' },
python: { package: 'subtrackr-sdk', registry: 'pypi' },
go: {
package: 'github.com/Smartdevs17/SubTrackr/sdks/go',
// Go semantic import versioning: the module path carries /vN from v2 on
// (see sdks/go/go.mod and sdks/scripts/lib/release.mjs).
package: 'github.com/Smartdevs17/SubTrackr/sdks/go/v2',
registry: 'proxy.golang.org',
},
};

const TAG_PATTERN = /^sdk-v(\d+\.\d+\.\d+)$/;
// Matches the versions sdks/scripts/release.mjs accepts, pre-releases included.
const TAG_PATTERN = /^sdk-v(\d+\.\d+\.\d+(?:-(?:alpha|beta|rc)\.\d+)?)$/;

function assertOpenApi31(spec) {
if (!spec || typeof spec !== 'object') {
Expand All @@ -37,7 +40,9 @@ function buildPublishPlan(spec, tag, languages = Object.keys(TARGETS)) {
assertOpenApi31(spec);
const match = TAG_PATTERN.exec(tag || '');
if (!match) {
throw new Error(`[sdk:publish] Invalid version tag "${tag}". Expected sdk-vX.Y.Z`);
throw new Error(
`[sdk:publish] Invalid version tag "${tag}". Expected sdk-vX.Y.Z or sdk-vX.Y.Z-(alpha|beta|rc).N`
);
}
if (!languages.length) {
throw new Error('[sdk:publish] No SDK targets selected');
Expand Down
22 changes: 22 additions & 0 deletions sdks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SubTrackr SDK changelog

All three SDKs (JavaScript, Python, Go) share one version, set in
[`VERSION`](VERSION). Every release needs a section here before it can be
tagged; `node sdks/scripts/release.mjs check` enforces it. See
[docs/releasing.md](docs/releasing.md).

## [2.0.0]

First release published to the package registries.

- JavaScript: `@subtrackr/sdk` on npm.
- Python: `subtrackr-sdk` on PyPI.
- Go: `github.com/Smartdevs17/SubTrackr/sdks/go/v2`. The module path takes the
`/v2` suffix that Go requires for major version 2.
- Python: restored `create_plan()` (same payload as the JavaScript SDK's
`createPlan`), which had been lost in a client refactor. Every call now goes
through one pooled `requests.Session`.
- JavaScript: includes the circuit breaker and resilience layer; fixed a
missing `CircuitState` import that stopped the package from compiling.
- Requests carry `X-SDK-Version` / `X-API-Version`. Deprecation policy:
[docs/deprecation-policy.md](docs/deprecation-policy.md).
1 change: 1 addition & 0 deletions sdks/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
Loading
Loading