1- include :
2- - project : ' devops/cicd'
3- ref : main
4- file : ' /scripts/set_ssh_key.yml'
5-
1+ ---
2+ include :
63 - local : ' .gitlab/ci/invidious.yml'
74
85stages :
9- - sync
6+ - lint
107 - update_services
8+ - sync
9+
10+ yaml_lint :
11+ stage : lint
12+ image : python:3.10
13+ script :
14+ - pip install yamllint
15+ - yamllint . -c .yamllint
16+ only :
17+ changes :
18+ - " **/*.yml"
19+ - " **/*.yml.j2"
20+ - " **/*.yaml"
21+ - " **/*.yaml.j2"
22+ allow_failure : true
1123
1224sync-to-clean :
1325 stage : sync
@@ -20,44 +32,45 @@ sync-to-clean:
2032 # Installazione delle dipendenze necessarie
2133 - apk add --no-cache git rsync
2234 script :
23- # Step 1: Estrazione delle informazioni della commit corrente
24- - COMMIT_AUTHOR_NAME=$(git log -1 --pretty=format:"%an")
25- - COMMIT_AUTHOR_EMAIL=$(git log -1 --pretty=format:"%ae")
26- - COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
27-
28- # Step 2: Clonare il repository homelab-clean utilizzando il token CI già disponibile
29- - git clone https://${GIT_USERNAME}:${SYNC_PAT_TOKEN}@${CI_SERVER_HOST}/${GIT_USERNAME}/homelab-clean.git /tmp/homelab-clean
30-
31- # Step 3: Eliminare tutto tranne la cartella .git dal repository clonato
32- - find /tmp/homelab-clean -mindepth 1 -path "/tmp/homelab-clean/.git" -prune -o -exec rm -rf {} \; 2>/dev/null || true
33-
34- # Step 4: Copiare il contenuto del repository attuale (tranne .git) nel repository clonato
35- - rsync -av --exclude='.git' $CI_PROJECT_DIR/ /tmp/homelab-clean/
36-
37- # Step 5: Eliminare le cartelle e i file specificati nel file .exclude_from_github
38- - cd /tmp/homelab-clean
39-
40- # Verificare se il file .exclude_from_github esiste
41- - if [ -f ".exclude_from_github" ]; then
42- - echo "File .exclude_from_github trovato, elaborazione delle esclusioni..."
43- - while IFS= read -r item || [ -n "$item" ]; do
44- - if [ -n "$item" ] && [[ ! "$item" =~ ^\s*# ]]; then
45- - item=$(echo $item | xargs) # Rimuove eventuali spazi bianchi
46- - echo "Rimozione di $item"
47- - rm -rf "$item"
48- - fi
49- - done < .exclude_from_github
50- - rm -f .exclude_from_github
51- - else
52- - echo "File .exclude_from_github non trovato, nessuna esclusione da applicare"
53- - fi
54-
55- # Maschera la mail
56- -
find . -type f \( -name "*.yml" -o -name "*.yaml" -o -name "*.md" -o -name "*.j2" -o -name "*.json" \) -exec sed -i "s/$(echo ${EMAIL_TO_MASK} | sed 's/[\/&]/\\&/g')/[email protected] /g" {} \; 57-
58- # Step 6: Commit e push delle modifiche con lo stesso autore e messaggio originale
59- - git add .
60- - git config user.name "$COMMIT_AUTHOR_NAME"
61- - git config user.email "$COMMIT_AUTHOR_EMAIL"
62- - git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit"
63- - git push https://${GIT_USERNAME}:${SYNC_PAT_TOKEN}@${CI_SERVER_HOST}/${GIT_USERNAME}/homelab-clean.git main
35+ - |
36+ # Step 1: Estrazione delle informazioni della commit corrente
37+ COMMIT_AUTHOR_NAME=$(git log -1 --pretty=format:"%an")
38+ COMMIT_AUTHOR_EMAIL=$(git log -1 --pretty=format:"%ae")
39+ COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
40+
41+ # Step 2: Clonare il repository homelab-clean utilizzando il token CI già disponibile
42+ git clone https://${GIT_USERNAME}:${SYNC_PAT_TOKEN}@${CI_SERVER_HOST}/${GIT_USERNAME}/homelab-clean.git /tmp/homelab-clean
43+
44+ # Step 3: Eliminare tutto tranne la cartella .git dal repository clonato
45+ find /tmp/homelab-clean -mindepth 1 -path "/tmp/homelab-clean/.git" -prune -o -exec rm -rf {} \; 2>/dev/null || true
46+
47+ # Step 4: Copiare il contenuto del repository attuale (tranne .git) nel repository clonato
48+ rsync -av --exclude='.git' $CI_PROJECT_DIR/ /tmp/homelab-clean/
49+
50+ # Step 5: Eliminare le cartelle e i file specificati nel file .exclude_from_github
51+ cd /tmp/homelab-clean
52+
53+ # Verificare se il file .exclude_from_github esiste
54+ if [ -f ".exclude_from_github" ]; then
55+ echo "File .exclude_from_github trovato, elaborazione delle esclusioni..."
56+ while IFS= read -r item || [ -n "$item" ]; do
57+ if [ -n "$item" ] && [[ ! "$item" =~ ^\s*# ]]; then
58+ item=$(echo $item | xargs) # Rimuove eventuali spazi bianchi
59+ echo "Rimozione di $item"
60+ rm -rf "$item"
61+ fi
62+ done < .exclude_from_github
63+ rm -f .exclude_from_github
64+ else
65+ echo "File .exclude_from_github non trovato, nessuna esclusione da applicare"
66+ fi
67+
68+ # Maschera la mail
69+ find . -type f \( -name "*.yml" -o -name "*.yaml" -o -name "*.md" -o -name "*.j2" -o -name "*.json" \) -exec sed -i "s/$(echo ${EMAIL_TO_MASK} | sed 's/[\/&]/\\&/g')/[email protected] /g" {} \; 70+
71+ # Step 6: Commit e push delle modifiche con lo stesso autore e messaggio originale
72+ git add .
73+ git config user.name "$COMMIT_AUTHOR_NAME"
74+ git config user.email "$COMMIT_AUTHOR_EMAIL"
75+ git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit"
76+ git push https://${GIT_USERNAME}:${SYNC_PAT_TOKEN}@${CI_SERVER_HOST}/${GIT_USERNAME}/homelab-clean.git main
0 commit comments