From 3319028ef11cb346382cb6c119b895fb74c7c575 Mon Sep 17 00:00:00 2001 From: Florian Heilmann Date: Thu, 14 Nov 2019 22:23:39 +0100 Subject: [PATCH] Add john--'s travis scripts --- .travis.yml | 15 +++++++++++ travis_scripts/ci-build.sh | 38 ++++++++++++++++++++++++++ travis_scripts/validate-file.py | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .travis.yml create mode 100644 travis_scripts/ci-build.sh create mode 100644 travis_scripts/validate-file.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..41564bfea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +# This is a travis-ci.org continuous integration configuration file. +language: node_js +node_js: + - 12 + +cache: + npm: true + directories: + - travis_cache + +before_install: + - chmod +x ./travis_scripts/ci-build.sh + - npm install remark-cli remark-validate-links + +script: ./travis_scripts/ci-build.sh diff --git a/travis_scripts/ci-build.sh b/travis_scripts/ci-build.sh new file mode 100644 index 000000000..65cd75f46 --- /dev/null +++ b/travis_scripts/ci-build.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +BASE_DIR=${PWD} +CACHE_DIR=${PWD}/travis_cache + +chmod +x ${BASE_DIR}/travis_scripts/*.py + +ADMESH_DIR=${CACHE_DIR}/admesh-0.98.4 +mkdir -p ${CACHE_DIR} +cd ${CACHE_DIR} +if [ ! -d ${ADMESH_DIR} ]; then + echo "Admesh cache miss; fetching and building ..." + wget https://github.com/admesh/admesh/releases/download/v0.98.4/admesh-0.98.4.tar.gz + tar -zxf admesh-0.98.4.tar.gz + cd ${ADMESH_DIR} + ./configure + make + chmod +x admesh +fi +cd ${BASE_DIR} +sudo ln -s ${ADMESH_DIR}/admesh /usr/bin/admesh + +if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + # Compare branch against master + git remote set-branches --add origin master + git fetch + git diff --name-only --diff-filter=AMR origin/master | xargs -n 1 -I {} ${BASE_DIR}/travis_scripts/validate-file.py ${BASE_DIR}/{} +else + # Compare head against the branch to merge into (PR) + git diff --name-only --diff-filter=AMR -R HEAD origin/${TRAVIS_BRANCH} | xargs -n 1 -I {} ${BASE_DIR}/travis_scripts/validate-file.py ${BASE_DIR}/{} +fi + +cd ${BASE_DIR} + +# Validate all markdown files (eg, README.md). +remark -u validate-links --no-stdout --frail . + + diff --git a/travis_scripts/validate-file.py b/travis_scripts/validate-file.py new file mode 100644 index 000000000..cf8317fa5 --- /dev/null +++ b/travis_scripts/validate-file.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 +import subprocess, re, os, sys, getopt + +def read_param(text, parameter): + matches = re.search("(" + parameter + ")\s+\:\s+(\d+)", text) + #print(matches) + if matches: + # The decimal group + return int(matches.group(2)) + else: + # Uh oh, no match + print ("Could not find {0}".format(parameter)) + exit(1) + +def assert_param_threshold(result, parameter, threshold): + param_val = read_param(result, parameter) + if param_val > threshold: + print ("!! Detected \"{0}\" value of {1}".format(parameter, param_val)) + exit(1) + #else: + #print ("{0} value OK".format(parameter)) + +def process_stl(filename): + cmd = "admesh \"{0}\"".format(filename) + print ("Validating STL {0}".format(filename)) + result = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE) + output = str(result.stdout) + + assert_param_threshold(output, "Edges fixed", 0) + assert_param_threshold(output, "Backwards edges", 0) + assert_param_threshold(output, "Degenerate facets", 0) + assert_param_threshold(output, "Facets removed", 0) + assert_param_threshold(output, "Facets added", 0) + assert_param_threshold(output, "Facets reversed", 0) + +def process_markdown(filename): + cmd = "remark -u validate-links --no-stdout --frail \"{0}\"".format(filename) + print ("Validating Markdown {0}".format(filename)) + subprocess.run(cmd, shell=True, check=True) + +def main(argv): + argument = " ".join(sys.argv[1:]) + + if argument.lower().endswith(".stl"): + process_stl(argument) + +if __name__ == "__main__": + main(sys.argv[1:])