From 839453329229382a893c5e24d753ecd0a4fde878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= Date: Sat, 1 May 2021 13:27:23 +0200 Subject: [PATCH] [CI] Add pre-commit check (#845) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [CI] Add pre-commit check Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Add other folder for testing Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Simplify CI Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Update pre-commit Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Update job name Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Linter issues Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Fix conditionals Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Separate chart linting and pre-commit Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Change workflow name Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs * Allow running against all files Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs --- .github/workflows/charts-lint-test.yaml | 34 +++++----------------- .github/workflows/pre-commit-check.yaml | 38 +++++++++++++++++++++++++ .pre-commit-config.yaml | 16 ++++------- 3 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/pre-commit-check.yaml diff --git a/.github/workflows/charts-lint-test.yaml b/.github/workflows/charts-lint-test.yaml index 1d92715f..e26a8ddd 100644 --- a/.github/workflows/charts-lint-test.yaml +++ b/.github/workflows/charts-lint-test.yaml @@ -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() }} diff --git a/.github/workflows/pre-commit-check.yaml b/.github/workflows/pre-commit-check.yaml new file mode 100644 index 00000000..01a265de --- /dev/null +++ b/.github/workflows/pre-commit-check.yaml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bec56f1c..80e92c36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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