name: SDK Release concurrency: sdk-release on: push: branches: [main] # Required for OIDC (Trusted Publishing) permissions: contents: read id-token: write jobs: detect-release: runs-on: ubuntu-latest outputs: version: ${{ steps.extract.outputs.version }} steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Check for release commit id: check run: | if git log --oneline -1 | grep -qP '^.*sdk\[release\]: \K.+'; then echo "release=true" >> $GITHUB_OUTPUT else echo "release=false" >> $GITHUB_OUTPUT fi - name: Extract version from commit message if: steps.check.outputs.release == 'true' id: extract run: | version=$(git log --oneline -1 | grep -oP 'sdk\[release\]: \K\S+') echo "Extracted version: $version" echo "version=$version" >> $GITHUB_OUTPUT tag: needs: detect-release if: needs.detect-release.outputs.version != '' runs-on: ubuntu-latest permissions: contents: write steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Create annotated tag run: | version="${{ needs.detect-release.outputs.version }}" git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git tag -a "sdk/$version" -m "SDK Release $version" git push origin "sdk/$version" publish-python: needs: [detect-release, tag] if: needs.detect-release.outputs.version != '' runs-on: ubuntu-latest environment: sdk-release steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: "sdk/${{ needs.detect-release.outputs.version }}" fetch-depth: 0 - name: Install uv uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2 - name: Build Python SDK working-directory: sdk/python run: uv build --no-sources - name: Publish to PyPI (Trusted Publishing) working-directory: sdk/python # uv publish automatically uses OIDC in GitHub Actions with id-token: write run: uv publish publish-typescript: needs: [detect-release, tag] if: needs.detect-release.outputs.version != '' runs-on: ubuntu-latest environment: sdk-release steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: "sdk/${{ needs.detect-release.outputs.version }}" fetch-depth: 0 - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 with: package_json_file: sdk/typescript/package.json - name: Setup Node.js uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: .nvmrc registry-url: "https://registry.npmjs.org" cache: "pnpm" cache-dependency-path: "sdk/typescript/pnpm-lock.yaml" - name: Install dependencies working-directory: sdk/typescript run: pnpm install --frozen-lockfile - name: Build TypeScript SDK working-directory: sdk/typescript run: pnpm run build - name: Select npm dist-tag id: npm_tag working-directory: sdk/typescript run: | version=$(node -p "require('./package.json').version") if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+- ]]; then tag=next else tag=latest fi echo "Publishing @polar-sh/sdk@$version with dist-tag '$tag'" echo "tag=$tag" >> "$GITHUB_OUTPUT" - name: Publish to npm (Trusted Publishing) working-directory: sdk/typescript run: npm publish --tag "${{ steps.npm_tag.outputs.tag }}" update-sdk-dependents: needs: [detect-release, publish-typescript] if: needs.detect-release.outputs.version != '' && !contains(needs.detect-release.outputs.version, '-') runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: write pull-requests: write defaults: run: working-directory: clients steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: main - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 with: package_json_file: clients/package.json - name: Setup Node.js uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version-file: .nvmrc cache: "pnpm" cache-dependency-path: "clients/pnpm-lock.yaml" - name: Update adapter and CLI SDK dependencies and add patch changeset env: RELEASE_VERSION: ${{ needs.detect-release.outputs.version }} run: node scripts/update-sdk-dependencies.mjs "$RELEASE_VERSION" - name: Wait for the SDK release to propagate on npm env: RELEASE_VERSION: ${{ needs.detect-release.outputs.version }} run: | deadline=$((SECONDS + 300)) attempt=1 while true; do if npm view "@polar-sh/sdk@$RELEASE_VERSION" version >/dev/null 2>&1; then echo "@polar-sh/sdk@$RELEASE_VERSION is available on npm" exit 0 fi if [ "$SECONDS" -ge "$deadline" ]; then break fi echo "Attempt $attempt: @polar-sh/sdk@$RELEASE_VERSION not yet available, retrying in 15s" sleep 15 attempt=$((attempt + 1)) done echo "::error::@polar-sh/sdk@$RELEASE_VERSION did not appear on npm within 5 minutes" exit 1 - name: Update lockfile run: pnpm install --lockfile-only --ignore-scripts --no-frozen-lockfile - name: Create SDK dependency update pull request env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} RELEASE_VERSION: ${{ needs.detect-release.outputs.version }} run: | git add adapters/*/package.json packages/cli/package.json pnpm-lock.yaml .changeset/ if git diff --cached --quiet; then exit 0 fi branch="sdk/dependents-$RELEASE_VERSION" title="chore: update adapters and CLI to SDK $RELEASE_VERSION" remote_sha=$(git ls-remote --heads origin "refs/heads/$branch" | cut -f1) git switch -c "$branch" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git commit -m "$title" git push --force-with-lease="refs/heads/$branch:$remote_sha" origin "HEAD:refs/heads/$branch" existing_pr=$(gh pr list --head "$branch" --base main --state open --json number --jq '.[0].number // empty') if [ -n "$existing_pr" ]; then echo "Updated PR #$existing_pr" exit 0 fi body_file="$RUNNER_TEMP/sdk-dependency-update-pr.md" printf '%s\n' \ "Update all adapters and the CLI to @polar-sh/sdk@$RELEASE_VERSION after its successful npm release." \ "" \ "Includes updated SDK dependencies and peer dependencies, the pnpm lockfile, and a patch changeset for every adapter and polar-cli." \ > "$body_file" gh pr create --base main --head "$branch" --draft --title "$title" --body-file "$body_file" create-github-release: needs: [detect-release, publish-python, publish-typescript] if: needs.detect-release.outputs.version != '' && !contains(needs.detect-release.outputs.version, '-') runs-on: ubuntu-latest permissions: contents: write steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: "sdk/${{ needs.detect-release.outputs.version }}" - name: Install uv uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2 - name: Extract release notes working-directory: sdk/generator env: RELEASE_VERSION: ${{ needs.detect-release.outputs.version }} run: uv run --locked keepachangelog show "$RELEASE_VERSION" ../CHANGELOG.md > "$RUNNER_TEMP/sdk-release-notes.md" - name: Create GitHub Release uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 with: tag_name: "sdk/${{ needs.detect-release.outputs.version }}" name: "SDK ${{ needs.detect-release.outputs.version }}" body_path: ${{ runner.temp }}/sdk-release-notes.md