Release to npm #33
Workflow file for this run
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: Release to npm | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (e.g., 0.8.6). If not provided, uses git tag.' | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure NPM for OIDC | |
| run: | | |
| cat > ~/.npmrc << EOF | |
| @crispthinking:registry=https://registry.npmjs.org/ | |
| registry=https://registry.npmjs.org/ | |
| EOF | |
| - name: Set version from tag or input | |
| run: | | |
| # Check if version was provided via workflow_dispatch input | |
| if [[ -n "${{ inputs.version }}" ]]; then | |
| INPUT_VERSION="${{ inputs.version }}" | |
| # Remove 'v' prefix if present | |
| VERSION=${INPUT_VERSION#v} | |
| echo "Using version from workflow input: $VERSION" | |
| elif [[ "$GITHUB_REF" == refs/tags/* ]]; then | |
| TAG_VERSION=${GITHUB_REF#refs/tags/} | |
| # Remove 'v' prefix if present | |
| VERSION=${TAG_VERSION#v} | |
| echo "Using version from git tag: $VERSION" | |
| else | |
| echo "No version provided and not building from a tag, using default version" | |
| VERSION="0.0.0" | |
| fi | |
| echo "Setting version to: $VERSION" | |
| npm --no-git-tag-version version "$VERSION" || exit 1 | |
| echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV | |
| - run: | | |
| echo "Publishing version: $PACKAGE_VERSION" | |
| cat package.json | grep -A2 '"name"' | |
| echo "Checking npm config:" | |
| npm config get registry | |
| npm config get //registry.npmjs.org/:_authToken | |
| npm ci | |
| npm run codegen | |
| npm run build:release | |
| npm publish --provenance --access public | |
| name: Build and Publish |