Skip to content

Commit 2808b1c

Browse files
authored
Merge pull request #40 from sysprog21/enable-github-actions
Enable GitHub Actions
2 parents 02ed0b8 + a2ee304 commit 2808b1c

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

.ci/build-n-run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
function build_mod()
4+
{
5+
make all || exit 1
6+
}
7+
8+
function run_tests()
9+
{
10+
make check || exit 2
11+
}
12+
13+
build_mod
14+
run_tests

.ci/check-format.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(cpp|cc|c|h)\$")
4+
5+
CLANG_FORMAT=$(which clang-format-12)
6+
if [ $? -ne 0 ]; then
7+
CLANG_FORMAT=$(which clang-format)
8+
if [ $? -ne 0 ]; then
9+
echo "[!] clang-format not installed. Unable to check source file format policy." >&2
10+
exit 1
11+
fi
12+
fi
13+
14+
set -x
15+
16+
for file in ${SOURCES};
17+
do
18+
$CLANG_FORMAT ${file} > expected-format
19+
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
20+
done
21+
exit $($CLANG_FORMAT --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")

.ci/check-newline.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -u -o pipefail
4+
5+
ret=0
6+
show=0
7+
# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
8+
while IFS= read -rd '' f; do
9+
if file --mime-encoding "$f" | grep -qv binary; then
10+
tail -c1 < "$f" | read -r _ || show=1
11+
if [ $show -eq 1 ]; then
12+
echo "Warning: No newline at end of file $f"
13+
ret=1
14+
show=0
15+
fi
16+
fi
17+
done < <(git ls-files -z src tests/arch-test-target)
18+
19+
exit $ret

.github/workflows/main.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: main
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
validate:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout code
16+
uses: actions/checkout@v4
17+
- name: validate coding style and functionality
18+
run: |
19+
sudo apt-get install -q -y clang-format-12
20+
.ci/check-newline.sh
21+
.ci/check-format.sh
22+
.ci/build-n-run.sh
23+
shell: bash

0 commit comments

Comments
 (0)