From 15c3efe3173ac573f337aeadf4accc46f4ae556f Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Fri, 21 Feb 2025 10:38:08 +0100 Subject: [PATCH] Travil to github actios --- .github/scripts/validate-and-lint.sh | 30 +++++++++++++ .github/scripts/validate-examples.sh | 17 ++++++++ .github/workflows/ci.yml | 42 ++++++++++++++++++ .travis.yml | 10 ----- .travis/travis-ci_git-commit.sh | 64 ---------------------------- .travis/xmllint-check.sh | 4 -- 6 files changed, 89 insertions(+), 78 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 delete mode 100644 .travis/travis-ci_git-commit.sh delete mode 100644 .travis/xmllint-check.sh diff --git a/.github/scripts/validate-and-lint.sh b/.github/scripts/validate-and-lint.sh new file mode 100755 index 00000000..cfb5d5fd --- /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" \) -not -path "./git" -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 00000000..881e5068 --- /dev/null +++ b/.github/scripts/validate-examples.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Validate all SIRI XML examples from the examples/ directory against the SIRI 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 SIRI XML examples ..." + +if xmllint --noout --schema xsd/siri.xsd examples/*/*.xml; then + echo -e '\033[0;32mValidating SIRI XML examples succeeded\033[0m' +else + echo -e '\033[0;31mValidating SIRI 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 00000000..c9f5f8f3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master", "main", "integration" ] + pull_request: + branches: [ "master", "main", "integration" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +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 + with: + # https://github.com/marketplace/actions/add-commit#working-with-prs + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + + - 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 SIRI 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 7db6ea77..00000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: minimal - -before_script: - - sudo apt-get install -qq libxml2-utils - -script: - - bash .travis/xmllint-check.sh - -after_script: - - bash .travis/travis-ci_git-commit.sh diff --git a/.travis/travis-ci_git-commit.sh b/.travis/travis-ci_git-commit.sh deleted file mode 100644 index 896660f6..00000000 --- a/.travis/travis-ci_git-commit.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# function to make a commit on a branch in a Travis CI build -# be sure to avoid creating a Travis CI fork bomb -# see https://gist.github.com/mitchellkrogza/a296ab5102d7e7142cc3599fca634203 and https://github.com/travis-ci/travis-ci/issues/1701 -function travis-branch-commit() { - local head_ref branch_ref - head_ref=$(git rev-parse HEAD) - if [[ $? -ne 0 || ! $head_ref ]]; then - err "Failed to get HEAD reference" - return 1 - fi - branch_ref=$(git rev-parse "$TRAVIS_BRANCH") - if [[ $? -ne 0 || ! $branch_ref ]]; then - err "Failed to get $TRAVIS_BRANCH reference" - return 1 - fi - if [[ $head_ref != $branch_ref ]]; then - msg "HEAD ref ($head_ref) does not match $TRAVIS_BRANCH ref ($branch_ref)" - msg "Someone may have pushed new commits before this build cloned the repo" - return 1 - fi - if ! git checkout "$TRAVIS_BRANCH"; then - err "Failed to checkout $TRAVIS_BRANCH" - return 1 - fi - - if ! git add --all .; then - err "Failed to add modified files to git index" - return 1 - fi - # make Travis CI skip this build - if ! git commit -m "Travis CI update [skip ci]"; then - err "Failed to commit updates" - return 1 - fi - # add to your .travis.yml: `branches\n except:\n - "/travis_build-\\d+/"\n` - local git_tag=travis_build-$TRAVIS_BUILD_NUMBER - if ! git tag "$git_tag" -m "Generated tag from Travis CI build $TRAVIS_BUILD_NUMBER"; then - err "Failed to create git tag: $git_tag" - return 1 - fi - local remote=origin - if [[ $GH_TOKEN ]]; then - remote=https://$GH_TOKEN@github.com/$GH_REPO - fi - if [[ $TRAVIS_BRANCH == master ]]; then - msg "Not pushing updates to branch $TRAVIS_BRANCH" - return 0 - fi - if ! git push --quiet --follow-tags "$remote" "$TRAVIS_BRANCH" > /dev/null 2>&1; then - err "Failed to push git changes" - return 1 - fi -} - -function msg() { - echo "travis-commit: $*" -} - -function err() { - msg "$*" 1>&2 -} - -travis-branch-commit \ No newline at end of file diff --git a/.travis/xmllint-check.sh b/.travis/xmllint-check.sh deleted file mode 100644 index ac2f81b1..00000000 --- a/.travis/xmllint-check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -/usr/bin/find . -name "*.xsd" -type f | while read i; do XMLLINT_INDENT=" " xmllint --pretty 1 "$i" > "$i.pretty"; mv "$i.pretty" "$i"; done; /usr/bin/find . -name "*.xml" -type f | while read i; do XMLLINT_INDENT=" " xmllint --pretty 1 "$i" > "$i.pretty"; mv "$i.pretty" "$i"; done; /usr/bin/find . -name "*.wsdl" -type f | while read i; do XMLLINT_INDENT=" " xmllint --pretty 1 "$i" > "$i.pretty"; mv "$i.pretty" "$i"; done; -echo "finished formatting" -find examples/ -iname "*.xml" | xargs xmllint --noout --schema xsd/siri.xsd \ No newline at end of file