Publish SDK to NPM and GitHub Package Registry #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish SDK to NPM | |
| on: | |
| release: | |
| types: [published, edited] | |
| workflow_dispatch: {} | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| publish: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }} | |
| environment: npm | |
| steps: | |
| - name: Checkout branch | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: "https://registry.npmjs.org/" | |
| - name: Upgrade npm for OIDC support | |
| run: npm install -g npm@latest | |
| - name: Install dependencies | |
| run: npm install | |
| - id: latest-release | |
| name: Export latest release git tag | |
| run: | | |
| echo "latest-release-tag=$(curl -qsSL \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \ | |
| | jq -r .tag_name)" >> $GITHUB_OUTPUT | |
| - id: npm-tag | |
| name: Determine NPM tag | |
| env: | |
| GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| run: | | |
| VERSION=$(jq -r '.version' package.json) | |
| LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}" | |
| if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then | |
| RELEASE_TAG=${GITHUB_REF#refs/tags/} | |
| else | |
| RELEASE_TAG=$GITHUB_RELEASE_TAG | |
| fi | |
| if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then | |
| echo "npm-tag=latest" >> "$GITHUB_OUTPUT" | |
| elif [[ "$VERSION" == *"-beta"* ]]; then | |
| echo "npm-tag=beta" >> "$GITHUB_OUTPUT" | |
| elif [[ "$VERSION" == *"-alpha"* ]]; then | |
| echo "npm-tag=alpha" >> "$GITHUB_OUTPUT" | |
| elif [[ "$VERSION" == *"-rc"* ]]; then | |
| echo "npm-tag=rc" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT" | |
| fi | |
| - id: release | |
| name: Test, build and publish to npm | |
| env: | |
| BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | |
| BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | |
| run: | | |
| if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then | |
| npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --dry-run | |
| else | |
| npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --provenance | |
| fi | |
| # - name: Report results to Jellyfish | |
| # uses: optimizely/jellyfish-deployment-reporter-action@main | |
| # if: ${{ always() && github.event_name == 'release' && (steps.release.outcome == 'success' || steps.release.outcome == 'failure') }} | |
| # with: | |
| # jellyfish_api_token: ${{ secrets.JELLYFISH_API_TOKEN }} | |
| # is_successful: ${{ steps.release.outcome == 'success' }} |