|
| 1 | +name: Release new NPM version |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: changeset-${{ github.head_ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + npm: |
| 15 | + name: Changeset release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: write # to be able to publish a GitHub release |
| 19 | + pull-requests: write # to be able to comment on released pull requests |
| 20 | + id-token: write # to enable use of OIDC for npm provenance |
| 21 | + steps: |
| 22 | + - name: Checkout the repo |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 1 |
| 26 | + |
| 27 | + - name: Setup Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: 16.16 |
| 31 | + cache: 'yarn' |
| 32 | + cache-dependency-path: '**/yarn.lock' |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: yarn install --no-progress --ignore-engines |
| 36 | + |
| 37 | + - name: Check for changesets |
| 38 | + id: check_changesets |
| 39 | + run: | |
| 40 | + if [ -z "$(ls -A .changeset)" ]; then |
| 41 | + echo "No changesets found. Exiting." |
| 42 | + echo "changesets_found=false" >> $GITHUB_ENV |
| 43 | + exit 0 |
| 44 | + else |
| 45 | + echo "changesets_found=true" >> $GITHUB_ENV |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Update package version and remove changesets |
| 49 | + if: env.changesets_found == 'true' |
| 50 | + run: npx changeset version |
| 51 | + |
| 52 | + - name: Commit and push changes |
| 53 | + if: env.changesets_found == 'true' |
| 54 | + run: | |
| 55 | + git config --global user.name 'github-actions[bot]' |
| 56 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 57 | + git add package.json .changeset |
| 58 | + git commit -m "Update package version & delete changesets" |
| 59 | + git push |
| 60 | +
|
| 61 | + - name: Publish to NPM |
| 62 | + if: env.changesets_found == 'true' |
| 63 | + id: changesets |
| 64 | + uses: changesets/action@v1 |
| 65 | + with: |
| 66 | + publish: npx changeset publish |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 70 | + NPM_CONFIG_PROVENANCE: true |
0 commit comments