Skip to content

Commit ba827a9

Browse files
committed
refactor: rename sync workflow and enhance branch synchronization logic
1 parent 0f2ecf3 commit ba827a9

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
1-
name: Sync Main to Staging
1+
name: Sync branches
22

33
on:
44
push:
55
branches:
66
- main
77

88
permissions:
9-
contents: write
9+
contents: write # Necesario para que el push funcione
1010

1111
jobs:
12-
sync:
12+
deploy:
1313
runs-on: ubuntu-latest
14+
1415
steps:
15-
- name: Checkout staging branch
16-
uses: actions/checkout@v3
16+
# 1️⃣ Clonamos el repo con la deploy key y todo el historial (fetch-depth: 0 es clave)
17+
- name: Checkout main
18+
uses: actions/checkout@v4
1719
with:
18-
ref: staging
19-
# The GITHUB_TOKEN is automatically used here due to the `permissions` key
20-
- name: Configure Git
20+
ssh-key: ${{ secrets.DEPLOY_KEY }}
21+
fetch-depth: 0
22+
23+
# 2️⃣ Configuramos identidad del bot
24+
- name: Setup Git
2125
run: |
22-
git config user.name "github-actions[bot]"
23-
git config user.email "github-actions[bot]@users.noreply.github.com"
24-
- name: Merge main into staging
26+
git config user.name "Staging Sync Bot"
27+
git config user.email "[email protected]"
28+
29+
# 3️⃣ Sincronizamos staging con main solo si es fast-forward posible
30+
- name: Push to staging
2531
run: |
26-
git pull origin main
27-
git push origin staging
32+
# Traemos lo último de remoto
33+
git fetch origin
34+
35+
# Si la rama staging existe, la usamos; si no, la creamos desde remoto
36+
git checkout staging || git checkout -b staging origin/staging
37+
38+
# Intentamos fast-forward desde main
39+
if git merge --ff-only origin/main; then
40+
echo "✅ Fast-forward successful. Pushing to staging..."
41+
git push origin staging
42+
else
43+
echo "❌ No fast-forward possible. Manual intervention required."
44+
# Si quieres que simplemente no haga nada, comenta la siguiente línea
45+
exit 1
46+
fi

0 commit comments

Comments
 (0)