Publish to npm #10
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: Publish to npm | |
| # Trigger when a new tag matching the pattern is created and pushed | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| scope: '@kispace-io' | |
| - name: Update npm | |
| run: npm install -g npm@latest | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG=${GITHUB_REF#refs/tags/} | |
| VERSION=${TAG#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "Extracted version: $VERSION from tag: $TAG" | |
| - name: Get tag message | |
| id: tag_message | |
| run: | | |
| TAG="${{ steps.version.outputs.tag }}" | |
| TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG" 2>/dev/null || echo "") | |
| if [ -z "$TAG_MESSAGE" ]; then | |
| TAG_MESSAGE="Release $TAG" | |
| fi | |
| echo "message<<EOF" >> $GITHUB_OUTPUT | |
| echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| run: | | |
| TAG="${{ steps.version.outputs.tag }}" | |
| BODY="${{ steps.tag_message.outputs.message }}" | |
| gh release create "$TAG" \ | |
| --title "Release $TAG" \ | |
| --notes "$BODY" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update package.json version (CI only, not committed) | |
| run: | | |
| npm version "${{ steps.version.outputs.version }}" --no-git-tag-version | |
| echo "Updated package.json version to ${{ steps.version.outputs.version }} (CI only, will not be committed)" | |
| - name: Build package | |
| run: npm run build | |
| - name: Run type check | |
| run: npm run type-check | |
| continue-on-error: true | |
| - name: Publish to npm | |
| run: npm publish --access public | |