Skip to content

Commit

Permalink
Added Pre-commit hooks (#33)
Browse files Browse the repository at this point in the history
# Binaries changes

- fixed awkLint should fail if lint error found
- fix megalinter check version argument order was changing behavior
- plantuml docker pull plantuml/plantuml image automatically

# Documentation

- moved most of the best practices to my-documents project
- moved TODO to my-notes personal private project

# Validation/Tooling

- Github action run pre-commit to launch all the tests
- pre-commit manual stage for full megalinter config on github actions
- make pre-commit config using locally defined pre-commit-hooks
  • Loading branch information
fchastanet authored Nov 9, 2023
1 parent d420d65 commit f5eea25
Show file tree
Hide file tree
Showing 42 changed files with 235 additions and 1,161 deletions.
81 changes: 39 additions & 42 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,59 @@ on: # yamllint disable-line rule:truthy
jobs:
linters:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
vendor:
- ubuntu
steps:
- name: Checkout Code
uses: actions/checkout@v3
- uses: actions/checkout@v3

- uses: ouzi-dev/commit-status-updater@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
name: lint
status: pending

- name: Linting - Dockerfile
run: |
set -exo pipefail
./bin/dockerLint -f checkstyle | tee logs/docker-checkstyle.xml
python-version: 3.9

- name: Linting - Shellcheck
run: |
set -exo pipefail
./bin/shellcheckLint -f checkstyle | \
tee logs/shellcheck-checkstyle.xml
- name: Install pre-commit
run: pip install pre-commit

- name: Linting - Framework
- name: update .pre-commit-config.yaml local hooks to last sha version
run: |
./bin/frameworkLint -f checkstyle --expected-warnings-count 72 |
tee logs/framework-checkstyle.xml
currentRev="$(grep -A 1 -m 1 -E "repo: \." .pre-commit-config.yaml |
grep -E 'rev:' |
sed -E -e 's/rev: (.*)$/\1/' -e 's/^[[:space:]]*//;s/[[:space:]]*$//'
)"
echo -n "${currentRev}" > /tmp/currentRev
sed -i -E -e "s/rev: ${currentRev}/rev: ${GITHUB_SHA}/g" .pre-commit-config.yaml
- name: Linting - Awk
run: |
set -exo pipefail
./bin/awkLint | tee logs/awk-checkstyle.xml
- uses: ouzi-dev/commit-status-updater@v2
with:
name: lint
status: pending

- name: build bin files + check md5
run: |
set -exo pipefail
./bin/buildBinFiles 2>&1 | tee logs/buildBinFiles.log
- name: Run pre-commit
run: pre-commit run -a --hook-stage manual

- name: check megalinter version
- name: Restore .pre-commit-config.yaml file
if: ${{ always() }}
run: |
set -exo pipefail
status=0
newVersion="$(./bin/megalinter --check-megalinter-version)" || status=$?
if [[ "${status}" != "0" ]] ; then
echo "::warning file=.mega-linter.yml,title=new version of megalinter available::${newVersion}"
fi
currentRev="$(cat /tmp/currentRev)"
sed -i -E -e "s/rev: ${GITHUB_SHA}/rev: ${currentRev}/g" .pre-commit-config.yaml
- name: Archive results
if: ${{ always() }}
continue-on-error: true
uses: actions/upload-artifact@v3
with:
name: linter-reports
path: |
logs/*.xml
logs/*.log
megalinter-reports/**
- name: Create Pull Request
if: ${{ failure() }}
uses: peter-evans/create-pull-request@v4
with:
branch: update/pre-commit-fixes
title: lint fixes
commit-message: Auto-update lint fixes
body: |
some auto fixes have been generated during pre-commit run
labels: updates

- uses: ouzi-dev/commit-status-updater@v2
if: always()
Expand Down Expand Up @@ -178,12 +175,12 @@ jobs:
pull-requests: write
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
path: artifacts

- name: Checkstyle aggregation
uses: jwgmeligmeyling/checkstyle-github-action@master
uses: lcollins/checkstyle-github-action@v2.0.0
with:
path: 'artifacts/**/*.xml'

Expand Down
117 changes: 0 additions & 117 deletions .github/workflows/mega-linter.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
##########################
## Hadolint config file ##
##########################
ignored:
- DL3018
7 changes: 7 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ JAVASCRIPT_DEFAULT_STYLE: prettier
JAVASCRIPT_ES_CONFIG_FILE: .eslintrc.js
JAVASCRIPT_ES_FILTER_REGEX_EXCLUDE: report/

YAML_V8R_FILTER_REGEX_EXCLUDE: |
(?x)(
^\.vscode/\.checkov\.yml|
^\.secretlintrc\.yml|
^\.grype\.yaml
)
JSON_JSONLINT_FILTER_REGEX_EXCLUDE: |
(?x)(
^\.vscode/settings\.json|
Expand Down
Loading

0 comments on commit f5eea25

Please sign in to comment.