build-and-publish-npm.yml 2.0 KB

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