|
1 | 1 | name: publish |
2 | | -env: |
3 | | - CI: true |
4 | 2 | on: |
5 | | - workflow_dispatch: |
6 | 3 | push: |
7 | 4 | branches: |
8 | 5 | - master |
9 | | - paths: |
10 | | - - "package.json" |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +env: |
| 12 | + CI: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + id-token: write |
| 17 | + packages: write |
11 | 18 |
|
12 | 19 | jobs: |
13 | | - build: |
| 20 | + check: |
14 | 21 | runs-on: ubuntu-latest |
15 | | - permissions: |
16 | | - contents: read |
17 | | - packages: write |
| 22 | + timeout-minutes: 5 |
| 23 | + outputs: |
| 24 | + can_publish: ${{ steps.can-publish.outputs.can_publish }} |
18 | 25 | steps: |
19 | | - - uses: actions/checkout@v6 |
| 26 | + - uses: actions/checkout@v4 |
20 | 27 | - name: Setup node |
21 | | - uses: actions/setup-node@v6 |
| 28 | + uses: actions/setup-node@v4 |
22 | 29 | with: |
23 | | - node-version-file: package.json |
| 30 | + node-version: 24 |
24 | 31 | registry-url: "https://registry.npmjs.org" |
25 | 32 | - uses: ./.github/actions/pnpm-install |
26 | 33 | - run: pnpm run build |
27 | | - - run: | |
28 | | - echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" > .npmrc |
29 | | - npx can-npm-publish --verbose && npm publish || echo "Does not publish" |
30 | | - env: |
31 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_NODE_AUTH_TOKEN }} |
| 34 | + - name: Check if can publish |
| 35 | + id: can-publish |
| 36 | + run: | |
| 37 | + npx can-npm-publish --verbose && echo "can_publish=true" >> $GITHUB_OUTPUT || echo "can_publish=false" >> $GITHUB_OUTPUT |
| 38 | + continue-on-error: true |
| 39 | + - uses: actions/upload-artifact@v4 |
| 40 | + with: |
| 41 | + name: dist |
| 42 | + path: dist |
| 43 | + retention-days: 1 |
| 44 | + |
| 45 | + publish-release: |
| 46 | + needs: check |
| 47 | + if: needs.check.outputs.can_publish == 'true' |
| 48 | + runs-on: ubuntu-latest |
| 49 | + timeout-minutes: 5 |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + - name: Setup node |
| 53 | + uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: 24 |
| 56 | + registry-url: "https://registry.npmjs.org" |
| 57 | + - uses: actions/download-artifact@v4 |
| 58 | + with: |
| 59 | + name: dist |
| 60 | + path: dist |
| 61 | + - name: Publish |
| 62 | + run: | |
| 63 | + npm publish |
| 64 | +
|
| 65 | + publish-alpha: |
| 66 | + needs: check |
| 67 | + if: needs.check.outputs.can_publish != 'true' |
| 68 | + runs-on: ubuntu-latest |
| 69 | + timeout-minutes: 5 |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + fetch-depth: 0 |
| 74 | + - name: Setup node |
| 75 | + uses: actions/setup-node@v4 |
| 76 | + with: |
| 77 | + node-version: 24 |
| 78 | + registry-url: "https://registry.npmjs.org" |
| 79 | + - uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + name: dist |
| 82 | + path: dist |
| 83 | + - name: Update version |
| 84 | + run: | |
| 85 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 86 | + git config --global user.name "github-actions[bot]" |
| 87 | + npm version prepatch --preid alpha-$(($(date +%s%N)/1000000))-$(git rev-parse --short HEAD) |
| 88 | + - name: Publish |
| 89 | + run: | |
| 90 | + npm publish --tag alpha |
0 commit comments