diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1e4f1494..3f79d54c 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,4 +1,4 @@ -name: Build and Test Pluto +name: Build and test Pluto on: push: diff --git a/.github/workflows/find_trailing_whitespace.yml b/.github/workflows/find_trailing_whitespace.yml new file mode 100644 index 00000000..aef07fd9 --- /dev/null +++ b/.github/workflows/find_trailing_whitespace.yml @@ -0,0 +1,71 @@ +name: Check trailing whitespaces + +on: + push: + branches: [master] + paths-ignore: + - '**.png' + pull_request: + branches: [master] + paths-ignore: + - '**.png' + + +jobs: + check-trailing-whitespace: + name: Check trailing whitespaces + runs-on: [self-hosted] + steps: + - uses: actions/checkout@v2 + + # Choose the git commit to diff against for the purposes of diff-check. + # Since this workflow is triggered on both pushes and pull requests, we + # have to determine if the pull request target branch is set (which it + # will only be on the PR triggered flow). If it's not, then compare + # against the last commit. + - name: choose-commit + if: ${{ always() }} + env: + # Base ref is the target branch, in text form (not hash) + PR_BASE: ${{ github.base_ref }} + run: | + # Determine diff commit name. + if [[ -z "$PR_BASE" ]]; then + DIFF_COMMIT_NAME="HEAD^" + else + DIFF_COMMIT_NAME="$PR_BASE" + fi + echo "DIFF_COMMIT_NAME=$DIFF_COMMIT_NAME" >> $GITHUB_ENV + + # Since we did a shallow fetch for this repo, we must fetch the commit + # upon which we be diff'ing. The last step set the ref name in the + # $DIFF_COMMIT_NAME environment variable. When running the fetch, resolve + # it to the commit hash and pass that hash along to subsequent steps. + - name: git fetch base commit + continue-on-error: true + run: | + if [[ ! "$DIFF_COMMIT_NAME" == *"HEAD"* ]]; then + git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME + DIFF_COMMIT_SHA=$( git rev-parse origin/$DIFF_COMMIT_NAME ) + else + DIFF_COMMIT_SHA=$( git rev-parse $DIFF_COMMIT_NAME ) + fi + echo "DIFF_COMMIT=$DIFF_COMMIT_SHA" >> $GITHUB_ENV + + # Run 'git diff --check', comparing against the target commit hash. If + # diff check fixed anything, fail and output a patch. + - name: diff-check + shell: bash + working-directory: ${{github.workspace}} + run: | + git diff --ignore-submodules --check $DIFF_COMMIT + echo "git diff --check found no whitespace problems" + exit 0 + +# Cancel workflows when new commit is pushed to a branch other than master. +concurrency: + # Use github.run_id on master branch. + # Use github.event.pull_request.number on pull requests, so it's unique per pull request. + # Use github.ref on other branches, so it's unique per branch. + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_id || github.event.pull_request.number || github.ref }} + cancel-in-progress: true diff --git a/README.md b/README.md index 2d14a6d7..4e89dc0c 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ test](https://github.com/bondhugula/pluto/actions/workflows/build_and_test.yml/b [![Check format with clang-format](https://github.com/bondhugula/pluto/actions/workflows/clang_format.yml/badge.svg)](https://github.com/bondhugula/pluto/actions/workflows/clang_format.yml) +[![Find trailing whitespace](https://github.com/bondhugula/pluto/actions/workflows/find_trailing_whitespace.yml/badge.svg)](https://github.com/bondhugula/pluto/actions/workflows/find_trailing_whitespace.yml) + ## License Pluto and libpluto are available under the MIT LICENSE. Please see the file