Skip to content

Commit bcb5932

Browse files
authored
Initial commit
0 parents  commit bcb5932

File tree

18 files changed

+487
-0
lines changed

18 files changed

+487
-0
lines changed

.github/workflows/initialisation.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Initialise repo
2+
3+
on: [push]
4+
5+
permissions: write-all
6+
7+
jobs:
8+
check_secret_ingredients:
9+
runs-on: ubuntu-latest
10+
env:
11+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
12+
steps:
13+
- name: PAT Secret is set
14+
run: |
15+
[ ! $PERSONAL_ACCESS_TOKEN = "" ]
16+
17+
setup_repo:
18+
runs-on: ubuntu-latest
19+
needs: check_secret_ingredients
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
24+
# only take the HEAD from template (not the history aswell)
25+
fetch-depth: 0
26+
ref: ${{ github.head_ref }}
27+
- name: set_project_name
28+
env:
29+
REPOSITORY_NAME: ${{ github.event.repository.name }}
30+
REPOSITORY_URL: ${{ github.event.repository.url }}
31+
run: |
32+
mv includes/{PROJECT_NAME} includes/${REPOSITORY_NAME}
33+
mv includes/${REPOSITORY_NAME}/{PROJECT_NAME}.h includes/${REPOSITORY_NAME}/${REPOSITORY_NAME}.h
34+
mv Project.md README.md
35+
sed -i "s/PROJECT_NAME/${REPOSITORY_NAME}/g" includes/${REPOSITORY_NAME}/${REPOSITORY_NAME}.h
36+
sed -i "s/{PROJECT_NAME}/${REPOSITORY_NAME}/g" src/main.c make_settings/settings.mk README.md .gitignore src/utility/some-file.c tests/unit_tests/some-test.c
37+
sed -i "s!{REPOSITORY_URL}!${REPOSITORY_URL}!g" README.md
38+
rm -f .github/workflows/initialisation.yaml
39+
- uses: stefanzweifel/git-auto-commit-action@v4
40+
with:
41+
commit_message: "Initial project setup"
42+
push_options: --force
43+
44+
protect_main_branch:
45+
needs: setup_repo
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Setup Branch Protection
49+
uses: actions/github-script@v6
50+
with:
51+
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
52+
script: |
53+
github.rest.repos.updateBranchProtection({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
branch: "main",
57+
required_status_checks: {
58+
strict: true,
59+
contexts: []
60+
},
61+
enforce_admins: false,
62+
required_pull_request_reviews: {
63+
dismiss_stale_reviews: false,
64+
require_code_owner_reviews: false,
65+
required_approving_review_count: 1
66+
},
67+
restrictions: null,
68+
});

.github/workflows/tests.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: C/C++ CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
11+
linux:
12+
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
submodules: recursive
20+
21+
- name: Update version
22+
run: sudo apt-get update
23+
- name: Install Criterion
24+
run: sudo apt-get install libcriterion-dev
25+
- name: Install Additional libraries
26+
run: sudo apt-get install libbsd-dev
27+
- name: Build project
28+
run: make
29+
- name: Build unit tests/run_tests.sh
30+
run: make unit_test_build
31+
- name: Run unit test
32+
run: sh tests/unit_tests/run_tests.sh
33+
34+
macos:
35+
36+
runs-on: macos-latest
37+
timeout-minutes: 5
38+
39+
steps:
40+
- uses: actions/checkout@v3
41+
with:
42+
submodules: recursive
43+
44+
- name: Update version
45+
run: brew update
46+
- name: Install Criterion
47+
run: brew install criterion
48+
- name: Build project
49+
run: make
50+
- name: Build unit tests/run_tests.sh
51+
run: make unit_test_build
52+
- name: Run unit test
53+
run: sh tests/unit_tests/run_tests.sh

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
ft_ls
39+
40+
# Debug files
41+
*.dSYM/
42+
*.su
43+
*.idb
44+
*.pdb
45+
46+
# Kernel Module Compile Results
47+
*.mod*
48+
*.cmd
49+
.tmp_versions/
50+
modules.order
51+
Module.symvers
52+
Mkfile.old
53+
dkms.conf
54+
55+
# vscode...
56+
.vscode
57+
58+
# build folder
59+
.obj
60+
bin
61+
{PROJECT_NAME}
62+
!includes/{PROJECT_NAME}/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libkm"]
2+
path = libkm
3+
url = https://github.com/K1ngmar/libkm.git

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Ingmar Kole
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
SETTINGS_DIR := make_settings
2+
3+
include $(SETTINGS_DIR)/src.mk
4+
include $(SETTINGS_DIR)/settings.mk
5+
include $(SETTINGS_DIR)/colors.mk
6+
7+
all: $(NAME)
8+
9+
# Compilation
10+
11+
$(NAME): $(LIBKM) $(OBJ)
12+
@echo "$(COLOR_GREEN)Creating $(NAME) executable...$(COLOR_RESET)"
13+
@$(CC) -o $@ $(OBJ) $(LIBKM_LIB) $(LFLAGS) $(CFLAGS)
14+
15+
-include $(DEPENDENCIES)
16+
17+
$(OBJ): $(ODIR)/%.o: $(SDIR)/%.c
18+
@mkdir -p $(@D)
19+
@echo "$(COLOR_LBLUE)Compiling... $(COLOR_BLUE)$<$(COLOR_RESET)"
20+
@$(CC) -c -o $@ $< $(CFLAGS) -MMD -MP $(IFLAGS)
21+
22+
$(LIBKM):
23+
@$(MAKE) -C $(LIBKM_LOCATION)
24+
25+
# Clean up
26+
27+
clean:
28+
@echo "$(COLOR_YELLOW)clean $(NAME)... $(COLOR_RESET)"
29+
@$(MAKE) clean -C $(LIBKM_LOCATION)
30+
@printf "$(COLOR_RED)"
31+
$(RM) -r $(ODIR)
32+
@printf "$(COLOR_RESET)"
33+
34+
fclean: clean
35+
@echo "$(COLOR_YELLOW)force clean $(NAME)... $(COLOR_RESET)"
36+
@$(MAKE) fclean -C $(LIBKM_LOCATION)
37+
@printf "$(COLOR_RED)"
38+
$(RM) $(NAME)
39+
$(RM) -rf $(UNIT_BIN)
40+
@printf "$(COLOR_RESET)"
41+
42+
re: fclean
43+
@$(MAKE) re -C $(LIBKM_LOCATION)
44+
@$(MAKE) all
45+
46+
# Unit tests
47+
48+
$(UNIT_DIR)/bin/%: $(UNIT_DIR)/%.c
49+
@mkdir -p $(UNIT_DIR)/bin
50+
@echo "$(COLOR_LBLUE)Compiling tests... $(COLOR_BLUE)$<$(COLOR_RESET)"
51+
@$(CC) $(CFLAGS) $(IFLAGS) $< $(UNIT_OBJ) -o $@ -lcriterion $(LIBKM_LIB)
52+
53+
unit_test_build: $(NAME) $(UNIT_DIR) $(UNIT_BIN)
54+
55+
unit_test: unit_test_build
56+
@sh $(UNIT_DIR)/run_tests.sh
57+
58+
# Debugging
59+
debug: fclean
60+
@echo "$(COLOR_YELLOW)Building $(NAME) debug... $(COLOR_RESET)"
61+
@$(MAKE) debug -C $(LIBKM_LOCATION)
62+
@$(MAKE) DEBUG=1
63+
64+
leaks: fclean
65+
@echo "$(COLOR_YELLOW)Building $(NAME) leaks... $(COLOR_RESET)"
66+
@$(MAKE) leaks -C $(LIBKM_LOCATION)
67+
@$(MAKE) LEAKS=1
68+
69+
fsanitize: fclean
70+
@echo "$(COLOR_YELLOW)Building $(NAME) fsanitize... $(COLOR_RESET)"
71+
@$(MAKE) fsanitize -C $(LIBKM_LOCATION)
72+
@$(MAKE) FSANITIZE=1
73+
74+
# Phony
75+
.PHONY: debug fsanitize test clean fclean re

Project.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ✔️ {PROJECT_NAME}
2+
An awesome description of your ✨ amazing ✨ C project!
3+
4+
# 📥 Installation
5+
```bash
6+
# Clone the repository
7+
$ git clone --recurse-submodules {REPOSITORY_URL}
8+
9+
# Build the project
10+
$ make -C {PROJECT_NAME}
11+
12+
# Run the program!
13+
$ ./{PROJECT_NAME}/{PROJECT_NAME}
14+
```
15+
16+
# 🧡 Project template
17+
This project was hatched from an awesome C project template created with ❤️ by [K1ngmar](https://github.com/K1ngmar).
18+
Check out the template [here!](https://github.com/K1ngmar/C-project-template)

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ❤️ C project template
2+
Are you tired of manually copying, pasting and renaming files when you start a new project? Look no further because setting up C project just became easy!
3+
4+
## ❓ How to easily setup your C projects?
5+
6+
1. Create a new repository by clicking use this template on this repository.
7+
8+
2. Create a [Personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with write rights.
9+
10+
3. On the newly generated repository go to `settings->Secrets and variables->Actions` and create a secret called `PERSONAL_ACCESS_TOKEN`, and paste your token in the secret textbox.
11+
12+
4. On your repository, go to `Actions`, click on the last failed job and rerun the the failed jobs.
13+
14+
5. Clone your project!
15+
```bash
16+
# make sure you use --recurse-submodules when cloning
17+
git clone --recurse-submodules https://github.com/you/your-repo
18+
19+
# or if you already cloned without --recurse-submodules
20+
cd your-repo && git submodule init && git submodule update
21+
```
22+
23+
6. Enjoy your fully setup project! It really is that easy!
24+
25+
## 🙋 What does it do?
26+
27+
- Setup your project, with custom filenames, etc.
28+
- Protect your main branch!
29+
- Setup automated unit testing with github actions!
30+
- License your project!
31+
- Reduce your headaches!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
#ifndef PROJECT_NAME_H
3+
# define PROJECT_NAME_H
4+
5+
#include <stdbool.h>
6+
7+
bool some_function(bool val);
8+
9+
#endif

libkm

Submodule libkm added at 2e1e699

0 commit comments

Comments
 (0)