forked from OISF/suricata
-
Notifications
You must be signed in to change notification settings - Fork 18
153 lines (145 loc) · 5.67 KB
/
formatting.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: formatting-check
on:
push:
# Only run on pushes to pull request branches
branches-ignore:
- 'master'
- 'master-*'
paths-ignore:
- "doc/**"
pull_request:
paths-ignore:
- "doc/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: read-all
env:
DEBIAN_FRONTEND: "noninteractive"
jobs:
# Checking for correct formatting of branch for C code changes
check-formatting:
name: Formatting Check (clang 14)
runs-on: ubuntu-22.04
container: ubuntu:22.04
continue-on-error: false
steps:
# Cache Rust stuff.
- name: Cache cargo registry
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2
with:
path: ~/.cargo/registry
key: cargo-registry
- name: Install dependencies
run: |
apt update
apt -y install \
libpcre2-dev \
build-essential \
autoconf \
automake \
cargo \
cbindgen \
clang-format-14 \
git \
libtool \
libpcap-dev \
libnet1-dev \
libyaml-0-2 \
libyaml-dev \
libcap-ng-dev \
libcap-ng0 \
libmagic-dev \
libnetfilter-queue-dev \
libnetfilter-queue1 \
libnfnetlink-dev \
libnfnetlink0 \
libhiredis-dev \
libjansson-dev \
make \
rustc \
python-is-python3 \
python3 \
software-properties-common \
wget \
zlib1g \
zlib1g-dev
# Checking out the branch is not as simple as "checking out".
#
# In case master has any new commits since we branched off, github will
# automatically add a "merge commit" from our branch to master and check
# this out instead of the original last commit on the branch.
#
# This screws up git clang-format as it'll also format the "merge commit"
# and essentially report any formatting issues in the "merge commit".
# However, we really don't care about any of the new commits on master.
#
# There are supposed to be ways to use with/ref to fix that and while
# they work perfectly well for pull requests within the forked repo, none
# of the ones tried worked for pull requests from forks to the OISF repo.
#
# My patience simply ran too short to keep on looking. See follow-on
# action to manually fix this up.
- name: Checkout - might be merge commit!
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: 0
# Use last commit of branch, not potential merge commit!
#
# This works perfectly well on pull requests within forked repos, but
# not for pull requests from forks to the OISF repo as the latter one
# does not know the branch (from the forked repo). Argh.
# with:
# ref: ${{ github.head_ref }} # check out branch
# The action above is supposed to do this for us, but it doesn't appear to stick.
- run: /usr/bin/git config --global --add safe.directory /__w/suricata/suricata
# Manually ignore the merge commit as none of the with/ref things tried
# with actions/checkout seemed to work for pull requests from forks into
# the OISF repo.
- name: Peel off potential merge request
run: |
# The "merge commit" has a distinct subject that we can look for.
# If we find it, ignore it by checking out the "real last commit".
#
# Note, github uses the non-abbreviated sha for the commit subject.
#
# Commit history example in case github added merge, i.e. if you did
# git log --pretty=oneline -2:
# sha_1 Merge sha_2 into latest_sha_on_master
# sha_2 This is the real last commit on branch
echo "Last two commits on checkout:"
git log --pretty=oneline -2
last_commit_subject=$(git log --pretty=%s -1)
second_last_commit_sha=$(git log --pretty=%H -2 |tail -1)
echo "$last_commit_subject" | grep -e "^Merge $second_last_commit_sha into [0-9a-fA-F]*$" > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Last commit was a merge to master - ignore
echo "Found github merge commit - checking out real last commit instead..."
git checkout $second_last_commit_sha
else
echo "No github merge commit found"
fi
shell: bash {0}
- run: git clone https://github.com/OISF/libhtp -b 0.5.x
- run: ./autogen.sh
- run: ./configure --enable-warnings --enable-unittests
- name: Check formatting
run: |
./scripts/clang-format.sh check-branch --diffstat --show-commits >> check_formatting_log.txt 2>&1
rc=$?
if [ $rc -eq 0 ]; then
cat check_formatting_log.txt
echo "Formatting is following code style guide"
elif [ $rc -eq 1 ]; then
# limit output as it might be a lot in the worst case
tail -n 100 check_formatting_log.txt
echo "::error ::Formatting is not following code style guide!"
exit 1
else
cat check_formatting_log.txt
# use last output line as error
last_line=$(tail -n 1 check_formatting_log.txt)
echo "::error ::$last_line"
exit 1
fi
shell: bash {0}