|
| 1 | +name: "Build and Publish on NPM" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +env: |
| 9 | + PR_TITLE: "Create Release" |
| 10 | + COMMIT_MSG: "chore: create new release" |
| 11 | + |
| 12 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + node-version: [22.x] |
| 21 | + |
| 22 | + permissions: |
| 23 | + contents: write # For pushing Git tags and creating releases |
| 24 | + pull-requests: write # For creating the changesets relese PR |
| 25 | + id-token: write # The OIDC ID token is used for authentication with JSR |
| 26 | + |
| 27 | + env: |
| 28 | + CI: "true" |
| 29 | + STORE_PATH: "" |
| 30 | + PNPM_VERSION: 10 |
| 31 | + RETENTION_DAYS: 2 |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Setup Node.js v${{ matrix.node-version }} |
| 38 | + uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: ${{ matrix.node-version }} |
| 41 | + |
| 42 | + - name: Setup pnpm |
| 43 | + uses: pnpm/action-setup@v4 |
| 44 | + with: |
| 45 | + version: ${{ env.PNPM_VERSION }} |
| 46 | + run_install: false |
| 47 | + |
| 48 | + - name: Get pnpm store directory |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 52 | +
|
| 53 | + - name: Setup pnpm cache |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: ${{ env.STORE_PATH }} |
| 57 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-pnpm-store- |
| 60 | +
|
| 61 | + - name: Install dependencies |
| 62 | + run: pnpm i |
| 63 | + |
| 64 | + - name: Build package |
| 65 | + run: pnpm build-all |
| 66 | + |
| 67 | + - name: Create artifact |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: dist |
| 71 | + path: dist/ |
| 72 | + retention-days: ${{ env.RETENTION_DAYS }} |
| 73 | + |
| 74 | + - name: Create release or publish package |
| 75 | + uses: changesets/action@v1 |
| 76 | + id: changesets |
| 77 | + with: |
| 78 | + publish: npm run publish-package |
| 79 | + commit: ${{ env.COMMIT_MSG }} |
| 80 | + title: ${{ env.PR_TITLE }} |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments