mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-06 04:14:25 +00:00
188 lines
7.3 KiB
YAML
188 lines
7.3 KiB
YAML
name: "Release - Package Splitter"
|
|
run-name: ${{ github.workflow }} - ${{ github.ref_name }}
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
force_all:
|
|
description: "Force split/push of all template repos, even if no changes detected"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
# IMPORTANT: workflows below must match the upstream workflow's `name:` exactly
|
|
workflow_run:
|
|
workflows:
|
|
- Release - HugoBlox Modules
|
|
types:
|
|
- completed
|
|
|
|
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@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- id: changed
|
|
# Only run change detection for push events
|
|
if: ${{ github.event_name == 'push' }}
|
|
uses: tj-actions/changed-files@v47
|
|
with:
|
|
files: |
|
|
templates/academic-cv/**
|
|
templates/resume/**
|
|
templates/blog/**
|
|
templates/documentation/**
|
|
templates/link-in-bio/**
|
|
templates/landing-page/**
|
|
templates/dev-portfolio/**
|
|
templates/markdown-slides/**
|
|
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 || '' }}
|
|
FORCE_ALL: ${{ github.event.inputs.force_all || 'false' }}
|
|
run: |
|
|
# Define the full mapping
|
|
declare -A STARTER_MAP=(
|
|
["templates/academic-cv"]="hugo-theme-academic-cv"
|
|
["templates/resume"]="hugo-theme-resume"
|
|
["templates/data-science-blog"]="hugo-theme-data-science-blog"
|
|
["templates/documentation"]="hugo-theme-documentation"
|
|
["templates/link-in-bio"]="hugo-theme-link-in-bio"
|
|
["templates/startup-landing-page"]="hugo-theme-startup-landing-page"
|
|
["templates/dev-portfolio"]="hugo-theme-developer-portfolio"
|
|
["templates/markdown-slides"]="hugo-theme-markdown-slides"
|
|
)
|
|
|
|
build_full_matrix() {
|
|
local JSON="[" FIRST=true
|
|
local ROOTS=()
|
|
|
|
# Sort keys to keep output stable across runs
|
|
readarray -t ROOTS < <(printf "%s\n" "${!STARTER_MAP[@]}" | sort)
|
|
|
|
for ROOT in "${ROOTS[@]}"; do
|
|
if [ "$FIRST" = true ]; then
|
|
FIRST=false
|
|
else
|
|
JSON+=","
|
|
fi
|
|
JSON+="{\"local_path\":\"$ROOT\",\"split_repository\":\"${STARTER_MAP[$ROOT]}\"}"
|
|
done
|
|
|
|
JSON+="]"
|
|
echo "$JSON"
|
|
}
|
|
|
|
# Manual override to force splitting all templates
|
|
if [ "$FORCE_ALL" = "true" ]; then
|
|
echo "Force mode enabled; splitting all templates"
|
|
FULL_MATRIX=$(build_full_matrix)
|
|
echo "matrix=$FULL_MATRIX" >> "$GITHUB_OUTPUT"
|
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
# For non-push events, always use full matrix derived from the map above
|
|
if [ "${{ github.event_name }}" != "push" ]; then
|
|
echo "Using full matrix for ${{ github.event_name }} event"
|
|
FULL_MATRIX=$(build_full_matrix)
|
|
echo "matrix=$FULL_MATRIX" >> "$GITHUB_OUTPUT"
|
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Detected template directories: $CHANGED_DIRS"
|
|
|
|
# If no changes, set empty matrix
|
|
if [ -z "$CHANGED_DIRS" ]; then
|
|
echo "No templates changed"
|
|
echo "matrix=[]" >> "$GITHUB_OUTPUT"
|
|
echo "has_changes=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
# Build JSON array for changed templates
|
|
JSON="["
|
|
FIRST=true
|
|
# tj-actions outputs space-separated list
|
|
for DIR in $CHANGED_DIRS; do
|
|
# Normalize potential trailing slash
|
|
DIR="${DIR%/}"
|
|
|
|
# Collapse to the template root (first two path segments), e.g. templates/landing-page
|
|
IFS='/' read -r SEG1 SEG2 _ <<< "$DIR"
|
|
if [[ -n "$SEG1" && -n "$SEG2" ]]; then
|
|
ROOT="$SEG1/$SEG2"
|
|
else
|
|
ROOT="$DIR"
|
|
fi
|
|
|
|
# Only process if it's a known starter
|
|
if [[ -n "${STARTER_MAP[$ROOT]}" ]]; then
|
|
if [ "$FIRST" = true ]; then
|
|
FIRST=false
|
|
else
|
|
JSON+=","
|
|
fi
|
|
JSON+="{\"local_path\":\"$ROOT\",\"split_repository\":\"${STARTER_MAP[$ROOT]}\"}"
|
|
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:
|
|
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:
|
|
package: ${{ fromJson(needs.determine_changed.outputs.matrix) }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# step if no tag is pushed
|
|
- if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
uses: "symplify/monorepo-split-github-action@v2.4.0"
|
|
with:
|
|
package_directory: "${{ matrix.package.local_path }}"
|
|
repository_organization: "HugoBlox"
|
|
repository_name: "${{ matrix.package.split_repository }}"
|
|
user_name: "Splitter Bot"
|
|
user_email: "no.reply@hugoblox.com"
|