Skip to content

feat: introduce pre-commit to lint code #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2023
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: 2 additions & 1 deletion .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: tj-actions/[email protected]
- name: Build & Test (Publish)
run: |
pip install pre-commit && pre-commit install
docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}'
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ "$file" == *"Dockerfile" ]]; then
Expand All @@ -40,7 +41,7 @@ jobs:
elif [[ "$tag" == *"alpine"* ]]; then
docker run clang-tools:$tag clang-format --version | grep -E "clang-format version"
docker run clang-tools:$tag clang-tidy --version | grep "LLVM version"
else
else
docker run clang-tools:$tag clang-format --version | grep -E "clang-format version $tag"
docker run clang-tools:$tag clang-tidy --version | grep "LLVM version $tag"
fi
Expand Down
4 changes: 0 additions & 4 deletions .hadolint.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: detect-private-key
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
args:
[
--ignore,DL3008,
--ignore,DL3018,
--ignore,SC2086,
]
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion 13/sources.list.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
2 changes: 1 addition & 1 deletion 14/sources.list.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
2 changes: 1 addition & 1 deletion 15/sources.list.kinetic
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ kinetic-security main restricted
deb http://security.ubuntu.com/ubuntu/ kinetic-security universe
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security universe
deb http://security.ubuntu.com/ubuntu/ kinetic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security multiverse
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ prune: ## clean all that is not actively used
@docker system prune -af
@echo "== Prune ✅ image(s) Succeeded"

lint: check-file ## Lint the $(DOCKERFILE) content
@echo "== Linting $(DOCKERFILE)..."
@echo "Output Lint results"
@docker run --rm -i -v $$PWD/.hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint hadolint - < $(DOCKERFILE)
lint: ## Lint code
@echo "== Running pre-commit against all-files..."
@pre-commit run --all-files
@echo "== Lint ✅ Succeeded"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $ docker run -v $PWD:/src xianpengshen/clang-tools:12 clang-format --dry-run -i
$ docker run xianpengshen/clang-tools:12 clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 12.0.0

Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: cascadelake
Expand Down Expand Up @@ -83,7 +83,7 @@ $ docker run clang-tools clang-tidy helloworld.c \
-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-cplusplus-*,clang-analyzer-*,cppcoreguidelines-*
```

### Use specific tag in `Dockerfile`
### Use specific tag in `Dockerfile`

If you want to use a specific tag of clang-tools, you can build image by passing `--build-arg`

Expand Down
4 changes: 2 additions & 2 deletions all/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN set -ex \
&& apt-get update \
&& for CLANG_VERSION in $CLANG_VERSIONS; do \
apt-get --no-install-recommends -y install clang-format-$CLANG_VERSION clang-tidy-$CLANG_VERSION; done \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*


ENV CLANG_VERSIONS="16 15 14 13"
Expand All @@ -26,7 +26,7 @@ RUN set -ex \
./llvm.sh $CLANG_VERSION \
&& apt-get --no-install-recommends -y install clang-format-$CLANG_VERSION clang-tidy-$CLANG_VERSION; done \
&& rm llvm.sh \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*


# Integrity testing
Expand Down
2 changes: 1 addition & 1 deletion all/sources.list.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
2 changes: 1 addition & 1 deletion demo/compile_commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"command": "/usr/bin/g++ -Wall -Werror helloworld.cpp",
"file": "/helloworld.cpp"
}
]
]