|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + # ✅ Only run in your main repository (prevent auto-release from forks) |
| 11 | + if: ${{ github.repository_owner == 'Ohh-889' }} |
| 12 | + name: Version & Publish Changed Packages |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | + steps: |
| 19 | + # 🧩 Checkout full repository (with history) |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + # 🧰 Setup Node + pnpm environment |
| 26 | + - name: Setup Node.js 20 |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: 20 |
| 30 | + cache: "pnpm" |
| 31 | + |
| 32 | + - name: Setup pnpm |
| 33 | + uses: pnpm/action-setup@v4 |
| 34 | + with: |
| 35 | + version: 9.0.6 |
| 36 | + |
| 37 | + # 📦 Install dependencies |
| 38 | + - name: Install dependencies |
| 39 | + run: pnpm install --frozen-lockfile |
| 40 | + |
| 41 | + # 🔍 Detect which packages will be published |
| 42 | + - name: Detect changed packages |
| 43 | + id: changed |
| 44 | + run: | |
| 45 | + CHANGED=$(pnpm changeset status --json | jq -r '.changesets[].releases[].name' | sort | uniq) |
| 46 | + echo "changed=$CHANGED" >> $GITHUB_OUTPUT |
| 47 | + shell: bash |
| 48 | + |
| 49 | + # 🏗️ Build only changed packages (and their dependencies) |
| 50 | + - name: Build changed packages |
| 51 | + if: steps.changed.outputs.changed != '' |
| 52 | + run: | |
| 53 | + for pkg in ${{ steps.changed.outputs.changed }}; do |
| 54 | + echo "🏗️ Building $pkg..." |
| 55 | + pnpm install --filter "./packages/$pkg..." --frozen-lockfile |
| 56 | + pnpm build --filter "./packages/$pkg" |
| 57 | + done |
| 58 | + shell: bash |
| 59 | + |
| 60 | + # 🏷️ Create version PR or publish to npm |
| 61 | + - name: Create Version PR or Publish to npm |
| 62 | + id: changesets |
| 63 | + uses: changesets/action@v1 |
| 64 | + with: |
| 65 | + commit: "chore(release): version packages" |
| 66 | + title: "chore(release): version packages" |
| 67 | + version: node .github/changeset-version.js |
| 68 | + publish: pnpm changeset publish |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 72 | + NODE_ENV: "production" |
0 commit comments