Split & Release #13
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 & Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "New version" | |
| required: true | |
| packages: | |
| description: "Packages to deploy (JSON object with package info)" | |
| required: true | |
| user_token: | |
| description: "User's GitHub token (for release authorship)" | |
| required: false | |
| default: "" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.BOT }} | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package-list: ${{ steps.parse.outputs.package-list }} | |
| core-version: ${{ steps.parse.outputs.core-version }} | |
| is-prerelease: ${{ steps.parse.outputs.is-prerelease }} | |
| steps: | |
| - name: Parse packages | |
| id: parse | |
| run: | | |
| # Create a temp file to avoid shell injection | |
| cat > packages.json << 'EOF' | |
| ${{ github.event.inputs.packages }} | |
| EOF | |
| echo "Raw packages file:" | |
| cat packages.json | |
| # Validate JSON | |
| if ! jq empty packages.json 2>/dev/null; then | |
| echo "❌ Invalid JSON in 'packages' input" | |
| exit 1 | |
| fi | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [[ $VERSION =~ -(alpha|beta|rc) ]]; then | |
| echo "🚧 Detected prerelease version: $VERSION" | |
| IS_PRERELEASE=true | |
| else | |
| echo "✅ Detected stable version: $VERSION" | |
| IS_PRERELEASE=false | |
| fi | |
| echo "Parsed packages:" | |
| jq -r 'to_entries[] | "\(.key): Messages=[\(.value["release-message"] | join(", "))] Stability=\(.value["moox-stability"] // "dev")"' packages.json | |
| package_list=$(jq -r 'keys | @json' packages.json) | |
| echo "package-list=$package_list" >> $GITHUB_OUTPUT | |
| echo "core-version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
| echo "is-prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT | |
| echo "Package list for matrix: $package_list" | |
| echo "Is prerelease: $IS_PRERELEASE" | |
| split: | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.prepare.outputs.package-list != '[]' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJson(needs.prepare.outputs.package-list) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get package stability and determine version | |
| working-directory: packages/${{ matrix.package }} | |
| id: version | |
| run: | | |
| if [ -f composer.json ]; then | |
| # Extract moox-stability from composer.json | |
| STABILITY=$(jq -r '.extra."moox-stability" // "dev"' composer.json) | |
| BASE_VERSION="${{ needs.prepare.outputs.core-version }}" | |
| echo "Package: ${{ matrix.package }}" | |
| echo "Base version: $BASE_VERSION" | |
| echo "Stability: $STABILITY" | |
| # Determine final version based on stability | |
| if [ "$STABILITY" = "stable" ]; then | |
| FINAL_VERSION="$BASE_VERSION" | |
| IS_PRERELEASE=false | |
| echo "✅ Using stable version: $FINAL_VERSION" | |
| elif [ "$STABILITY" = "dev" ]; then | |
| FINAL_VERSION="${BASE_VERSION}-dev" | |
| IS_PRERELEASE=true | |
| echo "🔧 Using dev version: $FINAL_VERSION" | |
| else | |
| FINAL_VERSION="${BASE_VERSION}-${STABILITY}" | |
| IS_PRERELEASE=true | |
| echo "🚧 Using $STABILITY version: $FINAL_VERSION" | |
| fi | |
| echo "final-version=$FINAL_VERSION" >> $GITHUB_OUTPUT | |
| echo "is-prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT | |
| echo "stability=$STABILITY" >> $GITHUB_OUTPUT | |
| else | |
| echo "No composer.json found in ${{ matrix.package }}" | |
| echo "final-version=${{ needs.prepare.outputs.core-version }}" >> $GITHUB_OUTPUT | |
| echo "is-prerelease=false" >> $GITHUB_OUTPUT | |
| echo "stability=stable" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Replace core version in composer.json | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| if [ -f composer.json ]; then | |
| echo "Updating moox/core version in ${{ matrix.package }} to ${{ needs.prepare.outputs.core-version }}" | |
| # More robust sed pattern that handles different JSON formatting | |
| sed -i 's/"moox\/core":\s*"[^"]*"/"moox\/core": "${{ needs.prepare.outputs.core-version }}"/g' composer.json | |
| # Also handle self.version case | |
| sed -i 's/"moox\/core":\s*"self\.version"/"moox\/core": "${{ needs.prepare.outputs.core-version }}"/g' composer.json | |
| echo "Updated composer.json:" | |
| grep "moox/core" composer.json || echo "No moox/core dependency found" | |
| else | |
| echo "No composer.json found in ${{ matrix.package }}" | |
| fi | |
| - name: Commit changes | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| if [ -f composer.json ]; then | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git add composer.json | |
| git commit -m "Update moox/core dependency to ${{ needs.prepare.outputs.core-version }}" || echo "No changes to commit" | |
| fi | |
| - name: Split package to separate repository | |
| run: | | |
| PACKAGE="${{ matrix.package }}" | |
| VERSION="${{ steps.version.outputs.final-version }}" | |
| IS_PRERELEASE="${{ steps.version.outputs.is-prerelease }}" | |
| STABILITY="${{ steps.version.outputs.stability }}" | |
| echo "Package: $PACKAGE" | |
| echo "Version: $VERSION" | |
| echo "Is prerelease: $IS_PRERELEASE" | |
| echo "Stability: $STABILITY" | |
| # - name: Split package to separate repository | |
| # uses: symplify/[email protected] | |
| # env: | |
| # GITHUB_TOKEN: ${{ github.event.inputs.user_token != '' && github.event.inputs.user_token || secrets.BOT }} | |
| # with: | |
| # tag: "${{ steps.version.outputs.final-version }}" | |
| # package_directory: "packages/${{ matrix.package }}" | |
| # repository_organization: "mooxphp" | |
| # repository_name: "${{ matrix.package }}" | |
| # user_name: "Moox Bot" | |
| # user_email: "[email protected]" | |
| # - name: Create GitHub Release for split package | |
| # run: | | |
| # PACKAGE="${{ matrix.package }}" | |
| # VERSION="${{ steps.version.outputs.final-version }}" | |
| # IS_PRERELEASE="${{ steps.version.outputs.is-prerelease }}" | |
| # STABILITY="${{ steps.version.outputs.stability }}" | |
| # RELEASE_BODY=$(echo '${{ github.event.inputs.packages }}' | jq -r ".\"$PACKAGE\".\"release-message\" // [] | .[:10] | join(\"\\n\")") | |
| # echo "Package: $PACKAGE" | |
| # echo "Version: $VERSION" | |
| # echo "Stability: $STABILITY" | |
| # echo "Is prerelease: $IS_PRERELEASE" | |
| # echo "Release notes: $RELEASE_BODY" | |
| # # Only create release if stability is not 'dev' | |
| # if [ "$STABILITY" != "dev" ]; then | |
| # echo "✅ Creating release for $PACKAGE (stability: $STABILITY)" | |
| # # Wait for tag propagation | |
| # sleep 10 | |
| # if [ "$IS_PRERELEASE" = "true" ]; then | |
| # gh release create "$VERSION" \ | |
| # --repo "mooxphp/$PACKAGE" \ | |
| # --title "Release $VERSION" \ | |
| # --notes "$RELEASE_BODY" \ | |
| # --prerelease | |
| # else | |
| # gh release create "$VERSION" \ | |
| # --repo "mooxphp/$PACKAGE" \ | |
| # --title "Release $VERSION" \ | |
| # --notes "$RELEASE_BODY" | |
| # fi | |
| # echo "✅ Release created successfully" | |
| # else | |
| # echo "⏭️ Skipping release for $PACKAGE (stability: dev)" | |
| # echo " Package was split to repository but no release was created" | |
| # fi | |
| # env: | |
| # GH_TOKEN: ${{ github.event.inputs.user_token != '' && github.event.inputs.user_token || secrets.BOT }} |