diff --git a/.github/workflows/subsplit-packages.yml b/.github/workflows/subsplit-packages.yml index 278300491..f973ef7c2 100644 --- a/.github/workflows/subsplit-packages.yml +++ b/.github/workflows/subsplit-packages.yml @@ -2,13 +2,10 @@ name: "Sub-split packages" on: push: - branches: [main] + branches: ["*"] tags: ["v*"] workflow_dispatch: -env: - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} - jobs: get_packages: name: Get packages @@ -24,10 +21,11 @@ jobs: - name: Get packages id: get_json - run: echo "::set-output name=json::$(bin/get-packages)" + run: echo "json=$(bin/get-packages)" >> $GITHUB_OUTPUT - name: Output packages run: echo "${{ steps.get_json.outputs.json }}" + outputs: matrix: ${{ steps.get_json.outputs.json }} @@ -41,34 +39,12 @@ jobs: package: ${{ fromJson(needs.get_packages.outputs.matrix) }} steps: - uses: actions/checkout@v4 - # no tag - - if: "!startsWith(github.ref, 'refs/tags/')" - uses: "symplify/monorepo-split-github-action@v2.3.0" - with: - # ↓ split "packages/console" directory - package_directory: "${{ matrix.package.directory }}" - - # ↓ into https://github.com/tempestphp/tempest-console repository - repository_organization: "${{ matrix.package.organization }}" - repository_name: "${{ matrix.package.repository }}" - - # ↓ the user signed under the split commit - user_name: "aidan-casey" - user_email: "aidan@caseyhouse.net" - - # with tag - - if: "startsWith(github.ref, 'refs/tags/')" - uses: "symplify/monorepo-split-github-action@v2.3.0" - with: - tag: ${GITHUB_REF#refs/tags/} - - # ↓ split "packages/console" directory - package_directory: "${{ matrix.package.directory }}" - # ↓ into https://github.com/tempestphp/tempest-console repository - repository_organization: "${{ matrix.package.organization }}" - repository_name: "${{ matrix.package.repository }}" + - name: Set up git-filter-repo + run: pip install git-filter-repo - # ↓ the user signed under the split commit - user_name: "aidan-casey" - user_email: "aidan@caseyhouse.net" + - name: Split Package + env: + SUBSPLIT_TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: + ./bin/split "${{ matrix.package.name }}" diff --git a/bin/split b/bin/split new file mode 100755 index 000000000..d9fae426a --- /dev/null +++ b/bin/split @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +PACKAGE_NAME=$1 +SUBSPLIT_DIR="${PACKAGE_NAME}_subsplit" + +# Clone our Tempest repository and jump into it. +git clone https://github.com/tempestphp/tempest-framework "$SUBSPLIT_DIR" +cd "$SUBSPLIT_DIR" + +# Get the current default branch of the Tempest repo. +DEFAULT_BRANCH=$(git branch --show-current) + +# Filter the history down to only the one package. +git filter-repo --subdirectory-filter "packages/${PACKAGE_NAME}" + +# Setup our remote repository we are splitting to. +git remote add origin "https://x-access-token:${SUBSPLIT_TOKEN}@github.com/tempestphp/tempest-${PACKAGE_NAME}.git" +git branch -m "$DEFAULT_BRANCH" + +# Push all branches + history to the repo. +git push --force --all origin + +# Push all releases / tags to the repo. +git push --force --tags origin + +# Cleanup +cd ../ +rm -rf "${SUBSPLIT_DIR}" \ No newline at end of file