From 7fddc84ec02f4827fe7a20f5172d2716e254bda6 Mon Sep 17 00:00:00 2001 From: Bruce BUJON Date: Tue, 26 Oct 2021 10:12:31 +0200 Subject: [PATCH] feat: Add hosts validation action --- .github/workflows/hosts-validation.yml | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/hosts-validation.yml diff --git a/.github/workflows/hosts-validation.yml b/.github/workflows/hosts-validation.yml new file mode 100644 index 0000000..ae46b80 --- /dev/null +++ b/.github/workflows/hosts-validation.yml @@ -0,0 +1,38 @@ +name: Hosts Validation + +on: + push: + paths: + - hotst.txt + pull_request: + paths: + - hotst.txt + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Validate hosts file + run: | + input="hosts.txt" + debug=false + while IFS= read -r line + do + if [[ "$line" =~ ^\# ]]; then + $debug && echo "$line is a comment" + elif [[ "$line" = "" ]]; then + $debug && echo "line is empty" + elif [[ "$line" =~ ^127\.0\.0\.1 ]] || [[ "$line" =~ ^::1 ]]; then + $debug && echo "$line is an allowed redirection" + else + echo "$line is not an allowed redirection" + echo "Only redirection to the loopback interface is allowed (127.0.0.1 for IPv4 or ::1 for IPv6)" + exit 1 + fi + done < "$input" + echo "Hosts file is valid"