From 4a3195529c10d22b91864523821a34569aeb8788 Mon Sep 17 00:00:00 2001 From: Roelof Date: Tue, 17 Mar 2020 11:49:24 +0100 Subject: [PATCH] Add GitHub Actions (#1193) --- .github/workflows/test.yml | 23 +++++++++++++++ build/github-pull.sh | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100755 build/github-pull.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..3e7a7bd6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: "Run tests" + +on: + - push + - pull_request + +env: + FORMAT_FILE: README.md + +jobs: + test: + name: 'Validate README.md' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Validate Markdown format + run: build/validate_format.py ${FORMAT_FILE} + + - name: Validate pull request changes + run: build/github-pull.sh ${{ github.repository }} ${{ github.event.pull_request.number }} ${FORMAT_FILE} + if: github.event_name == 'pull_request' diff --git a/build/github-pull.sh b/build/github-pull.sh new file mode 100755 index 00000000..4c5c3a4b --- /dev/null +++ b/build/github-pull.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -e + +# Argument validation +if [ $# -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Assign variables +GITHUB_REPOSITORY="$1" +GITHUB_PULL_REQUEST="$2" +FORMAT_FILE="$3" + +# Move to root of project +cd "$GITHUB_WORKSPACE" + +# Determine files +FORMAT_FILE="$( realpath "${FORMAT_FILE}" )" + +# Skip if build number could not be determined +if [ -z "$GITHUB_REPOSITORY" -o -z "$GITHUB_PULL_REQUEST" ]; then + echo "No pull request and/or repository is provided" + exit 1 +fi + +# Pull changes on PR +echo "running on Pull Request #$GITHUB_PULL_REQUEST" + +# Trick the URL validator python script into not seeing this as a URL +DUMMY_SCHEME="https" +DIFF_URL="$DUMMY_SCHEME://patch-diff.githubusercontent.com/raw/$GITHUB_REPOSITORY/pull/$GITHUB_PULL_REQUEST.diff" +curl -L -o diff.txt "$DIFF_URL" + +# Construct diff +echo "------- BEGIN DIFF -------" +cat diff.txt +echo "-------- END DIFF --------" +cat diff.txt | egrep "\+" > additions.txt + +echo "------ BEGIN ADDITIONS -----" +cat additions.txt +echo "------- END ADDITIONS ------" +LINK_FILE=additions.txt + +# Validate links +echo "Running link validation..." +./build/validate_links.py "$LINK_FILE" + +# Vebosity +if [[ $? != 0 ]]; then + echo "link validation failed!" + exit 1 +else + echo "link validation passed!" +fi