[CI] Add pre-commit check (#845)

* [CI] Add pre-commit check

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Add other folder for testing

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Simplify CI

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Update pre-commit

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Update job name

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Linter issues

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Fix conditionals

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Separate chart linting and pre-commit

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Change workflow name

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>

* Allow running against all files

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2021-05-01 13:27:23 +02:00 committed by GitHub
parent f5e0e308b9
commit 8394533292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 37 deletions

View File

@ -85,10 +85,7 @@ jobs:
lint:
needs:
- changes-lint
if: |
!contains(github.event.head_commit.message, '[ci-skip]')
&&
needs.changes-lint.outputs.detected == 'true'
if: "!contains(github.event.head_commit.message, '[ci-skip]') && needs.changes-lint.outputs.detected == 'true'"
name: Lint charts
runs-on: ubuntu-20.04
steps:
@ -113,24 +110,10 @@ jobs:
id: lint
run: ct lint --config .github/ct-lint.yaml
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
lint_success:
needs:
- changes-lint
- lint
if: ${{ always() }}
name: Lint successful
runs-on: ubuntu-20.04
steps:
- name: Check lint matrix status
if: ${{ !contains(github.event.head_commit.message, '[ci-skip]') && needs.changes-lint.outputs.detected == 'true' && needs.lint.result != 'success' }}
run: exit 1
unittest:
needs:
- lint_success
if: |
!contains(github.event.head_commit.message, '[ci-skip]')
needs:
- lint
if: "!contains(github.event.head_commit.message, '[ci-skip]')"
name: Run unit tests
runs-on: ubuntu-20.04
steps:
@ -165,11 +148,8 @@ jobs:
install:
needs:
- changes-install
- lint_success
if: |
!contains(github.event.head_commit.message, '[ci-skip]')
&&
needs.changes-install.outputs.detected == 'true'
- lint
if: "!contains(github.event.head_commit.message, '[ci-skip]') && needs.changes-install.outputs.detected == 'true'"
name: Install charts
strategy:
matrix: ${{ fromJson(needs.changes-install.outputs.matrix) }}
@ -208,7 +188,7 @@ jobs:
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
install_success:
needs:
needs:
- changes-install
- install
if: ${{ always() }}

38
.github/workflows/pre-commit-check.yaml vendored Normal file
View File

@ -0,0 +1,38 @@
name: "Pre-commit consistency check"
on:
workflow_dispatch:
pull_request:
jobs:
pre-commit-check:
if: "!contains(github.event.head_commit.message, '[ci-skip]')"
name: Run pre-commit checks
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: '**'
# run only if changed files were detected
- name: Run against changes
uses: pre-commit/action@v2.0.2
if: steps.filter.outputs.addedOrModified == 'true'
with:
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}
# run if no changed files were detected (e.g. workflow_dispatch on master branch)
- name: Run against all files
uses: pre-commit/action@v2.0.2
if: steps.filter.outputs.addedOrModified != 'true'
with:
extra_args: --all-files

View File

@ -7,15 +7,11 @@ repos:
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: check-merge-conflict
- id: check-case-conflict
- repo: local
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.10
hooks:
- id: ct-lint
name: "Chart Test: Lint"
language: docker_image
pass_filenames: false
types: ['file']
files: '^charts/.*(\.ya?ml|\.tpl|\.helmignore|NOTES.txt)'
entry: -u 0 quay.io/helmpack/chart-testing:v3.0.0 ct
args:
- lint
- id: remove-crlf
- id: remove-tabs