From 5224ee7e9cb6fe3c296cd70de7d48b3481fffe28 Mon Sep 17 00:00:00 2001 From: Joab <89288499+Joabutt@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:13:16 +0800 Subject: [PATCH] Create check_pr.yml --- .github/workflows/check_pr.yml | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/check_pr.yml diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml new file mode 100644 index 0000000..9a2145f --- /dev/null +++ b/.github/workflows/check_pr.yml @@ -0,0 +1,37 @@ +name: Check JSON on PR +on: + pull_request: + paths: + - 'domains/**/*.json' + +jobs: + check_json: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Check JSON + run: | + for jsonfile in $(find domains -name "*.json"); do + echo "\nProcessing ${jsonfile}" + if ! cat ${jsonfile} | jq empty; then + echo "Failed parsing ${jsonfile}" + exit 1 + fi + REQUIRED_FIELDS=('subdomain' 'url' 'email') + for field in ${REQUIRED_FIELDS[@]}; do + if ! cat "${jsonfile}" | jq -e "has(\"${field}\")"; then + echo "${field} does not exist in ${jsonfile}" + exit 1 + fi + done + TYPE=$(jq -r '.type // "CNAME"' ${jsonfile}) + URL=$(jq -r '.url' ${jsonfile}) + if [ ${TYPE} = "CNAME" ] || [ -z ${TYPE} ]; then + if echo ${URL} | grep -E '^https?://[^/]*/[^/]+'; then + echo "URL in ${jsonfile} must not contain subdirectories for CNAME records." + exit 1 + fi + fi + done