-
-
Notifications
You must be signed in to change notification settings - Fork 16
213 lines (180 loc) · 8.16 KB
/
split.yml
File metadata and controls
213 lines (180 loc) · 8.16 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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@v6.0.2
- name: Get package stability and determine version
working-directory: packages/${{ matrix.package }}
id: version
run: |
if [ -f composer.json ]; then
# Extract 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}-beta"
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
# Handle other Moox packages dependencies
sed -i 's/"moox\/\([^"]*\)":\s*"dev-main"/"moox\/\1": "${{ 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 "github-actions@github.com"
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/monorepo-split-github-action@v2.4.5
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: "bot@moox.org"
- 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 }}