Skip to content

Commit b4d1831

Browse files
committed
Add reverse sync workflow to standalone repos
1 parent d4e9d5b commit b4d1831

6 files changed

Lines changed: 420 additions & 54 deletions

File tree

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
name: Sync to Standalone Repos
2+
3+
on:
4+
push:
5+
branches: [development]
6+
paths:
7+
- 'src/imperazim/command/**'
8+
- 'src/imperazim/form/**'
9+
- 'src/imperazim/packet/**'
10+
- 'src/imperazim/hud/**'
11+
- 'src/imperazim/db/**'
12+
- 'src/imperazim/serializer/**'
13+
14+
jobs:
15+
detect-changes:
16+
if: "!contains(github.event.head_commit.message, '[sync]')"
17+
runs-on: ubuntu-latest
18+
outputs:
19+
command: ${{ steps.filter.outputs.command }}
20+
form: ${{ steps.filter.outputs.form }}
21+
packet: ${{ steps.filter.outputs.packet }}
22+
hud: ${{ steps.filter.outputs.hud }}
23+
db: ${{ steps.filter.outputs.db }}
24+
serializer: ${{ steps.filter.outputs.serializer }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 2
29+
30+
- name: Detect changed modules
31+
id: filter
32+
run: |
33+
CHANGED=$(git diff --name-only HEAD~1 HEAD)
34+
echo "command=$(echo "$CHANGED" | grep -q 'src/imperazim/command/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
35+
echo "form=$(echo "$CHANGED" | grep -q 'src/imperazim/form/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
36+
echo "packet=$(echo "$CHANGED" | grep -q 'src/imperazim/packet/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
37+
echo "hud=$(echo "$CHANGED" | grep -q 'src/imperazim/hud/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
38+
echo "db=$(echo "$CHANGED" | grep -q 'src/imperazim/db/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
39+
echo "serializer=$(echo "$CHANGED" | grep -q 'src/imperazim/serializer/' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
40+
41+
sync-command:
42+
needs: detect-changes
43+
if: needs.detect-changes.outputs.command == 'true'
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout EasyLibrary
47+
uses: actions/checkout@v4
48+
with:
49+
path: easylibrary
50+
51+
- name: Checkout LibCommand
52+
uses: actions/checkout@v4
53+
with:
54+
repository: ImperaZim/LibCommand
55+
ref: development
56+
token: ${{ secrets.SYNC_TOKEN }}
57+
path: standalone
58+
59+
- name: Sync files
60+
run: |
61+
SRC="easylibrary/src/imperazim/command"
62+
DEST="standalone/src/imperazim/command"
63+
64+
# Keep entry point, remove everything else
65+
ENTRY_POINT=""
66+
if [ -f "$DEST/LibCommand.php" ]; then
67+
ENTRY_POINT=$(cat "$DEST/LibCommand.php")
68+
fi
69+
70+
rm -rf "$DEST"
71+
mkdir -p "$DEST"
72+
cp -r "$SRC/"* "$DEST/"
73+
74+
# Restore entry point
75+
if [ -n "$ENTRY_POINT" ]; then
76+
echo "$ENTRY_POINT" > "$DEST/LibCommand.php"
77+
fi
78+
79+
- name: Commit and push
80+
run: |
81+
cd standalone
82+
git config user.name "github-actions[bot]"
83+
git config user.email "github-actions[bot]@users.noreply.github.com"
84+
if git diff --quiet && git diff --cached --quiet; then
85+
echo "No changes to sync"
86+
exit 0
87+
fi
88+
git add src/imperazim/command/
89+
git commit -m "[sync] Update LibCommand from EasyLibrary"
90+
git push
91+
92+
sync-form:
93+
needs: detect-changes
94+
if: needs.detect-changes.outputs.form == 'true'
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Checkout EasyLibrary
98+
uses: actions/checkout@v4
99+
with:
100+
path: easylibrary
101+
102+
- name: Checkout LibForm
103+
uses: actions/checkout@v4
104+
with:
105+
repository: ImperaZim/LibForm
106+
ref: development
107+
token: ${{ secrets.SYNC_TOKEN }}
108+
path: standalone
109+
110+
- name: Sync files
111+
run: |
112+
SRC="easylibrary/src/imperazim/form"
113+
DEST="standalone/src/imperazim/form"
114+
115+
ENTRY_POINT=""
116+
if [ -f "$DEST/LibForm.php" ]; then
117+
ENTRY_POINT=$(cat "$DEST/LibForm.php")
118+
fi
119+
120+
rm -rf "$DEST"
121+
mkdir -p "$DEST"
122+
cp -r "$SRC/"* "$DEST/"
123+
124+
if [ -n "$ENTRY_POINT" ]; then
125+
echo "$ENTRY_POINT" > "$DEST/LibForm.php"
126+
fi
127+
128+
- name: Commit and push
129+
run: |
130+
cd standalone
131+
git config user.name "github-actions[bot]"
132+
git config user.email "github-actions[bot]@users.noreply.github.com"
133+
if git diff --quiet && git diff --cached --quiet; then
134+
echo "No changes to sync"
135+
exit 0
136+
fi
137+
git add src/imperazim/form/
138+
git commit -m "[sync] Update LibForm from EasyLibrary"
139+
git push
140+
141+
sync-packet:
142+
needs: detect-changes
143+
if: needs.detect-changes.outputs.packet == 'true'
144+
runs-on: ubuntu-latest
145+
steps:
146+
- name: Checkout EasyLibrary
147+
uses: actions/checkout@v4
148+
with:
149+
path: easylibrary
150+
151+
- name: Checkout LibPacket
152+
uses: actions/checkout@v4
153+
with:
154+
repository: ImperaZim/LibPacket
155+
ref: development
156+
token: ${{ secrets.SYNC_TOKEN }}
157+
path: standalone
158+
159+
- name: Sync files
160+
run: |
161+
SRC="easylibrary/src/imperazim/packet"
162+
DEST="standalone/src/imperazim/packet"
163+
164+
ENTRY_POINT=""
165+
if [ -f "$DEST/LibPacket.php" ]; then
166+
ENTRY_POINT=$(cat "$DEST/LibPacket.php")
167+
fi
168+
169+
rm -rf "$DEST"
170+
mkdir -p "$DEST"
171+
cp -r "$SRC/"* "$DEST/"
172+
173+
if [ -n "$ENTRY_POINT" ]; then
174+
echo "$ENTRY_POINT" > "$DEST/LibPacket.php"
175+
fi
176+
177+
- name: Commit and push
178+
run: |
179+
cd standalone
180+
git config user.name "github-actions[bot]"
181+
git config user.email "github-actions[bot]@users.noreply.github.com"
182+
if git diff --quiet && git diff --cached --quiet; then
183+
echo "No changes to sync"
184+
exit 0
185+
fi
186+
git add src/imperazim/packet/
187+
git commit -m "[sync] Update LibPacket from EasyLibrary"
188+
git push
189+
190+
sync-hud:
191+
needs: detect-changes
192+
if: needs.detect-changes.outputs.hud == 'true'
193+
runs-on: ubuntu-latest
194+
steps:
195+
- name: Checkout EasyLibrary
196+
uses: actions/checkout@v4
197+
with:
198+
path: easylibrary
199+
200+
- name: Checkout LibHud
201+
uses: actions/checkout@v4
202+
with:
203+
repository: ImperaZim/LibHud
204+
ref: master
205+
token: ${{ secrets.SYNC_TOKEN }}
206+
path: standalone
207+
208+
- name: Sync files
209+
run: |
210+
SRC="easylibrary/src/imperazim/hud"
211+
DEST="standalone/src/imperazim/hud"
212+
213+
ENTRY_POINT=""
214+
if [ -f "$DEST/LibHud.php" ]; then
215+
ENTRY_POINT=$(cat "$DEST/LibHud.php")
216+
fi
217+
218+
rm -rf "$DEST"
219+
mkdir -p "$DEST"
220+
cp -r "$SRC/"* "$DEST/"
221+
222+
if [ -n "$ENTRY_POINT" ]; then
223+
echo "$ENTRY_POINT" > "$DEST/LibHud.php"
224+
fi
225+
226+
- name: Commit and push
227+
run: |
228+
cd standalone
229+
git config user.name "github-actions[bot]"
230+
git config user.email "github-actions[bot]@users.noreply.github.com"
231+
if git diff --quiet && git diff --cached --quiet; then
232+
echo "No changes to sync"
233+
exit 0
234+
fi
235+
git add src/imperazim/hud/
236+
git commit -m "[sync] Update LibHud from EasyLibrary"
237+
git push
238+
239+
sync-db:
240+
needs: detect-changes
241+
if: needs.detect-changes.outputs.db == 'true'
242+
runs-on: ubuntu-latest
243+
steps:
244+
- name: Checkout EasyLibrary
245+
uses: actions/checkout@v4
246+
with:
247+
path: easylibrary
248+
249+
- name: Checkout LibDB
250+
uses: actions/checkout@v4
251+
with:
252+
repository: ImperaZim/LibDB
253+
ref: master
254+
token: ${{ secrets.SYNC_TOKEN }}
255+
path: standalone
256+
257+
- name: Sync files
258+
run: |
259+
SRC="easylibrary/src/imperazim/db"
260+
DEST="standalone/src/imperazim/db"
261+
262+
ENTRY_POINT=""
263+
if [ -f "$DEST/LibDB.php" ]; then
264+
ENTRY_POINT=$(cat "$DEST/LibDB.php")
265+
fi
266+
267+
rm -rf "$DEST"
268+
mkdir -p "$DEST"
269+
cp -r "$SRC/"* "$DEST/"
270+
271+
if [ -n "$ENTRY_POINT" ]; then
272+
echo "$ENTRY_POINT" > "$DEST/LibDB.php"
273+
fi
274+
275+
- name: Commit and push
276+
run: |
277+
cd standalone
278+
git config user.name "github-actions[bot]"
279+
git config user.email "github-actions[bot]@users.noreply.github.com"
280+
if git diff --quiet && git diff --cached --quiet; then
281+
echo "No changes to sync"
282+
exit 0
283+
fi
284+
git add src/imperazim/db/
285+
git commit -m "[sync] Update LibDB from EasyLibrary"
286+
git push
287+
288+
sync-serializer:
289+
needs: detect-changes
290+
if: needs.detect-changes.outputs.serializer == 'true'
291+
runs-on: ubuntu-latest
292+
steps:
293+
- name: Checkout EasyLibrary
294+
uses: actions/checkout@v4
295+
with:
296+
path: easylibrary
297+
298+
- name: Checkout LibSerializer
299+
uses: actions/checkout@v4
300+
with:
301+
repository: ImperaZim/LibSerializer
302+
ref: master
303+
token: ${{ secrets.SYNC_TOKEN }}
304+
path: standalone
305+
306+
- name: Sync files
307+
run: |
308+
SRC="easylibrary/src/imperazim/serializer"
309+
DEST="standalone/src/imperazim/serializer"
310+
311+
ENTRY_POINT=""
312+
if [ -f "$DEST/LibSerializer.php" ]; then
313+
ENTRY_POINT=$(cat "$DEST/LibSerializer.php")
314+
fi
315+
316+
rm -rf "$DEST"
317+
mkdir -p "$DEST"
318+
cp -r "$SRC/"* "$DEST/"
319+
320+
if [ -n "$ENTRY_POINT" ]; then
321+
echo "$ENTRY_POINT" > "$DEST/LibSerializer.php"
322+
fi
323+
324+
- name: Commit and push
325+
run: |
326+
cd standalone
327+
git config user.name "github-actions[bot]"
328+
git config user.email "github-actions[bot]@users.noreply.github.com"
329+
if git diff --quiet && git diff --cached --quiet; then
330+
echo "No changes to sync"
331+
exit 0
332+
fi
333+
git add src/imperazim/serializer/
334+
git commit -m "[sync] Update LibSerializer from EasyLibrary"
335+
git push

0 commit comments

Comments
 (0)