Publish Package to npm #62
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Package to npm | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: write-all | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - run: bun i | |
| - run: bun test --coverage | |
| - run: bun lint | |
| - run: bun run build | |
| changepacks: | |
| name: changepacks | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| needs: | |
| - check | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: changepacks/action@main | |
| id: changepacks | |
| outputs: | |
| changepacks: ${{ steps.changepacks.outputs.changepacks }} | |
| schedule-check: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| outputs: | |
| changed: ${{ steps.new-size.outputs.new != steps.prev-size.outputs.prev }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: index.d.ts size | |
| run: | | |
| echo "prev=$(wc -c src/index.d.ts | awk '{print $1}')" >> $GITHUB_OUTPUT | |
| id: prev-size | |
| - run: bun i | |
| - run: bun test --coverage | |
| - run: bun lint | |
| - run: bun run build | |
| - name: index.d.ts size | |
| run: | | |
| echo "new=$(wc -c src/index.d.ts | awk '{print $1}')" >> $GITHUB_OUTPUT | |
| id: new-size | |
| - name: Update Package | |
| if: steps.new-size.outputs.new != steps.prev-size.outputs.prev | |
| run: | | |
| bunx @changepacks/cli -y --update-type patch -m "chore: update package version" | |
| git config --global user.email "bot@github.com" | |
| git config --global user.name "github-actions[bot]" | |
| git add . | |
| git commit -m "chore: update package version" | |
| git push | |
| # Create pr | |
| - uses: changepacks/action@main | |
| if: steps.new-size.outputs.new != steps.prev-size.outputs.prev | |
| - name: Merge PR | |
| if: steps.new-size.outputs.new != steps.prev-size.outputs.prev | |
| run: | | |
| PR_NUMBER=$(gh pr list --head changepacks/main --base main --json number --jq '.[0].number') | |
| if [ -n "$PR_NUMBER" ]; then | |
| gh pr merge $PR_NUMBER --merge --delete-branch | |
| else | |
| echo "No PR found for changepacks/main branch" | |
| exit 1 | |
| fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| publish: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - changepacks | |
| - schedule-check | |
| if: | | |
| always() && | |
| ( | |
| (needs.schedule-check.result == 'success' && needs.schedule-check.outputs.changed == 'true') || | |
| (needs.changepacks.result == 'success' && contains(needs.changepacks.outputs.changepacks, 'package.json')) | |
| ) | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - run: bun i | |
| - run: bun test --coverage --coverage-reporter=lcov | |
| - run: bun run build | |
| - name: Upload to codecov.io | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| fail_ci_if_error: true | |
| files: ./coverage/lcov.info | |
| # npm (not bun) does the actual publish: bun cannot perform the npm OIDC | |
| # token exchange. Trusted Publishing needs npm >= 11.5.1. | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Ensure npm >= 11.5.1 (OIDC Trusted Publishing) | |
| run: npm install -g npm@latest | |
| - run: npm publish --access public --ignore-scripts |