From 9b9c48ff84115b8d2caa1315deea97637608e892 Mon Sep 17 00:00:00 2001 From: Thomas Spriggs Date: Tue, 18 Aug 2020 18:23:08 +0100 Subject: [PATCH 1/4] Add github actions clang-format job This was formerly a Travis CI job. Setting it up using Github actions gives us a user interface which integrates into the rest of github better. This is a step towards having all jobs seup in Github actions and removing Travis. --- .../pull-request-check-clang-format.sh | 38 +++++++++++++++++++ .github/workflows/pull-request-checks.yaml | 20 ++++++++++ 2 files changed, 58 insertions(+) create mode 100755 .github/workflows/pull-request-check-clang-format.sh diff --git a/.github/workflows/pull-request-check-clang-format.sh b/.github/workflows/pull-request-check-clang-format.sh new file mode 100755 index 00000000000..cd20c756472 --- /dev/null +++ b/.github/workflows/pull-request-check-clang-format.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Stop on errors +set -e + +# Log information about the run of this check. +echo "Pull request's base branch is: ${BASE_BRANCH}" +echo "Pull request's merge branch is: ${MERGE_BRANCH}" +echo "Pull request's source branch is: ${GITHUB_HEAD_REF}" +clang-format-7 --version + +# The checkout action leaves us in detatched head state. The following line +# names the checked out commit, for simpler reference later. +git checkout -b ${MERGE_BRANCH} + +# Build list of files to ignore +while read file ; do EXCLUDES+="':(top,exclude)$file' " ; done < .clang-format-ignore + +# Make sure we can refer to ${BASE_BRANCH} by name +git checkout ${BASE_BRANCH} +git checkout ${MERGE_BRANCH} + +# Find the commit on which the PR is based. +MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${MERGE_BRANCH}) +echo "Checking for formatting errors introduced since $MERGE_BASE" + +# Do the checking. "eval" is used so that quotes (as inserted into $EXCLUDES +# above) are not interpreted as parts of file names. +eval git-clang-format-7 --binary clang-format-7 $MERGE_BASE -- $EXCLUDES +git diff > formatted.diff +if [[ -s formatted.diff ]] ; then + echo 'Formatting error! The following diff shows the required changes' + echo 'Use the raw log to get a version of the diff that preserves spacing' + cat formatted.diff + exit 1 +fi +echo 'No formatting errors found' +exit 0 diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index 3675fb5b963..25908e482ed 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -124,3 +124,23 @@ jobs: - name: Build cbmc run: "%SCRIPT_DIR%\\build-cbmc.bat" + + check-clang-format: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + - name: Fetch dependencies + env: + # This is needed in addition to -yq to prevent apt-get from asking for + # user input + DEBIAN_FRONTEND: noninteractive + run: | + sudo apt-get install -yq clang-format-7 + - name: Check updated lines of code match clang-format-7 style + env: + BASE_BRANCH: ${{ github.base_ref }} + MERGE_BRANCH: ${{ github.ref }} + run: ./.github/workflows/pull-request-check-clang-format.sh From 7c3a076da243a5e54bc90ead12ed9ef4d1b63bb4 Mon Sep 17 00:00:00 2001 From: Thomas Spriggs Date: Thu, 20 Aug 2020 14:43:13 +0100 Subject: [PATCH 2/4] Add github actions linting check This was formerly a Travis CI job. Setting it up using Github actions gives us a user interface which integrates into the rest of github better. This is a step towards having all jobs seup in Github actions and removing Travis. --- .../workflows/pull-request-check-cpplint.sh | 25 +++++++++++++++++++ .github/workflows/pull-request-checks.yaml | 20 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 .github/workflows/pull-request-check-cpplint.sh diff --git a/.github/workflows/pull-request-check-cpplint.sh b/.github/workflows/pull-request-check-cpplint.sh new file mode 100755 index 00000000000..9008a53e719 --- /dev/null +++ b/.github/workflows/pull-request-check-cpplint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Stop on errors +set -e + +# Log information about the run of this check. +echo "Pull request's base branch is: ${BASE_BRANCH}" +echo "Pull request's merge branch is: ${MERGE_BRANCH}" +echo "Pull request's source branch is: ${GITHUB_HEAD_REF}" + +# The checkout action leaves us in detatched head state. The following line +# names the checked out commit, for simpler reference later. +git checkout -b ${MERGE_BRANCH} + +# Make sure we can refer to ${BASE_BRANCH} by name +git checkout ${BASE_BRANCH} +git checkout ${MERGE_BRANCH} + +# Find the commit on which the PR is based. +MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${MERGE_BRANCH}) +echo "Checking standards of code touched since $MERGE_BASE" + +# Do the checking. +script_folder='./scripts' +$script_folder/run_diff.sh CPPLINT $MERGE_BASE diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index 25908e482ed..ebb6794cbeb 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -144,3 +144,23 @@ jobs: BASE_BRANCH: ${{ github.base_ref }} MERGE_BRANCH: ${{ github.ref }} run: ./.github/workflows/pull-request-check-clang-format.sh + + check-cpplint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + - name: Fetch dependencies + env: + # This is needed in addition to -yq to prevent apt-get from asking for + # user input + DEBIAN_FRONTEND: noninteractive + run: | + pip install unidiff + - name: Check updated lines of code meet linting standards + env: + BASE_BRANCH: ${{ github.base_ref }} + MERGE_BRANCH: ${{ github.ref }} + run: ./.github/workflows/pull-request-check-cpplint.sh From 5379a73ccc72ab57dd7c2f69fe038063e1d7fa4f Mon Sep 17 00:00:00 2001 From: Thomas Spriggs Date: Thu, 20 Aug 2020 15:15:33 +0100 Subject: [PATCH 3/4] Add string-table check in github actions This was formerly a Travis CI job. Setting it up using Github actions gives us a user interface which integrates into the rest of github better. This is a step towards having all jobs seup in Github actions and removing Travis. --- .github/workflows/pull-request-checks.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index ebb6794cbeb..7265087f52c 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -164,3 +164,10 @@ jobs: BASE_BRANCH: ${{ github.base_ref }} MERGE_BRANCH: ${{ github.ref }} run: ./.github/workflows/pull-request-check-cpplint.sh + + check-string-table: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Check for unused irep ids + run: ./scripts/string_table_check.sh From f34e22a920d9a69877d8b82455dd879036f0de10 Mon Sep 17 00:00:00 2001 From: Thomas Spriggs Date: Fri, 21 Aug 2020 18:10:33 +0100 Subject: [PATCH 4/4] Remove redundant use of `script_folder` environment variable --- .github/workflows/pull-request-check-cpplint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pull-request-check-cpplint.sh b/.github/workflows/pull-request-check-cpplint.sh index 9008a53e719..da533013a90 100755 --- a/.github/workflows/pull-request-check-cpplint.sh +++ b/.github/workflows/pull-request-check-cpplint.sh @@ -21,5 +21,4 @@ MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${MERGE_BRANCH}) echo "Checking standards of code touched since $MERGE_BASE" # Do the checking. -script_folder='./scripts' -$script_folder/run_diff.sh CPPLINT $MERGE_BASE +./scripts/run_diff.sh CPPLINT $MERGE_BASE