Skip to content

Commit 398d53e

Browse files
authored
Add git hook to check Markdown format of changed files (#275)
* Test commit to check git hook * Add git hook for the Markdown format checking * Improve git hook to detect changed by not yet commited files * Fix Markdown formatting
1 parent b3c6490 commit 398d53e

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ indent_size = 2
77
indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
10+
11+
[*{.mk,Makefile}]
12+
indent_style = tab

.github/workflows/markdown-check-format.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ jobs:
1414
- uses: actions/checkout@v3
1515
with:
1616
fetch-depth: 0
17-
# Please, make sure to enable Markdown linting in your IDE. For the Visual Studio Code editor it is
18-
# `davidanson.vscode-markdownlint` that is already specified in the `.vscode/extensions.json` file.
1917
- run: |
20-
files=$(git diff --diff-filter=ACMRT --name-only origin/${{ github.event.repository.default_branch }}.. "*.md")
21-
if [ -n "$files" ]; then
22-
image=ghcr.io/igorshubovych/markdownlint-cli@sha256:c902fc97bb4ba50cd073408e664fe00414e6e2064f0c213bafd393ea17f3a0fd # v0.32.1
23-
docker run --rm -v $PWD:/workdir $image $files --disable MD013 MD033
24-
fi
18+
BRANCH_NAME=${{ github.event.repository.default_branch }}
19+
scripts/markdown-check-format.sh

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config: githooks
2+
3+
githooks:
4+
echo "scripts/markdown-check-format.sh" > .git/hooks/pre-commit
5+
chmod +x .git/hooks/pre-commit

patterns/architect-for-flow.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ One key consideration is how best to break the system down into independent serv
1515
## Benefits
1616

1717
In high level terms, systems which are designed to maximise rapid, reliable delivery and operations:
18+
1819
* Are cost efficient: teams don't waste their time fighting the tools or working with difficult architectures
1920
* Improve business agility: these systems allow teams to respond more quickly to changes
2021
* Improve reliability: these systems are easier to understand, which leads to fewer failures and shorter recovery times
2122
* Improve team happiness: engineers are happy when the tools they work with let them get on with what they do best
2223

2324
In many cases, building a system as a set of independently running services/components has benefits:
25+
2426
* Multiple components enable parallel development work by multiple teams
2527
* Teams can work at their own cadence
2628
* Changes with each component are easier to reason about and test
@@ -35,10 +37,10 @@ In many cases, building a system as a set of independently running services/comp
3537

3638
* This pattern must not compromise quality: automation (including of quality control) is essential for safe implementation of this pattern
3739
* Architectures with multiple moving parts are more complicated. While splitting a system into multiple components is often a good idea, "too many" components can cause more harm than good. There is usually a sweet spot for how many components to break a system down into — and for small or simple systems a monolith might be better. In distributed systems:
38-
* There are more failure modes to test, since calls which go over the network can fail in more ways than simple method invocations
39-
* Versioning becomes a more complicated concern, and additional effort is required to ensure component APIs are compatible as each changes independently
40-
* Clean domain boundaries are essential for safe implementation of this pattern
41-
* Comprehensive monitoring and alerting is essential for safe implementation of this pattern
40+
* There are more failure modes to test, since calls which go over the network can fail in more ways than simple method invocations
41+
* Versioning becomes a more complicated concern, and additional effort is required to ensure component APIs are compatible as each changes independently
42+
* Clean domain boundaries are essential for safe implementation of this pattern
43+
* Comprehensive monitoring and alerting is essential for safe implementation of this pattern
4244
* Components should be built because working in that way gives benefits, not purely because the components might be reused later: if they are later reused, that's even better
4345

4446
## Details

scripts/markdown-check-format.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Check Markdown formating of all the "*.md" files that are changed and commited to the current branch.
4+
#
5+
# Usage:
6+
# $ [options] ./markdown-check-format.sh
7+
#
8+
# Options:
9+
# BRANCH_NAME=other-branch-than-main # Branch to compare with
10+
11+
# Please, make sure to enable Markdown linting in your IDE. For the Visual Studio Code editor it is
12+
# `davidanson.vscode-markdownlint` that is already specified in the `.vscode/extensions.json` file.
13+
14+
files=$((git diff --diff-filter=ACMRT --name-only origin/${BRANCH_NAME:-main}.. "*.md"; git diff --name-only "*.md") | sort | uniq)
15+
if [ -n "$files" ]; then
16+
image=ghcr.io/igorshubovych/markdownlint-cli@sha256:df7ce7cdcdb525d52a89d7aab17c507d49adceaddf2b767d3ed799c9537ded80 # v0.32.2
17+
docker run --rm \
18+
-v $PWD:/workdir \
19+
$image \
20+
$files \
21+
--disable MD013 MD033
22+
fi

0 commit comments

Comments
 (0)