Restore files after forced sync
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
name: Conditional Sync Upstream, Build, and Push Docker Image
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 * * * *' # ogni ora
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
sync-build-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Backup files and force sync upstream
|
||||
id: sync
|
||||
run: |
|
||||
git config user.name "github-actions"
|
||||
git config user.email "[email protected]"
|
||||
|
||||
git remote get-url upstream || git remote add upstream https://github.com/UrloMythus/MammaMia.git
|
||||
git fetch upstream
|
||||
|
||||
# Controlla se ci sono differenze PRIMA del reset
|
||||
if git diff --quiet HEAD upstream/main; then
|
||||
echo "Repository already up to date"
|
||||
echo "no_change=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Changes detected, proceeding with sync and build"
|
||||
|
||||
backup_dir=".git/backup_files"
|
||||
mkdir -p "$backup_dir/.github/workflows"
|
||||
mkdir -p "$backup_dir/Dockerfiles"
|
||||
|
||||
if [ -f config.json ]; then
|
||||
cp config.json "$backup_dir/config.json"
|
||||
else
|
||||
echo "⚠️ config.json non trovato, skipping backup"
|
||||
fi
|
||||
|
||||
if [ -f update_domains.py ]; then
|
||||
cp update_domains.py "$backup_dir/update_domains.py"
|
||||
else
|
||||
echo "⚠️ update_domains.py non trovato, skipping backup"
|
||||
fi
|
||||
|
||||
if [ -d .github/workflows ]; then
|
||||
cp -r .github/workflows/* "$backup_dir/.github/workflows/" || echo "⚠️ No workflows to backup"
|
||||
else
|
||||
echo "⚠️ Cartella .github/workflows non trovata, skipping backup"
|
||||
fi
|
||||
|
||||
if [ -d Dockerfiles ]; then
|
||||
cp -r Dockerfiles/* "$backup_dir/Dockerfiles/" || echo "⚠️ No Dockerfiles to backup"
|
||||
else
|
||||
echo "⚠️ Cartella Dockerfiles non trovata, skipping backup"
|
||||
fi
|
||||
|
||||
git checkout main || git checkout -b main
|
||||
git reset --hard upstream/main
|
||||
|
||||
if [ -f "$backup_dir/config.json" ]; then
|
||||
cp "$backup_dir/config.json" config.json
|
||||
else
|
||||
echo "⚠️ File config.json non trovato nel backup, skipping restore"
|
||||
fi
|
||||
|
||||
if [ -f "$backup_dir/update_domains.py" ]; then
|
||||
cp "$backup_dir/update_domains.py" update_domains.py
|
||||
else
|
||||
echo "⚠️ File update_domains.py non trovato nel backup, skipping restore"
|
||||
fi
|
||||
|
||||
mkdir -p .github/workflows
|
||||
if [ -d "$backup_dir/.github/workflows" ]; then
|
||||
cp -r "$backup_dir/.github/workflows/"* .github/workflows/ || echo "⚠️ No workflows to restore"
|
||||
else
|
||||
echo "⚠️ Backup workflows folder mancante, skipping restore"
|
||||
fi
|
||||
|
||||
mkdir -p Dockerfiles
|
||||
if [ -d "$backup_dir/Dockerfiles" ]; then
|
||||
cp -r "$backup_dir/Dockerfiles/"* Dockerfiles/ || echo "⚠️ No Dockerfiles to restore"
|
||||
else
|
||||
echo "⚠️ Backup Dockerfiles folder mancante, skipping restore"
|
||||
fi
|
||||
|
||||
git add .
|
||||
git commit -m "Restore files after forced sync" || echo "No changes needed"
|
||||
git push origin main --force
|
||||
echo "no_change=false" >> $GITHUB_OUTPUT
|
||||
|
||||
rm -rf "$backup_dir"
|
||||
fi
|
||||
|
||||
- name: Check if build is needed
|
||||
run: echo "Changes detected, proceed with build."
|
||||
if: steps.sync.outputs.no_change == 'false'
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
if: steps.sync.outputs.no_change == 'false'
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
if: steps.sync.outputs.no_change == 'false'
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: dula117/mammamia:latest
|
||||
if: steps.sync.outputs.no_change == 'false'
|
||||
@@ -0,0 +1,37 @@
|
||||
name: Update Domains
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 20 * * *" # Esegui alle 20:00 ogni giorno
|
||||
workflow_dispatch: # Permette di avviare manualmente il workflow
|
||||
|
||||
jobs:
|
||||
update-domains:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install requests
|
||||
|
||||
- name: Update domains in config.json
|
||||
run: |
|
||||
python update_domains.py
|
||||
|
||||
- name: Commit and push changes
|
||||
run: |
|
||||
git config --global user.email "[email protected]"
|
||||
git config --global user.name "Your Name"
|
||||
git add config.json
|
||||
git commit -m "Aggiornamento domini in config.json"
|
||||
git push
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
Reference in New Issue
Block a user