Skip to content

Commit 255bf01

Browse files
committed
Add preliminary CI scripts
Indent all C source files with clang-format-12. At present, "make" is the only way to validate the build.
1 parent 218f9e5 commit 255bf01

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.ci/check-format.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -u -o pipefail
4+
5+
SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(c|cxx|cpp|h|hpp)\$")
6+
7+
set -x
8+
9+
for file in ${SOURCES};
10+
do
11+
clang-format-12 ${file} > expected-format
12+
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
13+
done
14+
exit $(clang-format-12 --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")

.ci/check-newline.sh

+19
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.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
detect-code-related-file-changes:
7+
runs-on: ubuntu-22.04
8+
outputs:
9+
has_code_related_changes: ${{ steps.set_has_code_related_changes.outputs.has_code_related_changes }}
10+
steps:
11+
- name: Check out the repo
12+
uses: actions/checkout@v4
13+
- name: Test changed files
14+
id: changed-files
15+
uses: tj-actions/changed-files@v44
16+
with:
17+
files: |
18+
.ci/**
19+
mk/**
20+
src/**
21+
target/**
22+
.clang-format
23+
Makefile
24+
- name: Set has_code_related_changes
25+
id: set_has_code_related_changes
26+
run: |
27+
if [[ ${{ steps.changed-files.outputs.any_changed }} == true ]]; then
28+
echo "has_code_related_changes=true" >> $GITHUB_OUTPUT
29+
else
30+
echo "has_code_related_changes=false" >> $GITHUB_OUTPUT
31+
fi
32+
33+
host-x64:
34+
needs: [detect-code-related-file-changes]
35+
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
36+
runs-on: ubuntu-22.04
37+
steps:
38+
- uses: actions/checkout@v4
39+
- name: default build
40+
run: make
41+
42+
coding-style:
43+
needs: [detect-code-related-file-changes]
44+
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
45+
runs-on: ubuntu-22.04
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: coding convention
49+
run: |
50+
sudo apt-get install -q -y clang-format-12
51+
.ci/check-newline.sh
52+
.ci/check-format.sh
53+
shell: bash

0 commit comments

Comments
 (0)