From abca654f578138248f65220e8960051c100e09b1 Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Wed, 22 Feb 2023 15:28:57 +0100 Subject: [PATCH] Move from Travis to github actions --- .github/scripts/validate-and-lint.sh | 30 ++++++++++++++++++++++++++++ .github/scripts/validate-examples.sh | 17 ++++++++++++++++ .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++ .travis.yml | 7 ------- 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100755 .github/scripts/validate-and-lint.sh create mode 100755 .github/scripts/validate-examples.sh create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/scripts/validate-and-lint.sh b/.github/scripts/validate-and-lint.sh new file mode 100755 index 000000000..f3dfc1c91 --- /dev/null +++ b/.github/scripts/validate-and-lint.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Validate the XML file structure and lint XSD and XML files, e.g. indentation +# +# You need the binary `xmllint` +# apt-get install libxml2-utils + +# The -e flag causes the script to exit as soon as one command returns a non-zero exit code +set -e + +echo "Validating XML file structure and linting XSD and XML files ..." + +PARSING_ERROR=0 +# Iterate all XML and XSD files +while IFS= read -r -d $'\0' filename; do + # Prettify the file using xmllint and save the result to ${filename}.pretty + if XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --pretty 1 "${filename}" >"${filename}.pretty"; then + # Remove lines containing the term "xmlspy" to get rid of advertising this and save the result as ${filename} + grep -i -v "xmlspy" "${filename}.pretty" >"${filename}" + else + PARSING_ERROR=$? + echo -e "\033[0;Validating XML structure of file '${filename}' failed\033[0m" + fi + # Remove temp file + rm "${filename}.pretty" +done < <(/usr/bin/find . -type f \( -name "*.xsd" -or -name "*.xml" \) -print0) + +if [ ${PARSING_ERROR} -ne 0 ]; then + exit ${PARSING_ERROR} +fi +echo -e '\033[0;32mFinished validating XML file structure and linting XSD and XML files\033[0m' diff --git a/.github/scripts/validate-examples.sh b/.github/scripts/validate-examples.sh new file mode 100755 index 000000000..45041a37a --- /dev/null +++ b/.github/scripts/validate-examples.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Validate all OJP XML examples from the examples/ directory against the OJP XSD schema +# +# You need the binary `xmllint` +# apt-get install libxml2-utils + +# The -e flag causes the script to exit as soon as one command returns a non-zero exit code +set -e + +echo "Validating NeTEx XML examples ..." + +if xmllint --noout --schema xsd/NeTEx_publication.xsd examples/functions/calendar/*xml examples/functions/fares/*xml examples/functions/grouping/*xml examples/functions/newModes/*xml examples/functions/patterns/*xml examples/functions/pointOfInterest/*xml examples/functions/simpleNetwork/*xml examples/functions/site/*xml examples/functions/stopPlace/*xml examples/functions/timetable/*xml examples/functions/validityCondition/*xml examples/functions/variant/*xml examples/functions/vehicleSchedule/*xml examples/functions/versioning/*xml examples/standards/epip/*xml examples/standards/era_uic/*xml examples/standards/fxc/*xml examples/standards/gbfs/*xml examples/standards/gtfs/*xml examples/standards/neptune/*xml examples/standards/noptis/*xml examples/standards/tap_tsi/*xml examples/standards/txc/*xml examples/standards/vdv452/*/*xml examples/standards/vdv452/*/*/*xml; then + echo -e '\033[0;32mValidating NeTEx XML examples succeeded\033[0m' +else + echo -e '\033[0;31mValidating NeTEx XML examples failed\033[0m' + exit 1 +fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..650cbc2c3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: push + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - run: echo "Job was automatically triggered by a ${{ github.event_name }} event for branch ${{ github.ref }}" + + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Install xmllint and xsltproc + run: | + sudo apt-get update + sudo apt-get install libxml2-utils xsltproc + + - name: Validate structure and lint XSD and XML files + run: ./.github/scripts/validate-and-lint.sh + + - name: Validate NeTEx XML examples + run: ./.github/scripts/validate-examples.sh + + - name: Commit changes + uses: EndBug/add-and-commit@v9 # https://github.com/marketplace/actions/add-commit + with: + default_author: github_actions + message: 'Lint and update documentation tables' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 746538e08..000000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: c - -before_script: - - sudo apt-get install -qq libxml2-utils - -script: - - "xmllint --noout --schema xsd/NeTEx_publication.xsd examples/functions/calendar/*xml examples/functions/fares/*xml examples/functions/grouping/*xml examples/functions/newModes/*xml examples/functions/patterns/*xml examples/functions/pointOfInterest/*xml examples/functions/simpleNetwork/*xml examples/functions/site/*xml examples/functions/stopPlace/*xml examples/functions/timetable/*xml examples/functions/validityCondition/*xml examples/functions/variant/*xml examples/functions/vehicleSchedule/*xml examples/functions/versioning/*xml examples/standards/epip/*xml examples/standards/era_uic/*xml examples/standards/fxc/*xml examples/standards/gbfs/*xml examples/standards/gtfs/*xml examples/standards/neptune/*xml examples/standards/noptis/*xml examples/standards/tap_tsi/*xml examples/standards/txc/*xml examples/standards/vdv452/*/*xml examples/standards/vdv452/*/*/*xml"