Main v5 (#104) #25
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: CI/CD | |
| on: | |
| push: | |
| branches: [main, main-v5] | |
| pull_request: | |
| branches: [main, main-v5] | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| npm_tag: | |
| description: 'NPM tag (latest, beta, next)' | |
| required: true | |
| default: 'latest' | |
| type: choice | |
| options: | |
| - latest | |
| - beta | |
| - next | |
| env: | |
| NODE_VERSION: '20.x' | |
| jobs: | |
| build: | |
| name: Build & Verify | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build plugin | |
| run: npm run build | |
| - name: Verify plugin structure | |
| run: npm run verify | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| retention-days: 7 | |
| publish: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Verify version matches release tag | |
| if: github.event_name == 'release' | |
| run: | | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| RELEASE_TAG="${{ github.event.release.tag_name }}" | |
| RELEASE_VERSION="${RELEASE_TAG#v}" | |
| echo "[INFO] Package: $PKG_VERSION, Release: $RELEASE_VERSION" | |
| if [ "$PKG_VERSION" != "$RELEASE_VERSION" ]; then | |
| echo "[ERROR] Version mismatch!" | |
| exit 1 | |
| fi | |
| - name: Determine npm tag | |
| id: npm-tag | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "tag=${{ github.event.inputs.npm_tag }}" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| RELEASE_TAG="${{ github.event.release.tag_name }}" | |
| if [[ "$RELEASE_TAG" == *"-beta"* ]]; then | |
| echo "tag=beta" >> $GITHUB_OUTPUT | |
| elif [[ "$RELEASE_TAG" == *"-alpha"* ]]; then | |
| echo "tag=alpha" >> $GITHUB_OUTPUT | |
| elif [[ "$RELEASE_TAG" == *"-rc"* ]]; then | |
| echo "tag=next" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to NPM | |
| run: npm publish --access public --tag ${{ steps.npm-tag.outputs.tag }} | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Done | |
| run: | | |
| PKG_NAME=$(node -p "require('./package.json').name") | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| echo "[SUCCESS] Published $PKG_NAME@$PKG_VERSION" |