name: 'Release: NPM Package' on: workflow_dispatch: inputs: releaseMode: description: 'Release mode' required: true type: choice default: 'prod' options: - 'prod' # Production release with @latest tag - 'rc' # Release candidate with @RC tag - 'dev' # Dev release with @dev tag releaseType: description: 'Semver release type (prod and rc)' required: false type: choice default: 'patch' options: - 'patch' # bug fixes - 'minor' # new features, backwards compatible - 'major' # breaking changes rc_name: description: 'RC identifier (rc mode only); minor with 1 gives X.Y+1.0-rc.1.0. Use a new value for each RC' required: false type: string default: '' runTests: description: 'Run tests before releasing' required: true type: choice default: 'true' options: - 'true' - 'false' ref: description: 'Branch name or SHA to release from (defaults to current branch)' required: false type: string default: '' # allow parallel releases of different modes, queue releases of the same mode concurrency: group: npm-release-${{ github.event.inputs.releaseMode }} cancel-in-progress: false permissions: contents: write pull-requests: read id-token: write # Required for OIDC authentication with npm trusted publishing jobs: integration-tests: if: ${{ github.event.inputs.runTests == 'true' }} uses: ./.github/workflows/pr.yml secrets: PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} with: ref: ${{ inputs.ref }} version-and-release: name: Release to NPM needs: integration-tests if: ${{ !cancelled() && (needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped') }} runs-on: ubuntu-latest environment: npm-publish steps: - name: Checkout uses: actions/checkout@v7 with: ref: ${{ inputs.ref != '' && inputs.ref || github.ref }} - name: Validate ref is a branch for prod releases if: inputs.releaseMode == 'prod' && inputs.ref != '' shell: bash run: | if ! git symbolic-ref --short HEAD > /dev/null 2>&1; then echo "Error: For prod releases, ref must be a valid branch name, not a SHA. Provided ref: ${{ inputs.ref }}. Current HEAD is detached." exit 1 fi - name: Setup uses: ./.github/actions/setup ##### VERSION BUMP ##### - name: 'Bump version for production release' if: inputs.releaseMode == 'prod' shell: bash id: version-bump-prod run: | npm version ${{ inputs.releaseType }} --no-git-tag-version newVersion=$(jq -r '.version' package.json) echo "version=$newVersion" >> $GITHUB_OUTPUT echo "Bumped version to $newVersion (prod release)" - name: 'Bump version for RC release' if: inputs.releaseMode == 'rc' shell: bash id: version-bump-rc run: | if [ -z "${{ inputs.rc_name }}" ]; then echo "Error: rc_name is required for RC releases" exit 1 fi if ! [[ "${{ inputs.rc_name }}" =~ ^[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*$ ]]; then echo "Error: rc_name must be dot-separated alphanumerics or hyphens, e.g. 1 or 2026-07" exit 1 fi # RC versions aren't committed back, so each run bumps from the last # stable release: pre targets the intended release version. npm version pre${{ inputs.releaseType }} --preid=rc.${{ inputs.rc_name }} --no-git-tag-version newVersion=$(jq -r '.version' package.json) echo "version=$newVersion" >> $GITHUB_OUTPUT echo "Bumped version to $newVersion (RC release)" - name: 'Bump version for dev release' if: inputs.releaseMode == 'dev' shell: bash id: version-bump-dev run: | currentVersion=$(jq -r '.version' package.json) timestamp=$(date +%Y%m%d%H%M%S) devVersion="$currentVersion-dev.$timestamp" # Update package.json jq --arg newVersion "$devVersion" '.version = $newVersion' package.json > package.tmp && mv package.tmp package.json # Update package-lock.json version jq --arg newVersion "$devVersion" '.version = $newVersion' package-lock.json > package-lock.tmp && mv package-lock.tmp package-lock.json # Update package-lock.json packages[""].version jq --arg newVersion "$devVersion" '.packages[""].version = $newVersion' package-lock.json > package-lock.tmp && mv package-lock.tmp package-lock.json # Create version.json file versionFile="src/version.json" jq --null-input --arg version "$devVersion" '{"name": "@pinecone-database/pinecone", "version": $version}' > "$versionFile" echo "version=$devVersion" >> $GITHUB_OUTPUT echo "version_file=$versionFile" >> $GITHUB_OUTPUT echo "Bumped version to $devVersion (dev release)" ##### COMMIT AND TAG VERSION CHANGES (prod) ##### - name: Configure git CLI if: github.event.inputs.releaseMode == 'prod' shell: bash run: | git config --global user.email "clients@pinecone.io" git config --global user.name "${{ github.actor }}" - name: Commit and tag version changes for prod if: github.event.inputs.releaseMode == 'prod' shell: bash run: | git add . # commit version.json changes newVersion="${{ steps.version-bump-prod.outputs.version }}" git commit -m "[skip ci] Publish release v$newVersion" git tag "v$newVersion" ##### NPM PUBLISH ##### - name: Publish to npm (prod) if: github.event.inputs.releaseMode == 'prod' run: npm publish --provenance --tag latest shell: bash - name: Publish to npm (RC) if: github.event.inputs.releaseMode == 'rc' run: npm publish --provenance --tag RC shell: bash - name: Publish to npm (dev) if: github.event.inputs.releaseMode == 'dev' run: npm publish --provenance --tag dev shell: bash ##### GIT PUSH COMMIT AND TAG (prod) ##### - name: Push commit and tag (prod) if: github.event.inputs.releaseMode == 'prod' shell: bash run: | newVersion="${{ steps.version-bump-prod.outputs.version }}" if [ -n "${{ github.event.inputs.ref }}" ]; then git push origin "${{ github.event.inputs.ref }}" --follow-tags git push origin "v$newVersion" else git push --follow-tags git push origin "v$newVersion" fi ##### CREATE DRAFT RELEASE (prod) ##### - name: Create draft release with notes (prod) if: github.event.inputs.releaseMode == 'prod' shell: bash env: GH_TOKEN: ${{ github.token }} run: | gh release create "v${{ steps.version-bump-prod.outputs.version }}" \ --draft \ --generate-notes \ --title "Release v${{ steps.version-bump-prod.outputs.version }}" build-and-publish-docs: name: Build and publish docs to sdk-docs needs: version-and-release if: ${{ github.event.inputs.releaseMode == 'prod' && needs.version-and-release.result == 'success' }} uses: ./.github/workflows/build-and-publish-docs.yml secrets: SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} with: ref: ${{ github.event.inputs.ref }}