Skip to content

Commit b2ec7b3

Browse files
committed
Add preliminary CI scripts
Indent all C source files with clang-format-12 and force newline at the end of files. At present, "make" is the only way to validate the build. Later, we may perform headless validation for a file loopback device-based backend, allowing checks of the window system internals.
1 parent 2ca0bdb commit b2ec7b3

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

.ci/check-format.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+
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-18 ${file} > expected-format
12+
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
13+
done
14+
exit $(clang-format-18 --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.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
detect-code-related-file-changes:
7+
runs-on: ubuntu-24.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 repository
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+
include/**
21+
src/**
22+
backend/**
23+
apps/**
24+
tools/**
25+
.clang-format
26+
Makefile
27+
- name: Set has_code_related_changes
28+
id: set_has_code_related_changes
29+
run: |
30+
if [[ ${{ steps.changed-files.outputs.any_changed }} == true ]]; then
31+
echo "has_code_related_changes=true" >> $GITHUB_OUTPUT
32+
else
33+
echo "has_code_related_changes=false" >> $GITHUB_OUTPUT
34+
fi
35+
36+
host-x64:
37+
needs: [detect-code-related-file-changes]
38+
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
39+
runs-on: ubuntu-24.04
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: install-dependencies
43+
run: |
44+
sudo apt-get update -q -y
45+
sudo apt install libsdl2-dev libjpeg-dev libpng-dev
46+
shell: bash
47+
- name: default build
48+
run: make
49+
50+
coding-style:
51+
needs: [detect-code-related-file-changes]
52+
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
53+
runs-on: ubuntu-24.04
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: coding convention
57+
run: |
58+
sudo apt-get install -q -y clang-format-18
59+
.ci/check-newline.sh
60+
.ci/check-format.sh
61+
shell: bash

0 commit comments

Comments
 (0)