Skip to content

Commit e521110

Browse files
Feature/more pre commit checks (#7)
* Added pre-commit enforced branch protection. * added a lot of new pre-commit checks The following checks were added: - name: flake-checker description: Run health checks on your flake-powered Nix projects. - name: check-shebang-scripts-are-executable description: Ensure that all (non-binary) files with a shebang are executable - name: detect-private-keys description: Detect the presence of private keys. - name: check-symlinks description: Checks for broken symlinks in the repository. - name: gitlint description: Linting for your git commit messages The following checks were not added: - name: lychee description: Checks for broken links in Markdown files. because: (is broken) checking links is not possible in the sandbox. - name: editorconfig-checker description: Verify that the files are in harmony with the .editorconfig. because: (is clunky) might cause formatters to fight
1 parent 1c95540 commit e521110

8 files changed

Lines changed: 121 additions & 34 deletions

File tree

.config/pre-commit.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
# See https://github.com/cachix/git-hooks.nix/blob/fa466640195d38ec97cf0493d6d6882bc4d14969/modules/hooks.nix
12
{
23
src = ./..;
34
hooks = {
45

6+
# Run health checks on your flake-powered Nix projects.
7+
flake-checker = {
8+
enable = true;
9+
stages = [
10+
"pre-push"
11+
"manual"
12+
];
13+
};
14+
515
# Check if the flake passes all it's checks. (takes a long time)
616
nix-flake-check = {
717
enable = true;
@@ -14,6 +24,44 @@
1424
];
1525
};
1626

27+
# Ensure that all (non-binary) files with a shebang are executable.
28+
check-shebang-scripts-are-executable = {
29+
enable = true;
30+
stages = [
31+
"pre-commit"
32+
"pre-push"
33+
"manual"
34+
];
35+
};
36+
37+
# Detect the presence of private keys.
38+
detect-private-keys = {
39+
enable = true;
40+
stages = [
41+
"pre-commit"
42+
"pre-push"
43+
"manual"
44+
];
45+
};
46+
47+
# Checks for broken symlinks in the repository.
48+
check-symlinks = {
49+
enable = true;
50+
stages = [
51+
"pre-commit"
52+
"pre-push"
53+
"manual"
54+
];
55+
};
56+
57+
# Linting for your git commit messages"
58+
gitlint = {
59+
enable = true;
60+
stages = [
61+
"commit-msg"
62+
];
63+
};
64+
1765
# disallows commits to certain branches.
1866
no-commit-to-branch = {
1967
enable = true;
@@ -77,5 +125,26 @@
77125
];
78126
};
79127

128+
#! Requires an internet connection while in sandbox, thus does not work.
129+
# # Checks for broken links in Markdown files.
130+
# lychee = {
131+
# enable = true;
132+
# stages = [
133+
# "pre-commit"
134+
# "pre-push"
135+
# "manual"
136+
# ];
137+
# };
138+
139+
#! Does not work properly, especially because formatters fight.
140+
# # Verify that the files are in harmony with the `.editorconfig`.
141+
# editorconfig-checker = {
142+
# enable = true;
143+
# stages = [
144+
# "pre-commit"
145+
# "pre-push"
146+
# "manual"
147+
# ];
148+
# };
80149
};
81150
}

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
}
2323
}
2424
}
25-
}
25+
}

.editorconfig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ indent_style = space
1313
trim_trailing_whitespace = true
1414
indent_size = 4
1515

16-
1716
#| Markdown – 2-space is typical and trailing whitespace must be kept
1817

1918
[*.md]
@@ -103,3 +102,22 @@ indent_size = 2
103102

104103
[*.nix]
105104
indent_size = 2
105+
106+
107+
#| Lock files and Licence files are generated and should not be checked
108+
109+
[*.lock]
110+
charset = unset
111+
end_of_line = unset
112+
insert_final_newline = unset
113+
trim_trailing_whitespace = unset
114+
115+
[LICENSE]
116+
end_of_line = unset
117+
insert_final_newline = unset
118+
trim_trailing_whitespace = unset
119+
120+
[LICENSE*]
121+
end_of_line = unset
122+
insert_final_newline = unset
123+
trim_trailing_whitespace = unset

.envrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# automatically loads a Nix Development environment if nix is installed.
2-
if has nix; then
3-
use flake .
2+
if has nix; then
3+
use flake .
44
fi

.github/workflows/automerge-dependabot.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
permissions:
1111
contents: write # To push merges
1212
pull-requests: write # To comment, approve, or merge PRs
13-
13+
1414
jobs:
1515
automerge:
1616
runs-on: ubuntu-latest
@@ -30,28 +30,28 @@ jobs:
3030
echo "Invalid PR title: expected exactly two semantic versions" >&2
3131
exit 1
3232
fi
33-
33+
3434
VERSION_FROM="${VERSIONS[0]}"
3535
VERSION_TO="${VERSIONS[1]}"
36-
36+
3737
IFS='.' read -r MAJOR_FROM MINOR_FROM PATCH_FROM <<< "$VERSION_FROM"
3838
IFS='.' read -r MAJOR_TO MINOR_TO PATCH_TO <<< "$VERSION_TO"
39-
39+
4040
MAJOR_FROM=$(echo $VERSION_FROM | cut -d. -f1)
4141
MINOR_FROM=$(echo $VERSION_FROM | cut -d. -f2)
4242
PATCH_FROM=$(echo $VERSION_FROM | cut -d. -f3)
43-
43+
4444
echo "MAJOR_FROM: $MAJOR_FROM, MINOR_FROM: $MINOR_FROM, PATCH_FROM: $PATCH_FROM"
45-
45+
4646
MAJOR_TO=$(echo $VERSION_TO | cut -d. -f1)
4747
MINOR_TO=$(echo $VERSION_TO | cut -d. -f2)
4848
PATCH_TO=$(echo $VERSION_TO | cut -d. -f3)
49-
49+
5050
echo "MAJOR_TO: $MAJOR_TO, MINOR_TO: $MINOR_TO, PATCH_TO: $PATCH_TO"
51-
52-
if [ "$MAJOR_FROM" = "$MAJOR_TO" ] && [ "$MINOR_FROM" = "$MINOR_TO" ]; then
51+
52+
if [ "$MAJOR_FROM" = "$MAJOR_TO" ] && [ "$MINOR_FROM" = "$MINOR_TO" ]; then
5353
echo "patch_update=true"
54-
else
54+
else
5555
echo "patch_update=false"
5656
fi
5757
- name: Auto-merge PR (by bypassing status checks)

.github/workflows/deploy-github-pages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on:
55
push:
66
branches: ["main"]
77
paths:
8-
- "**/.MD"
9-
- "**/.md"
10-
8+
- "**/.MD"
9+
- "**/.md"
10+
1111
# Allows you to run this workflow manually from the Actions tab
1212
workflow_dispatch:
1313

.github/workflows/nix-flake-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- main
88
push:
99
branches:
10-
- main
10+
- main
1111

1212
jobs:
1313
nix-flake-check:

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33
<br>
44
<div align="center">
55
<a href="https://nixos.org">
6-
<img src="https://img.shields.io/badge/Built_With-Nix-5277C3.svg?style=flat&logo=nixos&labelColor=73C3D5" alt="Built with Nix"/>
6+
<img src="https://img.shields.io/badge/Built_With-Nix-5277C3.svg?style=flat&logo=nixos&labelColor=73C3D5" alt="Built with Nix"/>
77
</a>
88
<a href="https://containers.dev/">
9-
<img src="https://img.shields.io/badge/devcontainer-provided-green?style=flat" alt="devcontainer provided"/>
9+
<img src="https://img.shields.io/badge/devcontainer-provided-green?style=flat" alt="devcontainer provided"/>
1010
</a>
1111
<!--~ Repository CI/CD ~-->
1212
<a href="https://github.com/school-Tygo-van-den-Hurk/template/actions/workflows/deploy-github-pages.yml">
13-
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Deploy%20GitHub%20Pages/badge.svg?style=flat" alt="GitHub deployment status" />
13+
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Deploy%20GitHub%20Pages/badge.svg?style=flat" alt="GitHub deployment status" />
1414
</a>
1515
<a href="https://github.com/school-Tygo-van-den-Hurk/template/actions/workflows/nix-flake-check.yml">
16-
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Nix%20Flake%20Checks/badge.svg?style=flat" alt="GitHub tests status" />
16+
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Nix%20Flake%20Checks/badge.svg?style=flat" alt="GitHub tests status" />
1717
</a>
1818
<a href="https://github.com/school-Tygo-van-den-Hurk/template/actions/workflows/automerge-dependabot.yml">
19-
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Automerge%20Dependabot/badge.svg?style=flat" alt="GitHub dependabot automerge status" />
19+
<img src="https://github.com/school-Tygo-van-den-Hurk/template/workflows/Automerge%20Dependabot/badge.svg?style=flat" alt="GitHub dependabot automerge status" />
2020
</a>
2121
<!--~ Repository Statistics ~-->
2222
<a href="https://github.com/school-Tygo-van-den-Hurk/template/graphs/contributors">
23-
<img src="https://img.shields.io/github/contributors/school-Tygo-van-den-Hurk/template?style=flat" alt="Contributors"/>
23+
<img src="https://img.shields.io/github/contributors/school-Tygo-van-den-Hurk/template?style=flat" alt="Contributors"/>
2424
</a>
2525
<a href="https://github.com/school-Tygo-van-den-Hurk/template/blob/main/LICENSE">
26-
<img src="https://img.shields.io/github/license/school-Tygo-van-den-Hurk/template?style=flat" alt="The Eclipse Public License v2.0 badge" />
26+
<img src="https://img.shields.io/github/license/school-Tygo-van-den-Hurk/template?style=flat" alt="The Eclipse Public License v2.0 badge" />
2727
</a>
2828
<a href="https://github.com/school-Tygo-van-den-Hurk/template/commit">
29-
<img src="https://badgen.net/github/commits/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub commits" />
29+
<img src="https://badgen.net/github/commits/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub commits" />
3030
</a>
31-
<a href="https://github.com/school-Tygo-van-den-Hurk/template/commit">
32-
<img src="https://badgen.net/github/last-commit/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub latest commit" />
31+
<a href="https://github.com/school-Tygo-van-den-Hurk/template/commit">
32+
<img src="https://badgen.net/github/last-commit/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub latest commit" />
3333
</a>
3434
<a href="https://github.com/school-Tygo-van-den-Hurk/template/network/">
35-
<img src="https://badgen.net/github/forks/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub forks" />
35+
<img src="https://badgen.net/github/forks/school-Tygo-van-den-Hurk/template?style=flat" alt="GitHub forks" />
3636
</a>
3737
<a href="https://github.com/school-Tygo-van-den-Hurk/template/">
38-
<img src="https://img.shields.io/github/languages/count/school-Tygo-van-den-Hurk/template?style=flat" alt="amount of languages in the repository" />
38+
<img src="https://img.shields.io/github/languages/count/school-Tygo-van-den-Hurk/template?style=flat" alt="amount of languages in the repository" />
3939
</a>
4040
<a href="https://github.com/school-Tygo-van-den-Hurk/template/stargazers">
41-
<img src="https://img.shields.io/github/stars/school-Tygo-van-den-Hurk/template?style=flat" alt="amount of stars" />
41+
<img src="https://img.shields.io/github/stars/school-Tygo-van-den-Hurk/template?style=flat" alt="amount of stars" />
4242
</a>
4343
<!--~ Repository Updates ~-->
4444
<a href="https://github.com/school-Tygo-van-den-Hurk/template/pulse">
45-
<img src="https://img.shields.io/github/created-at/school-Tygo-van-den-Hurk/template?style=flat" alt="created at badge" />
45+
<img src="https://img.shields.io/github/created-at/school-Tygo-van-den-Hurk/template?style=flat" alt="created at badge" />
4646
</a>
4747
<a href="https://github.com/school-Tygo-van-den-Hurk/template/release">
48-
<img src="https://img.shields.io/github/release/school-Tygo-van-den-Hurk/template?style=flat&display_name=release" alt="newest release" />
48+
<img src="https://img.shields.io/github/release/school-Tygo-van-den-Hurk/template?style=flat&display_name=release" alt="newest release" />
4949
</a>
5050
<a href="https://github.com/school-Tygo-van-den-Hurk/template/">
51-
<img src="https://img.shields.io/github/repo-size/school-Tygo-van-den-Hurk/template?style=flat" alt="the size of the repository" />
51+
<img src="https://img.shields.io/github/repo-size/school-Tygo-van-den-Hurk/template?style=flat" alt="the size of the repository" />
5252
</a>
5353
</div>
5454
<br>

0 commit comments

Comments
 (0)