Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 100
12 changes: 12 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Checks: >
-*,
clang-analyzer-*,
bugprone-*,
performance-*,
readability-*,
modernize-*,
-modernize-use-trailing-return-type,
-readability-magic-numbers,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
HeaderFilterRegex: 'src/.*'
WarningsAsErrors: ''
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

on:
push:
branches: [dev, main]
pull_request:
branches: ["**"]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Build
run: make

- name: Run
run: ./hello
46 changes: 46 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

on:
push:
branches: [dev, main]
pull_request:
branches: ["**"]

jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Install clang tools
run: |
sudo apt-get update
sudo apt-get install -y clang-format clang-tidy

- name: Static analysis (clang-tidy)
run: |
find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
| xargs -I {} clang-tidy {} -- -Isrc

- name: Check formatting (clang-format)
run: |
find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
| xargs clang-format -i

- name: Commit if changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if ! git diff --cached --quiet; then
git commit -m "chore: auto-format code [skip ci]"
git push
fi
50 changes: 50 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: pre-commit

on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
workflow_call:
inputs:
working-directory:
type: string
required: false
default: '.'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: >
${{ format('pre-commit-{0}-{1}',
steps.setup-python.outputs.python-version,
hashFiles('.pre-commit-config.yaml')
) }}

- name: Install pre-commit
run: |
pip install --upgrade pip
pip install pre-commit
pre-commit install

- name: Run pre-commit hooks
working-directory: ${{ inputs.working-directory }}
run: |
git ls-files | xargs pre-commit run \
--show-diff-on-failure \
--color=always \
--files
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ dkms.conf

# debug information files
*.dwo
hello
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/google/yapf.git
rev: v0.43.0
hooks:
- id: yapf
additional_dependencies: [toml]
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: \.fits
- id: end-of-file-fixer
exclude: \.fits
- id: check-yaml
- id: debug-statements
- id: name-tests-test
exclude: conftestaux/
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.1
hooks:
- id: clang-format
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CC = gcc
CFLAGS = -Wall -Wextra -Isrc
SRCS = src/main.c src/mylib.c
TARGET = hello

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(SRCS)
$(CC) $(CFLAGS) -o $@ $^

clean:
rm -f $(TARGET)
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>
#include "mylib.h"

int main(void) {
int x = 3;
printf("%s\n", greet("World"));
return 0;
}
11 changes: 11 additions & 0 deletions src/mylib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mylib.h"
#include <stdio.h>

#define BUF_SIZE 256

static _Thread_local char buf[BUF_SIZE];

const char* greet(const char* name) {
snprintf(buf, BUF_SIZE, "Hello, %s!", name);
return buf;
}
7 changes: 7 additions & 0 deletions src/mylib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef MYLIB_H
#define MYLIB_H

/* Returns a greeting string for the given name. */
const char* greet(const char* name);

#endif /* MYLIB_H */
Loading