From c6239ddb8308f63f8217c4bcd1cfa36376c7f380 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 16:05:41 +0000 Subject: [PATCH 1/6] Add an action to validate XML files Fixes #168 --- .github/workflows/validate-config.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate-config.yml b/.github/workflows/validate-config.yml index c99bcbd..4709b67 100644 --- a/.github/workflows/validate-config.yml +++ b/.github/workflows/validate-config.yml @@ -7,13 +7,18 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - name: BOM check run: | ! grep -rlI $'\xEF\xBB\xBF' ispdb - - name: Validate file extensions - run: | - set -o pipefail - ls -1 ispdb/ | grep -v '\.xml$' | awk '{print "::error file=ispdb/"$0"::File name \"ispdb/"$0"\" does not end in .xml – Please rename!"}' && exit 1 || true + - name: Validate file extensions + run: | + set -o pipefail + ls -1 ispdb/ | grep -v '\.xml$' | awk '{print "::error file=ispdb/"$0"::File name \"ispdb/"$0"\" does not end in .xml – Please rename!"}' && exit 1 || true + + - name: Validate XML content + uses: action-pack/valid-xml@v1.09 + with: + path: "ispdb/" From 291645879bbe49e29c97a5920b9e61cbe1c58b66 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 16:08:58 +0000 Subject: [PATCH 2/6] Re-introduce the syntax error in the Naver file to verify the action works --- ispdb/naver.com.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ispdb/naver.com.xml b/ispdb/naver.com.xml index bd11fcf..09fc76e 100644 --- a/ispdb/naver.com.xml +++ b/ispdb/naver.com.xml @@ -25,6 +25,6 @@ %EMAILADDRESS% password-encrypted - + - + \ No newline at end of file From 09aed8d31eeef0bb7374672d4a3cc6d07f102f3a Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 16:43:45 +0000 Subject: [PATCH 3/6] Use a script instead, which uses the same parser as convert.py --- .github/workflows/validate-config.yml | 5 ++- tools/validate.py | 51 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tools/validate.py diff --git a/.github/workflows/validate-config.yml b/.github/workflows/validate-config.yml index 4709b67..65e1452 100644 --- a/.github/workflows/validate-config.yml +++ b/.github/workflows/validate-config.yml @@ -19,6 +19,5 @@ jobs: ls -1 ispdb/ | grep -v '\.xml$' | awk '{print "::error file=ispdb/"$0"::File name \"ispdb/"$0"\" does not end in .xml – Please rename!"}' && exit 1 || true - name: Validate XML content - uses: action-pack/valid-xml@v1.09 - with: - path: "ispdb/" + run: | + python tools/validate.py ispdb/* diff --git a/tools/validate.py b/tools/validate.py new file mode 100644 index 0000000..9604470 --- /dev/null +++ b/tools/validate.py @@ -0,0 +1,51 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# This script checks all input files to validate that their content is valid +# XML. It is meant to run in the CI for PRs against the autoconfig repository. + +import argparse +import os +import sys +from typing import List +from lxml import etree + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "file", nargs="*", help="input file(s) to process, wildcards allowed" + ) + args = parser.parse_args(sys.argv[1:]) + + # Defining `files` here isn't strictly necessary, but the extra typing + # (which we can't really get otherwise) helps with maintenance. + files: List[str] = args.file + + # The exit code. Stays 0 unless we encounter a file that doesn't parse. + ret = 0 + + for f in files: + # Filter out directories an non-XML files + if os.path.isdir(f): + print(f"Ignoring directory {f}") + continue + + if not f.endswith(".xml"): + print(f"Ignoring non-XML file {f}") + continue + + # Try parsing the file. If this did not work, print the error and set + # the exit code to 1. + try: + etree.parse(f) + except Exception as e: + print(f"File {f} did not parse: {e}") + ret = 1 + + exit(ret) + + +if __name__ == "__main__": + main() From f516b5a4d2014185d3d29a56a7cd936dae00ba8d Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 17:13:27 +0000 Subject: [PATCH 4/6] Fix formatting --- .github/workflows/validate-config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-config.yml b/.github/workflows/validate-config.yml index 65e1452..d8aad7d 100644 --- a/.github/workflows/validate-config.yml +++ b/.github/workflows/validate-config.yml @@ -9,9 +9,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: BOM check - run: | - ! grep -rlI $'\xEF\xBB\xBF' ispdb + - name: BOM check + run: | + ! grep -rlI $'\xEF\xBB\xBF' ispdb - name: Validate file extensions run: | From da4fa6fd46cc723eb26642ec62b2c50df0647a34 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 17:15:33 +0000 Subject: [PATCH 5/6] Install lxml --- .github/workflows/validate-config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate-config.yml b/.github/workflows/validate-config.yml index d8aad7d..9ebc696 100644 --- a/.github/workflows/validate-config.yml +++ b/.github/workflows/validate-config.yml @@ -20,4 +20,5 @@ jobs: - name: Validate XML content run: | + pip install lxml python tools/validate.py ispdb/* From 44fb4c5e56e9a819d3faba36219eb5dc99c261d0 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 17 Dec 2025 17:16:32 +0000 Subject: [PATCH 6/6] Script works, revert change to Naver config --- ispdb/naver.com.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ispdb/naver.com.xml b/ispdb/naver.com.xml index 09fc76e..78a4fa9 100644 --- a/ispdb/naver.com.xml +++ b/ispdb/naver.com.xml @@ -25,6 +25,6 @@ %EMAILADDRESS% password-encrypted - + \ No newline at end of file