|
| 1 | +name: CI |
| 2 | +permissions: |
| 3 | + contents: write |
| 4 | + pull-requests: write |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + node-version: |
| 19 | + - 20.x |
| 20 | + - 22.x |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + - name: Use Node.js ${{ matrix.node-version }} |
| 24 | + uses: actions/setup-node@v6 |
| 25 | + with: |
| 26 | + node-version: ${{ matrix.node-version }} |
| 27 | + - run: npm ci |
| 28 | + - run: npm test |
| 29 | + - run: npm run build |
| 30 | + - name: Save build |
| 31 | + if: matrix.node-version == '20.x' |
| 32 | + uses: actions/upload-artifact@v5 |
| 33 | + with: |
| 34 | + name: build |
| 35 | + path: | |
| 36 | + . |
| 37 | + !node_modules |
| 38 | + retention-days: 1 |
| 39 | + |
| 40 | + npm-publish-build: |
| 41 | + needs: build |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/download-artifact@v6 |
| 45 | + with: |
| 46 | + name: build |
| 47 | + - uses: actions/setup-node@v6 |
| 48 | + with: |
| 49 | + node-version: 20.x |
| 50 | + - uses: rlespinasse/github-slug-action@v3.x |
| 51 | + - name: Append commit hash to package version |
| 52 | + run: 'sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json' |
| 53 | + - name: Disable pre- and post-publish actions |
| 54 | + run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json' |
| 55 | + - uses: JS-DevTools/npm-publish@v4.1.0 |
| 56 | + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' |
| 57 | + with: |
| 58 | + token: ${{ secrets.NPM_TOKEN }} |
| 59 | + tag: ${{ env.GITHUB_REF_SLUG }} |
| 60 | + |
| 61 | + npm-publish-latest: |
| 62 | + needs: [build, npm-publish-build] |
| 63 | + runs-on: ubuntu-latest |
| 64 | + if: github.ref == 'refs/heads/main' |
| 65 | + steps: |
| 66 | + - uses: actions/download-artifact@v6 |
| 67 | + with: |
| 68 | + name: build |
| 69 | + - uses: actions/setup-node@v6 |
| 70 | + with: |
| 71 | + node-version: 20.x |
| 72 | + - name: Disable pre- and post-publish actions |
| 73 | + run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json' |
| 74 | + - uses: JS-DevTools/npm-publish@v4.1.0 |
| 75 | + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' |
| 76 | + with: |
| 77 | + token: ${{ secrets.NPM_TOKEN }} |
| 78 | + tag: latest |
0 commit comments