Skip to content

Commit 48b45a3

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 48b45a3

File tree

9 files changed

+92
-6
lines changed

9 files changed

+92
-6
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

src/diskimg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ int diskimg_init(struct diskimg *diskimg, const char *file_path)
3636
void diskimg_exit(struct diskimg *diskimg)
3737
{
3838
close(diskimg->fd);
39-
}
39+
}

src/virtio-blk.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ void virtio_blk_exit(struct virtio_blk_dev *dev)
194194
virtio_pci_exit(&dev->virtio_pci_dev);
195195
close(dev->irqfd);
196196
close(dev->ioeventfd);
197-
}
197+
}

src/virtio-blk.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ void virtio_blk_init_pci(struct virtio_blk_dev *dev,
4141
struct diskimg *diskimg,
4242
struct pci *pci,
4343
struct bus *io_bus,
44-
struct bus *mmio_bus);
44+
struct bus *mmio_bus);

src/virtio-pci.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ void virtio_pci_init(struct virtio_pci_dev *dev,
5454
struct pci *pci,
5555
struct bus *io_bus,
5656
struct bus *mmio_bus);
57-
void virtio_pci_exit();
57+
void virtio_pci_exit();

src/virtq.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ void virtq_handle_avail(struct virtq *vq)
6363
virtq_complete_request(vq);
6464
if (vq->guest_event->flags == VRING_PACKED_EVENT_FLAG_ENABLE)
6565
virtq_notify_used(vq);
66-
}
66+
}

src/virtq.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ void virtq_complete_request(struct virtq *vq);
4242
void virtq_notify_used(struct virtq *vq);
4343
void virtq_deassert_irq(struct virtq *vq);
4444
void virtq_handle_avail(struct virtq *vq);
45-
void virtq_init(struct virtq *vq, void *dev, struct virtq_ops *ops);
45+
void virtq_init(struct virtq *vq, void *dev, struct virtq_ops *ops);

0 commit comments

Comments
 (0)