diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 1148bd0..bab7fad 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -1,4 +1,4 @@ -name: Auto Tag on Release PR Merge +name: Auto Tag & Publish on Release PR Merge on: pull_request: @@ -14,6 +14,8 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + outputs: + tag: ${{ steps.version.outputs.tag }} steps: - uses: actions/checkout@v4 @@ -27,3 +29,35 @@ jobs: run: | git tag "${{ steps.version.outputs.tag }}" git push origin "${{ steps.version.outputs.tag }}" + + publish: + needs: tag + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.tag.outputs.tag }} + + - uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - run: npm ci + - run: npm run build + - run: npm test + + - name: Determine npm tag + id: npm-tag + run: | + VERSION="${{ needs.tag.outputs.tag }}" + VERSION="${VERSION#v}" + if echo "$VERSION" | grep -qE '(alpha|beta|rc|next)'; then + echo "tag=next" >> "$GITHUB_OUTPUT" + else + echo "tag=latest" >> "$GITHUB_OUTPUT" + fi + + - run: npm publish --tag ${{ steps.npm-tag.outputs.tag }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 0a4a2c1..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Publish to npm - -on: - push: - tags: - - 'v*' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: '20' - registry-url: 'https://registry.npmjs.org' - - - run: npm ci - - run: npm run build - - run: npm test - - name: Determine npm tag - id: npm-tag - run: | - VERSION="${GITHUB_REF#refs/tags/v}" - if echo "$VERSION" | grep -qE '(alpha|beta|rc|next)'; then - echo "tag=next" >> "$GITHUB_OUTPUT" - else - echo "tag=latest" >> "$GITHUB_OUTPUT" - fi - - - run: npm publish --tag ${{ steps.npm-tag.outputs.tag }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}