Skip to content

Commit 9b9c48f

Browse files
committed
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.
1 parent cbadaa5 commit 9b9c48f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Stop on errors
4+
set -e
5+
6+
# Log information about the run of this check.
7+
echo "Pull request's base branch is: ${BASE_BRANCH}"
8+
echo "Pull request's merge branch is: ${MERGE_BRANCH}"
9+
echo "Pull request's source branch is: ${GITHUB_HEAD_REF}"
10+
clang-format-7 --version
11+
12+
# The checkout action leaves us in detatched head state. The following line
13+
# names the checked out commit, for simpler reference later.
14+
git checkout -b ${MERGE_BRANCH}
15+
16+
# Build list of files to ignore
17+
while read file ; do EXCLUDES+="':(top,exclude)$file' " ; done < .clang-format-ignore
18+
19+
# Make sure we can refer to ${BASE_BRANCH} by name
20+
git checkout ${BASE_BRANCH}
21+
git checkout ${MERGE_BRANCH}
22+
23+
# Find the commit on which the PR is based.
24+
MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${MERGE_BRANCH})
25+
echo "Checking for formatting errors introduced since $MERGE_BASE"
26+
27+
# Do the checking. "eval" is used so that quotes (as inserted into $EXCLUDES
28+
# above) are not interpreted as parts of file names.
29+
eval git-clang-format-7 --binary clang-format-7 $MERGE_BASE -- $EXCLUDES
30+
git diff > formatted.diff
31+
if [[ -s formatted.diff ]] ; then
32+
echo 'Formatting error! The following diff shows the required changes'
33+
echo 'Use the raw log to get a version of the diff that preserves spacing'
34+
cat formatted.diff
35+
exit 1
36+
fi
37+
echo 'No formatting errors found'
38+
exit 0

.github/workflows/pull-request-checks.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,23 @@ jobs:
124124

125125
- name: Build cbmc
126126
run: "%SCRIPT_DIR%\\build-cbmc.bat"
127+
128+
check-clang-format:
129+
runs-on: ubuntu-20.04
130+
steps:
131+
- uses: actions/checkout@v2
132+
with:
133+
submodules: true
134+
fetch-depth: 0
135+
- name: Fetch dependencies
136+
env:
137+
# This is needed in addition to -yq to prevent apt-get from asking for
138+
# user input
139+
DEBIAN_FRONTEND: noninteractive
140+
run: |
141+
sudo apt-get install -yq clang-format-7
142+
- name: Check updated lines of code match clang-format-7 style
143+
env:
144+
BASE_BRANCH: ${{ github.base_ref }}
145+
MERGE_BRANCH: ${{ github.ref }}
146+
run: ./.github/workflows/pull-request-check-clang-format.sh

0 commit comments

Comments
 (0)