77jobs :
88 update-domains :
99 runs-on : ubuntu-latest
10-
1110 permissions :
1211 contents : write
13-
12+
1413 steps :
1514 - name : Checkout code
1615 uses : actions/checkout@v4
1716 with :
18- fetch-depth : 0 # Serve per l'amend
17+ fetch-depth : 0
1918 token : ${{ secrets.GITHUB_TOKEN }}
2019
2120 - name : Setup Python
2221 uses : actions/setup-python@v5
2322 with :
2423 python-version : ' 3.12'
25-
24+
2625 - name : Install dependencies
2726 run : |
2827 pip install httpx tldextract ua-generator dnspython
2928 pip install --upgrade pip setuptools wheel
30-
29+
3130 - name : Configure DNS
3231 run : |
3332 sudo sh -c 'echo "nameserver 208.67.220.220" > /etc/resolv.conf'
3433 sudo sh -c 'echo "nameserver 208.67.222.222" >> /etc/resolv.conf'
3534 sudo sh -c 'echo "nameserver 77.88.8.8" >> /etc/resolv.conf'
36-
35+
3736 - name : Execute domain update script
3837 run : python .github/workflows/script/domain_update.py
3938
40- - name : Always amend last commit
39+ - name : Check for changes and amend/ commit
4140 run : |
4241 git config --global user.name 'github-actions[bot]'
4342 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
4443
4544 if ! git diff --quiet .github/workflows/script/domains.json; then
46- echo "📝 Changes detected - amending last commit "
45+ echo "📝 Changes detected in domains.json "
4746 git add .github/workflows/script/domains.json
48- git commit --amend --no-edit
49- git push --force-with-lease origin main
47+
48+ if git rev-parse HEAD >/dev/null 2>&1; then
49+ if git log origin/main..HEAD --oneline | grep -q .; then
50+ echo "🔄 Amending unpushed commit"
51+ git commit --amend --no-edit
52+ else
53+ echo "✨ Creating new commit (last commit already pushed)"
54+ git commit -m "🔄 Update domains.json [$(date +'%Y-%m-%d %H:%M:%S')]"
55+ fi
56+ else
57+ echo "✨ Creating first commit"
58+ git commit -m "🔄 Update domains.json [$(date +'%Y-%m-%d %H:%M:%S')]"
59+ fi
60+
61+ git push --force-with-lease origin main || git push origin main
62+ echo "✅ Changes pushed successfully"
5063 else
5164 echo "✅ No changes to domains.json"
5265 fi
5568 if : failure()
5669 run : |
5770 echo "❌ Something went wrong. Repository state:"
58- git log --oneline -5
71+ git log --oneline -5 || echo "No commits yet"
5972 git status
0 commit comments