dns/.forgejo/workflows/ci.yaml

52 lines
1.6 KiB
YAML
Raw Normal View History

2023-10-24 18:04:11 +02:00
on:
push:
branches:
2023-10-25 00:53:02 +02:00
- 'main'
2023-10-24 18:04:11 +02:00
jobs:
deploy_script:
2023-10-24 18:04:11 +02:00
runs-on: linux_amd64
steps:
2024-08-20 16:45:39 +02:00
- name: Apply zone changes
2023-10-24 18:04:11 +02:00
shell: bash
2024-08-20 16:51:32 +02:00
run: |
2024-08-20 17:35:01 +02:00
CURRENT_ZONE=
2024-08-20 16:51:32 +02:00
echo "Preparing to update ${{ vars.DNS_SERVER }}..."
2024-08-20 17:27:39 +02:00
git clone ${{ gitea.server_url }}/${{ gitea.repository }} dns
cd dns
git diff HEAD^ HEAD > zone_diff.txt
2024-08-20 17:29:06 +02:00
while IFS= read -r line; do
case "$line" in
"--- "*".zone")
2024-08-20 17:40:11 +02:00
NAME=$(echo "$line" .zone | sed 's/--- //' | sed 's|a/||')
CURRENT_ZONE=$(basename $NAME)
2024-08-20 17:42:37 +02:00
echo "*** Updating $CURRENT_ZONE"
2024-08-20 17:29:06 +02:00
;;
2024-08-20 17:35:01 +02:00
"--- "*)
CURRENT_ZONE=
;;
2024-08-20 17:29:06 +02:00
"+++"*)
;;
"-"* | "+"*)
2024-08-20 17:36:31 +02:00
if [ ! -z $CURRENT_ZONE ]; then
2024-08-20 17:35:01 +02:00
if [[ $line == -* ]]; then # Enregistrement supprimé
RECORD=$(echo "$line" | sed 's/^-//')
2024-08-20 17:49:34 +02:00
echo "update delete $RECORD"
nsupdate -k $TSIG_KEY <<EOF
server $DNS_SERVER
update delete $RECORD
send
EOF
2024-08-20 17:35:01 +02:00
elif [[ $line == +* ]]; then # Enregistrement ajouté
RECORD=$(echo "$line" | sed 's/^+//')
echo "+ $RECORD"
2024-08-20 17:49:34 +02:00
nsupdate -k $TSIG_KEY <<EOF
server $DNS_SERVER
update add $RECORD
send
EOF
2024-08-20 17:35:01 +02:00
fi
2024-08-20 17:29:06 +02:00
fi
;;
esac
done < zone_diff.txt