Split & Publish #6
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: Split & Publish | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to publish (e.g., v0.7.0)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| # ==================== | |
| # Validate & Extract version | |
| # ==================== | |
| prepare: | |
| name: Prepare Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| tag: ${{ steps.version.outputs.tag }} | |
| steps: | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ github.event.inputs.tag }}" | |
| elif [ "${{ github.event_name }}" = "release" ]; then | |
| TAG="${{ github.event.release.tag_name }}" | |
| else | |
| TAG=${GITHUB_REF#refs/tags/} | |
| fi | |
| VERSION=${TAG#v} | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | |
| echo "Version: ${VERSION} (tag: ${TAG})" | |
| # ==================== | |
| # Build & Test | |
| # ==================== | |
| validate: | |
| name: Build & Test | |
| runs-on: ubuntu-latest | |
| needs: prepare | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| extensions: curl, json, mbstring | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run tests | |
| run: composer test | |
| - name: Run PHPStan | |
| run: composer phpstan | |
| - name: Check code style | |
| run: composer cs | |
| # ==================== | |
| # Split monorepo & push to read-only repos | |
| # ==================== | |
| split: | |
| name: Split & Publish | |
| runs-on: ubuntu-latest | |
| needs: [prepare, validate] | |
| strategy: | |
| matrix: | |
| include: | |
| - package: logtide | |
| directory: packages/logtide | |
| target: logtide-dev/logtide-php-sdk | |
| - package: logtide-laravel | |
| directory: packages/logtide-laravel | |
| target: logtide-dev/logtide-laravel | |
| - package: logtide-symfony | |
| directory: packages/logtide-symfony | |
| target: logtide-dev/logtide-symfony | |
| - package: logtide-slim | |
| directory: packages/logtide-slim | |
| target: logtide-dev/logtide-slim | |
| - package: logtide-wordpress | |
| directory: packages/logtide-wordpress | |
| target: logtide-dev/logtide-wordpress | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install splitsh-lite | |
| run: | | |
| curl -sL https://github.com/splitsh/lite/releases/download/v1.0.1/lite_linux_amd64.tar.gz | tar xz | |
| sudo mv splitsh-lite /usr/local/bin/splitsh-lite | |
| chmod +x /usr/local/bin/splitsh-lite | |
| - name: Split ${{ matrix.package }} | |
| id: split | |
| run: | | |
| SHA=$(splitsh-lite --prefix=${{ matrix.directory }}) | |
| echo "sha=${SHA}" >> $GITHUB_OUTPUT | |
| echo "Split SHA: ${SHA}" | |
| - name: Verify token | |
| env: | |
| SPLIT_TOKEN: ${{ secrets.SPLIT_TOKEN }} | |
| run: | | |
| if [ -z "${SPLIT_TOKEN}" ]; then | |
| echo "::error::SPLIT_TOKEN secret is empty or not set!" | |
| exit 1 | |
| fi | |
| echo "SPLIT_TOKEN is set (length: ${#SPLIT_TOKEN})" | |
| - name: Push to ${{ matrix.target }} | |
| env: | |
| SPLIT_TOKEN: ${{ secrets.SPLIT_TOKEN }} | |
| run: | | |
| TAG="${{ needs.prepare.outputs.tag }}" | |
| SHA="${{ steps.split.outputs.sha }}" | |
| TARGET="https://x-access-token:${SPLIT_TOKEN}@github.com/${{ matrix.target }}.git" | |
| # Push split branch to main | |
| git push "${TARGET}" "${SHA}:refs/heads/main" --force | |
| # Push the tag (using git's low-level update-ref to avoid local tag issues) | |
| git push "${TARGET}" "${SHA}:refs/tags/${TAG}" --force | |
| echo "Pushed ${{ matrix.package }} -> ${{ matrix.target }} @ ${TAG}" | |
| # ==================== | |
| # Summary | |
| # ==================== | |
| summary: | |
| name: Publish Summary | |
| runs-on: ubuntu-latest | |
| needs: [prepare, split] | |
| if: always() && needs.split.result == 'success' | |
| steps: | |
| - name: Create publish summary | |
| run: | | |
| VERSION="${{ needs.prepare.outputs.version }}" | |
| TAG="${{ needs.prepare.outputs.tag }}" | |
| echo "## Packages Published (${TAG})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Package | Split Repo | Install |" >> $GITHUB_STEP_SUMMARY | |
| echo "|---------|------------|---------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| logtide/logtide | [logtide-php-sdk](https://github.com/logtide-dev/logtide-php-sdk) | \`composer require logtide/logtide:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| logtide/logtide-laravel | [logtide-laravel](https://github.com/logtide-dev/logtide-laravel) | \`composer require logtide/logtide-laravel:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| logtide/logtide-symfony | [logtide-symfony](https://github.com/logtide-dev/logtide-symfony) | \`composer require logtide/logtide-symfony:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| logtide/logtide-slim | [logtide-slim](https://github.com/logtide-dev/logtide-slim) | \`composer require logtide/logtide-slim:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| logtide/logtide-wordpress | [logtide-wordpress](https://github.com/logtide-dev/logtide-wordpress) | \`composer require logtide/logtide-wordpress:${VERSION}\` |" >> $GITHUB_STEP_SUMMARY |