mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
Enhance sync-fork.yml with better error handling
Updated the sync-fork workflow to improve error handling and branch management.
This commit is contained in:
@@ -2,8 +2,19 @@ name: Safe Sync - Nitro-V3
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *' # Sincronizza ogni giorno a mezzanotte UTC
|
# GitHub non offre trigger cross-repo: non possiamo "ascoltare" i push
|
||||||
workflow_dispatch: # Permette l'avvio manuale dalla scheda Actions
|
# sull'upstream senza esserne collaboratori. Per avvicinarci a un
|
||||||
|
# "automatico quando cambia" facciamo polling frequente: ogni run fa
|
||||||
|
# fetch dell'upstream e lavora SOLO sui branch effettivamente avanzati
|
||||||
|
# (guard "skip se invariato" sotto). Alza/abbassa la frequenza qui.
|
||||||
|
# NB: i cron possono partire con qualche minuto di ritardo e GitHub li
|
||||||
|
# disabilita dopo 60 giorni di inattività del repo.
|
||||||
|
- cron: '*/30 * * * *' # ogni 30 minuti
|
||||||
|
workflow_dispatch: # avvio manuale dalla scheda Actions
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: safe-sync
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sync-safe:
|
sync-safe:
|
||||||
@@ -15,7 +26,7 @@ jobs:
|
|||||||
- name: Checkout Fork
|
- name: Checkout Fork
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Scarica tutta la cronologia per poter fare il merge correttamente
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Configure Git Credentials
|
- name: Configure Git Credentials
|
||||||
run: |
|
run: |
|
||||||
@@ -24,25 +35,33 @@ jobs:
|
|||||||
|
|
||||||
- name: Fetch and Merge Upstream
|
- name: Fetch and Merge Upstream
|
||||||
run: |
|
run: |
|
||||||
# Aggiunge il repository originale
|
set -euo pipefail
|
||||||
git remote add upstream https://github.com/duckietm/Nitro-V3.git
|
|
||||||
git fetch upstream
|
git remote add upstream https://github.com/duckietm/Nitro-V3.git 2>/dev/null || \
|
||||||
|
git remote set-url upstream https://github.com/duckietm/Nitro-V3.git
|
||||||
|
git fetch upstream --prune
|
||||||
|
|
||||||
# Cicla su tutti i branch presenti nell'upstream originale
|
|
||||||
for branch in $(git branch -r | grep 'upstream/' | grep -v 'HEAD'); do
|
for branch in $(git branch -r | grep 'upstream/' | grep -v 'HEAD'); do
|
||||||
local_branch=${branch#upstream/}
|
local_branch=${branch#upstream/}
|
||||||
echo "Elaborazione branch: $local_branch"
|
echo "::group::$local_branch"
|
||||||
|
|
||||||
# Si sposta sul branch locale (se non esiste lo crea basandosi sull'upstream)
|
git checkout "$local_branch" 2>/dev/null || \
|
||||||
git checkout $local_branch || git checkout -b $local_branch upstream/$local_branch
|
git checkout -b "$local_branch" "upstream/$local_branch"
|
||||||
|
|
||||||
# Esegue il merge delle novità dell'upstream nel tuo branch locale
|
upstream_sha=$(git rev-parse "upstream/$local_branch")
|
||||||
# --no-edit accetta il messaggio di commit automatico di git
|
if git merge-base --is-ancestor "$upstream_sha" HEAD; then
|
||||||
if git merge upstream/$local_branch --no-edit; then
|
echo "Nessun cambiamento per $local_branch, salto."
|
||||||
echo "Merge completato con successo per $local_branch. Invio gli aggiornamenti..."
|
echo "::endgroup::"
|
||||||
git push origin $local_branch
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Novità rilevate su $local_branch, provo il merge..."
|
||||||
|
if git merge "upstream/$local_branch" --no-edit; then
|
||||||
|
echo "Merge ok per $local_branch. Invio gli aggiornamenti..."
|
||||||
|
git push origin "$local_branch"
|
||||||
else
|
else
|
||||||
echo "Rilevato conflitto di merge su $local_branch! Il tuo lavoro è al sicuro. Salto il push per questo branch."
|
echo "Conflitto di merge su $local_branch! Il tuo lavoro è al sicuro: salto il push e annullo il merge."
|
||||||
git merge --abort
|
git merge --abort
|
||||||
fi
|
fi
|
||||||
|
echo "::endgroup::"
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user