dns/.forgejo/workflows/ci.yaml

48 lines
1.7 KiB
YAML

on:
push:
branches:
- 'main'
jobs:
deploy_script:
runs-on: linux_amd64
steps:
- name: Apply zone changes
shell: bash
run: |
CURRENT_ZONE=
echo "Preparing to update ${{ vars.DNS_SERVER }}..."
git clone ${{ gitea.server_url }}/${{ gitea.repository }} dns
cd dns
git diff HEAD^ HEAD > zone_diff.txt
while IFS= read -r line; do
case "$line" in
"--- "*".zone")
NAME=$(echo "$line" .zone | sed 's/--- //' | sed 's|a/||')
CURRENT_ZONE=$(basename $NAME)
echo "*** Updating $CURRENT_ZONE"
;;
"--- "*)
CURRENT_ZONE=
;;
"+++"*)
;;
"-"* | "+"*)
if [ ! -z $CURRENT_ZONE ]; then
if [[ $line == -* ]]; then # Enregistrement supprimé
RECORD=$(echo "$line" | sed 's/^-//')
echo "update delete $RECORD"
echo -e "server $DNS_SERVER\nupdate delete $RECORD\nsend" > temp_delete
nsupdate -k "${{ secrets.TSIG_KEY }}" temp_delete
rm temp_delete
elif [[ $line == +* ]]; then # Enregistrement ajouté
RECORD=$(echo "$line" | sed 's/^+//')
echo "+ $RECORD"
echo -e "server $DNS_SERVER\nupdate add $RECORD\nsend" > temp_add
nsupdate -k "${{ secrets.TSIG_KEY }}" temp_add
rm temp_add
fi
fi
;;
esac
done < zone_diff.txt