|
| 1 | +name: Publish to NPM |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Tests"] |
| 6 | + branches: [main] |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: github.event.workflow_run.conclusion == 'success' && !contains(github.event.workflow_run.head_commit.message, '[skip ci]') |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: "24" |
| 27 | + registry-url: "https://registry.npmjs.org" |
| 28 | + |
| 29 | + - name: Install pnpm |
| 30 | + uses: pnpm/action-setup@v4 |
| 31 | + with: |
| 32 | + version: 9 |
| 33 | + |
| 34 | + - name: Get pnpm store directory |
| 35 | + id: pnpm-cache |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 39 | +
|
| 40 | + - name: Setup pnpm cache |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
| 44 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-pnpm-store- |
| 47 | +
|
| 48 | + - name: Install dependencies |
| 49 | + run: pnpm install --frozen-lockfile |
| 50 | + |
| 51 | + - name: Configure Git |
| 52 | + run: | |
| 53 | + git config --global user.name "github-actions[bot]" |
| 54 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 55 | +
|
| 56 | + - name: Bump version and create tag |
| 57 | + run: | |
| 58 | + pnpm version patch --no-git-tag-version |
| 59 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 60 | + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 61 | + git add package.json |
| 62 | + git commit -m "chore: bump version to $NEW_VERSION [skip ci]" |
| 63 | + git tag "v$NEW_VERSION" |
| 64 | + git push origin main |
| 65 | + git push origin "v$NEW_VERSION" |
| 66 | +
|
| 67 | + - name: Build |
| 68 | + run: pnpm run build |
| 69 | + |
| 70 | + - name: Publish to NPM |
| 71 | + run: pnpm publish --no-git-checks --access public |
| 72 | + env: |
| 73 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments