diff --git a/.github/workflows/release-package-splitter.yml b/.github/workflows/release-package-splitter.yml index f3cf5fe6..30d8d5d2 100644 --- a/.github/workflows/release-package-splitter.yml +++ b/.github/workflows/release-package-splitter.yml @@ -17,43 +17,119 @@ env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} jobs: + determine_changed: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + has_changes: ${{ steps.set-matrix.outputs.has_changes }} + + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - id: changed + # Only run change detection for push events + if: ${{ github.event_name == 'push' }} + uses: tj-actions/changed-files@v44 + with: + files: | + starters/academic-cv/** + starters/resume/** + starters/blog/** + starters/documentation/** + starters/link-in-bio/** + starters/landing-page/** + dir_names: true + dir_names_max_depth: 2 + dir_names_exclude_current_dir: true + + # Build dynamic matrix + - name: Build dynamic matrix + id: set-matrix + env: + CHANGED_DIRS: ${{ steps.changed.outputs.dir_names || '' }} + run: | + # Define the full mapping + declare -A STARTER_MAP=( + ["starters/academic-cv"]="theme-academic-cv" + ["starters/resume"]="theme-resume" + ["starters/blog"]="theme-blog" + ["starters/documentation"]="theme-documentation" + ["starters/link-in-bio"]="theme-link-in-bio" + ["starters/landing-page"]="theme-landing-page" + ) + + # For non-push events, always use full matrix + if [ "${{ github.event_name }}" != "push" ]; then + echo "Using full matrix for ${{ github.event_name }} event" + echo "matrix=[{\"local_path\":\"starters/academic-cv\",\"split_repository\":\"theme-academic-cv\"},{\"local_path\":\"starters/resume\",\"split_repository\":\"theme-resume\"},{\"local_path\":\"starters/blog\",\"split_repository\":\"theme-blog\"},{\"local_path\":\"starters/documentation\",\"split_repository\":\"theme-documentation\"},{\"local_path\":\"starters/link-in-bio\",\"split_repository\":\"theme-link-in-bio\"},{\"local_path\":\"starters/landing-page\",\"split_repository\":\"theme-landing-page\"}]" >> "$GITHUB_OUTPUT" + echo "has_changes=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + + echo "Detected starter directories: $CHANGED_DIRS" + + # If no changes, set empty matrix + if [ -z "$CHANGED_DIRS" ]; then + echo "No starters changed" + echo "matrix=[]" >> "$GITHUB_OUTPUT" + echo "has_changes=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + # Build JSON array for changed starters + JSON="[" + FIRST=true + # tj-actions outputs space-separated list + for DIR in $CHANGED_DIRS; do + # Only process if it's a known starter + if [[ -n "${STARTER_MAP[$DIR]}" ]]; then + if [ "$FIRST" = true ]; then + FIRST=false + else + JSON+="," + fi + JSON+="{\"local_path\":\"$DIR\",\"split_repository\":\"${STARTER_MAP[$DIR]}\"}" + fi + done + JSON+="]" + + # Check if we actually added any starters + if [ "$JSON" = "[]" ]; then + echo "No valid starters found in changed directories" + echo "matrix=[]" >> "$GITHUB_OUTPUT" + echo "has_changes=false" >> "$GITHUB_OUTPUT" + else + echo "matrix=$JSON" >> "$GITHUB_OUTPUT" + echo "has_changes=true" >> "$GITHUB_OUTPUT" + fi + packages_split: - # Run normally for push/workflow_dispatch; for workflow_run only run on success - if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} + needs: determine_changed + # Run when: + # • Event is not workflow_run OR upstream workflow succeeded. + # • Event is not push OR at least one starter changed. + if: ${{ (github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success') && needs.determine_changed.outputs.has_changes == 'true' }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - # define package to repository map - package: - - local_path: "starters/academic-cv" - split_repository: "theme-academic-cv" - - local_path: "starters/resume" - split_repository: "theme-resume" - - local_path: "starters/blog" - split_repository: "theme-blog" - - local_path: "starters/documentation" - split_repository: "theme-documentation" - - local_path: "starters/link-in-bio" - split_repository: "theme-link-in-bio" - - local_path: "starters/landing-page" - split_repository: "theme-landing-page" + package: ${{ fromJson(needs.determine_changed.outputs.matrix) }} steps: - uses: actions/checkout@v5 + with: + fetch-depth: 0 # step if no tag is pushed - if: ${{ !startsWith(github.ref, 'refs/tags/') }} uses: "symplify/monorepo-split-github-action@v2.3.0" with: - # ↓ split "packages/" directory package_directory: "${{ matrix.package.local_path }}" - - # ↓ into https://github.com/HugoBlox/ repository repository_organization: "HugoBlox" repository_name: "${{ matrix.package.split_repository }}" - - # ↓ the user signed under the split commit user_name: "Splitter Bot" user_email: "no.reply@hugoblox.com"