|
| 1 | +name: Release & Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + release-please: |
| 17 | + if: github.event_name == 'push' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Release Please |
| 21 | + uses: google-github-actions/release-please-action@v4 |
| 22 | + with: |
| 23 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + command: manifest |
| 25 | + |
| 26 | + publish: |
| 27 | + if: github.event_name == 'release' |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup pnpm |
| 34 | + uses: pnpm/action-setup@v4 |
| 35 | + with: |
| 36 | + version: 9 |
| 37 | + |
| 38 | + - name: Setup Node.js |
| 39 | + uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: 18 |
| 42 | + cache: 'pnpm' |
| 43 | + registry-url: 'https://registry.npmjs.org' |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + run: pnpm install --frozen-lockfile |
| 47 | + |
| 48 | + - name: Build packages |
| 49 | + run: pnpm -r build |
| 50 | + |
| 51 | + - name: Determine package from tag |
| 52 | + id: which |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + TAG="${{ github.event.release.tag_name }}" |
| 56 | + echo "Release tag: $TAG" |
| 57 | + if [[ "$TAG" =~ ^loro-mirror-v([0-9]+\.[0-9]+\.[0-9]+) ]]; then |
| 58 | + echo "name=loro-mirror" >> "$GITHUB_OUTPUT" |
| 59 | + echo "dir=packages/core" >> "$GITHUB_OUTPUT" |
| 60 | + echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" |
| 61 | + elif [[ "$TAG" =~ ^loro-mirror-react-v([0-9]+\.[0-9]+\.[0-9]+) ]]; then |
| 62 | + echo "name=loro-mirror-react" >> "$GITHUB_OUTPUT" |
| 63 | + echo "dir=packages/react" >> "$GITHUB_OUTPUT" |
| 64 | + echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" |
| 65 | + elif [[ "$TAG" =~ ^loro-mirror-jotai-v([0-9]+\.[0-9]+\.[0-9]+) ]]; then |
| 66 | + echo "name=loro-mirror-jotai" >> "$GITHUB_OUTPUT" |
| 67 | + echo "dir=packages/jotai" >> "$GITHUB_OUTPUT" |
| 68 | + echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" |
| 69 | + else |
| 70 | + echo "Tag $TAG does not match known packages; skipping publish." |
| 71 | + echo "name=" >> "$GITHUB_OUTPUT" |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Publish to npm |
| 75 | + if: steps.which.outputs.name != '' |
| 76 | + env: |
| 77 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 78 | + run: | |
| 79 | + echo "Publishing ${{ steps.which.outputs.name }} at version ${{ steps.which.outputs.version }}" |
| 80 | + pnpm --filter "${{ steps.which.outputs.name }}" publish --no-git-checks |
0 commit comments