-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
182 lines (159 loc) Β· 7.08 KB
/
release-package-splitter.yml
File metadata and controls
182 lines (159 loc) Β· 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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/**
templates/*/.github/**
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/saas-landing-page"]="hugo-theme-saas-landing-page"
["templates/dev-portfolio"]="hugo-theme-developer-portfolio"
["templates/markdown-slides"]="hugo-theme-markdown-slides"
["templates/starter"]="hugo-starter"
)
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.4"
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"