From 9752629eaf5abbded42e29445ebc64ac729cbd9e Mon Sep 17 00:00:00 2001 From: Yaroslav Bondarenko Date: Tue, 23 Apr 2024 11:19:28 +0300 Subject: [PATCH] [DO-110] created groovy linter action --- Dockerfile | 13 ++++ README.md | 77 +++++++++++++++++++++- action.yml | 25 +++++++ entrypoint.sh | 14 ++++ example/.gitea/workflows/groovy-linter.yml | 46 +++++++++++++ example/.groovylintrc.json | 20 ++++++ 6 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 action.yml create mode 100755 entrypoint.sh create mode 100644 example/.gitea/workflows/groovy-linter.yml create mode 100644 example/.groovylintrc.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..68733e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# Copyright Avroid, Ltd. 2023-2024 +# +# You can not use the contents of the file in any way without +# AVROID, Ltd. written permission. +# +# To obtain such a permit, you should contact AVROID, Ltd. +# at https://avroid.ru + +FROM harbor.avroid.tech/devops/npm-groovy-lint:14.4.1-0 + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 40f09f0..a50478d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,78 @@ # npm-groovy-lint-docker-action -NPM Groovy Linter Gitea Action \ No newline at end of file +Gitea Action (Github Action) для проверки Groovy кода(Groovy Liter). +В качестве линтера используется 'NPM GROOVY LINT' - Groovy & Jenkinsfile Linter. NPM GROOVY LINT основан на базе CodeNarc - анализатора Groovy кода. + +[Ссылка на проект](https://github.com/nvuillam/npm-groovy-lint) + +Пример использования: + +1- Данный код в виде yaml файла размещаем в репозиторий для которого необходим линтинг groovy кода. Путь для размещения +файла: repo_with_groovy_files/.gitea/workflows/groovy-linter.yml + +```yaml +--- +name: Groovy linter +run-name: ${{ gitea.actor }} is start check sources +on: [pull_request] + +jobs: + linter: + name: Groovy linter + runs-on: docker + container: + image: harbor.avroid.tech/devops/npm-groovy-lint:14.4.1-0 + steps: + - run: echo "Start job on ${{ runner.name }} with OS ${{ runner.os }}" + - run: echo "Work with branch ${{ gitea.ref }} in repository ${{ gitea.repository }}" + - name: Check out repository code + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-checkout.git@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Get all groovy files that have changed + id: changed-files-specific + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-tj-actions-changed-files.git@v44 + with: + files: | + **/*.groovy + **/Jenkinsfile + - name: Run step if there is no changed files + id: no_files_to_check + if: steps.changed-files-specific.outputs.any_changed != 'true' + run: echo "*** No changed groovy files, nothing to check. ***" + + - name: Run linter for changed files + id: groovy_linter + if: steps.changed-files-specific.outputs.any_changed == 'true' + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Actions/npm-groovy-lint-docker-action.git@v17 + with: + input_flags: "--failon error" + input_files: ${{ steps.changed-files-specific.outputs.all_changed_files }} +``` +2 - Размещаем в корне проверяемого репозитория конфиг для линтера. Путь и имя для размещения +repo_with_groovy_files/.groovylintrc.json + +```json +{ + "extends": "recommended", + "rules": { + "convention.CompileStatic": "off", + "convention.NoDef": "off", + "groovyism.ExplicitCallToEqualsMethod": "off", + "groovyism.GStringExpressionWithinString": "off", + "naming.VariableName": { + "ignoreVariableNames": "_" + }, + "naming.FactoryMethodName": "off", + "unnecessary.UnnecessaryGetter": "off", + "size.NestedBlockDepth": { + "maxNestedBlockDepth": 10 + }, + "unused.UnusedVariable": { + "ignoreVariableNames": "_" + } + } +} +``` +Описание правил конфига линтера https://codenarc.org/codenarc-rule-index-by-name.html \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..42d36e1 --- /dev/null +++ b/action.yml @@ -0,0 +1,25 @@ +# Copyright Avroid, Ltd. 2023-2024 +# +# You can not use the contents of the file in any way without +# AVROID, Ltd. written permission. +# +# To obtain such a permit, you should contact AVROID, Ltd. +# at https://avroid.ru + +name: 'Groovy linter action' +description: 'This actions check groovy files' +inputs: + input_flags: + description: 'Additional flags for npm-groovy-lint' + required: false + default: '' + input_files: + description: 'Files for linter checking' + required: true + default: '' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - "${{ inputs.input_flags }}" + - "${{ inputs.input_files }}" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..1f78508 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh -l +# Copyright Avroid, Ltd. 2023-2024 +# +# You can not use the contents of the file in any way without +# AVROID, Ltd. written permission. +# +# To obtain such a permit, you should contact AVROID, Ltd. +# at https://avroid.ru + +echo "Triggering event: '$GITHUB_EVENT_NAME'" +echo "Linting changed groovy files:" +echo "=====================================" +echo /usr/local/bin/npm-groovy-lint "$INPUT_INPUT_FLAGS" "$INPUT_INPUT_FILES" | sh + diff --git a/example/.gitea/workflows/groovy-linter.yml b/example/.gitea/workflows/groovy-linter.yml new file mode 100644 index 0000000..0af84dc --- /dev/null +++ b/example/.gitea/workflows/groovy-linter.yml @@ -0,0 +1,46 @@ +# Copyright Avroid, Ltd. 2023-2024 +# +# You can not use the contents of the file in any way without +# AVROID, Ltd. written permission. +# +# To obtain such a permit, you should contact AVROID, Ltd. +# at https://avroid.ru + +--- +name: Groovy linter +run-name: ${{ gitea.actor }} is start check sources +on: [pull_request] + +jobs: + linter: + name: Groovy linter + runs-on: docker + container: + image: harbor.avroid.tech/devops/npm-groovy-lint:14.4.1-0 + steps: + - run: echo "Start job on ${{ runner.name }} with OS ${{ runner.os }}" + - run: echo "Work with branch ${{ gitea.ref }} in repository ${{ gitea.repository }}" + - name: Check out repository code + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-checkout.git@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Get all groovy files that have changed + id: changed-files-specific + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Mirrors/github-actions-tj-actions-changed-files.git@v44 + with: + files: | + **/*.groovy + **/Jenkinsfile + - name: Run step if there is no changed files + id: no_files_to_check + if: steps.changed-files-specific.outputs.any_changed != 'true' + run: echo "*** No changed groovy files, nothing to check. ***" + + - name: Run linter for changed files + id: groovy_linter + if: steps.changed-files-specific.outputs.any_changed == 'true' + uses: https://gitea:${{ secrets.CI_TOKEN }}@git.avroid.tech/Actions/npm-groovy-lint-docker-action.git@v17 + with: + input_flags: "--failon error" + input_files: ${{ steps.changed-files-specific.outputs.all_changed_files }} diff --git a/example/.groovylintrc.json b/example/.groovylintrc.json new file mode 100644 index 0000000..aaa0461 --- /dev/null +++ b/example/.groovylintrc.json @@ -0,0 +1,20 @@ +{ + "extends": "recommended", + "rules": { + "convention.CompileStatic": "off", + "convention.NoDef": "off", + "groovyism.ExplicitCallToEqualsMethod": "off", + "groovyism.GStringExpressionWithinString": "off", + "naming.VariableName": { + "ignoreVariableNames": "_" + }, + "naming.FactoryMethodName": "off", + "unnecessary.UnnecessaryGetter": "off", + "size.NestedBlockDepth": { + "maxNestedBlockDepth": 10 + }, + "unused.UnusedVariable": { + "ignoreVariableNames": "_" + } + } +} \ No newline at end of file