Merge pull request 'feture/DO-110--create-groovy-linter' (#1) from feture/DO-110--create-groovy-linter into main
Reviewed-on: https://git.avroid.tech/Actions/npm-groovy-lint-docker-action/pulls/1 Reviewed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -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"]
|
||||
79
README.md
79
README.md
@@ -1,3 +1,80 @@
|
||||
# npm-groovy-lint-docker-action
|
||||
|
||||
NPM Groovy Linter Gitea Action
|
||||
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": "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Директория example содержит примеры файлов .groovylintrc.json и .gitea/workflows/groovy-linter.yml
|
||||
|
||||
Описание правил конфига линтера https://codenarc.org/codenarc-rule-index-by-name.html
|
||||
|
||||
25
action.yml
Normal file
25
action.yml
Normal file
@@ -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 }}"
|
||||
14
entrypoint.sh
Executable file
14
entrypoint.sh
Executable file
@@ -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
|
||||
|
||||
46
example/.gitea/workflows/groovy-linter.yml
Normal file
46
example/.gitea/workflows/groovy-linter.yml
Normal file
@@ -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 }}
|
||||
20
example/.groovylintrc.json
Normal file
20
example/.groovylintrc.json
Normal file
@@ -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": "_"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user