From d8b13b0fd8dbd877dd6842e527c551fbabd7ef32 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 13 Oct 2020 10:21:23 -0500 Subject: [PATCH] now with files --- .automation/test/tekton/README.md | 19 +++++++ .automation/test/tekton/bad/tekton_bad_1.yml | 49 +++++++++++++++++++ .../test/tekton/good/tekton_good_1.yml | 49 +++++++++++++++++++ README.md | 2 + docs/disabling-linters.md | 23 +++++++++ lib/buildFileList.sh | 10 ++++ lib/linter.sh | 40 +++++++++++++-- lib/linterVersions.sh | 2 +- lib/worker.sh | 1 + 9 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 .automation/test/tekton/README.md create mode 100644 .automation/test/tekton/bad/tekton_bad_1.yml create mode 100644 .automation/test/tekton/good/tekton_good_1.yml diff --git a/.automation/test/tekton/README.md b/.automation/test/tekton/README.md new file mode 100644 index 00000000..221415e6 --- /dev/null +++ b/.automation/test/tekton/README.md @@ -0,0 +1,19 @@ +# Tekton language Test Cases + +This folder holds the test cases for **Tekton**. + +## Additional Docs + +No Additional information is needed for this test case. + +## Good Test Cases + +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. + +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases + +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. + +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/tekton/bad/tekton_bad_1.yml b/.automation/test/tekton/bad/tekton_bad_1.yml new file mode 100644 index 00000000..92f8e204 --- /dev/null +++ b/.automation/test/tekton/bad/tekton_bad_1.yml @@ -0,0 +1,49 @@ +apiVersion: tekton.dev/v1alpha1 +kind: Pipeline +metadata: + name: build-and-deploy-pipeline +spec: + resources: + - name: git-source + type: git + params: + - name: pathToContext and space + description: The path to the build context, used by Kaniko - within the workspace + default: + - name: pathToYamlFile + description: The path to the yaml file to deploy within the git source + - name: imageUrl + description: Url of image repository + - name: + description: Tag to apply to the built image + tasks: + - name: source-to-image + taskRef: + name: source-to-image + params: + - name: pathToContext + value: "$(params.pathToContext)" + - name: imageUrl + value: "$(params.imageUrl)" + - name: imageTag + value: "$(params.imageTag)" + resources: + inputs: + - name: git-source + resource: git-source + - name: deploy-to-cluster + taskRef: + name: deploy-using-kubectl + runAfter: + - source-to-image + params: + - name: pathToYamlFile + value: "$(params.pathToYamlFile)" + - name: imageUrl + value: "$(params.imageUrl)" + - name: imageTag + value: "$(params.imageTag)" + resources: + inputs: + - name: git-source + resource: git-source diff --git a/.automation/test/tekton/good/tekton_good_1.yml b/.automation/test/tekton/good/tekton_good_1.yml new file mode 100644 index 00000000..a12fdeb1 --- /dev/null +++ b/.automation/test/tekton/good/tekton_good_1.yml @@ -0,0 +1,49 @@ +apiVersion: tekton.dev/v1alpha1 +kind: Pipeline +metadata: + name: build-and-deploy-pipeline +spec: + resources: + - name: git-source + type: git + params: + - name: pathToContext + description: The path to the build context, used by Kaniko - within the workspace + default: src + - name: pathToYamlFile + description: The path to the yaml file to deploy within the git source + - name: imageUrl + description: Url of image repository + - name: imageTag + description: Tag to apply to the built image + tasks: + - name: source-to-image + taskRef: + name: source-to-image + params: + - name: pathToContext + value: "$(params.pathToContext)" + - name: imageUrl + value: "$(params.imageUrl)" + - name: imageTag + value: "$(params.imageTag)" + resources: + inputs: + - name: git-source + resource: git-source + - name: deploy-to-cluster + taskRef: + name: deploy-using-kubectl + runAfter: + - source-to-image + params: + - name: pathToYamlFile + value: "$(params.pathToYamlFile)" + - name: imageUrl + value: "$(params.imageUrl)" + - name: imageTag + value: "$(params.imageTag)" + resources: + inputs: + - name: git-source + resource: git-source diff --git a/README.md b/README.md index cb45400c..80385494 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [executable bit check] / [shfmt](https://github.com/mvdan/sh) | | **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) | | **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) | +| **Tekton** | [tekton-lint](https://github.com/IBM/tekton-lint) | | **Terraform** | [tflint](https://github.com/terraform-linters/tflint) / [terrascan](https://github.com/accurics/terrascan) | | **Terragrunt** | [terragrunt](https://github.com/gruntwork-io/terragrunt) | | **TypeScript** | [eslint](https://eslint.org/) / [standard js](https://standardjs.com/) | @@ -277,6 +278,7 @@ But if you wish to select or exclude specific linters, we give you full control | **VALIDATE_SNAKEMAKE_SNAKEFMT** | `true` | Flag to enable or disable the linting process of Snakefiles. (Utilizing: snakefmt) | | **VALIDATE_STATES** | `true` | Flag to enable or disable the linting process for AWS States Language. | | **VALIDATE_SQL** | `true` | Flag to enable or disable the linting process of the SQL language. | +| **VALIDATE_TEKTON** | `true` | Flag to enable or disable the linting process of the Tekton language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the Terraform language. | | **VALIDATE_TERRAFORM_TERRASCAN** | `true` | Flag to enable or disable the linting process of the Terraform language for security related issues. | | **VALIDATE_TERRAGRUNT** | `true` | Flag to enable or disable the linting process for Terragrunt files. | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 006f281a..540f4b49 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -51,6 +51,7 @@ For some linters it is also possible to override rules on a case by case level w - [Shell](#shell) - [Snakemake](#snakemake) - [SQL](#sql) + - [Tekton](#tekton) - [Terraform](#terraform) - [Typescript eslint](#typescript-eslint) - [Typescript standard](#typescript-standard) @@ -1177,6 +1178,28 @@ shfmt [supports EditorConfig files for configuration](https://github.com/mvdan/s --- +## Tekton + +- [Tekton](https://github.com/IBM/tekton-lint) + +### Tekton Config file + +- There is currently **No** Tekton format config rules file + +### Tekton disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### Tekton disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### Tekton disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + ## Terraform - [tflint](https://github.com/terraform-linters/tflint) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index cace7e9d..069f01f3 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -495,6 +495,16 @@ function BuildFileList() { FILE_ARRAY_CLOUDFORMATION+=("${FILE}") fi + ######################################## + # Check if the file is Tekton template # + ######################################## + if DetectTektonFile "${FILE}"; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_TEKTON+=("${FILE}") + fi + ############################################ # Check if the file is Kubernetes template # ############################################ diff --git a/lib/linter.sh b/lib/linter.sh index 85816907..32fd4f88 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -172,8 +172,8 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLOUDFORMATION' 'CLOJURE' 'C 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KUBERNETES_KUBEVAL' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' - 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'R' 'RAKU' 'RUBY' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'TERRAFORM' - 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') + 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'R' 'RAKU' 'RUBY' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' + 'TEKTON' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ############################## # Linter command names array # @@ -224,6 +224,7 @@ LINTER_NAMES_ARRAY['SNAKEMAKE_LINT']="snakemake" LINTER_NAMES_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt" LINTER_NAMES_ARRAY['STATES']="asl-validator" LINTER_NAMES_ARRAY['SQL']="sql-lint" +LINTER_NAMES_ARRAY['TEKTON']="tekton-lint" LINTER_NAMES_ARRAY['TERRAFORM']="tflint" LINTER_NAMES_ARRAY['TERRAFORM_TERRASCAN']="terrascan" LINTER_NAMES_ARRAY['TERRAGRUNT']="terragrunt" @@ -548,6 +549,39 @@ DetectOpenAPIFile() { fi } ################################################################################ +#### Function DetectTektonFile ################################################# +DetectTektonFile() { + ################ + # Pull in vars # + ################ + FILE="${1}" + + ############################### + # Check the file for keywords # + ############################### + grep -q -E 'apiVersion: tekton' "${FILE}" >/dev/null + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -eq 0 ]; then + ######################## + # Found string in file # + ######################## + return 0 + else + ################### + # No string match # + ################### + return 1 + fi +} +################################################################################ #### Function DetectARMFile #################################################### DetectARMFile() { ################ @@ -1151,6 +1185,7 @@ LINTER_COMMANDS_ARRAY['SNAKEMAKE_LINT']="snakemake --lint -s" LINTER_COMMANDS_ARRAY['SNAKEMAKE_SNAKEFMT']="snakefmt --config ${SNAKEMAKE_SNAKEFMT_LINTER_RULES} --check --compact-diff" LINTER_COMMANDS_ARRAY['STATES']="asl-validator --json-path" LINTER_COMMANDS_ARRAY['SQL']="sql-lint --config ${SQL_LINTER_RULES}" +LINTER_COMMANDS_ARRAY['TEKTON']="tekton-lint" LINTER_COMMANDS_ARRAY['TERRAFORM']="tflint -c ${TERRAFORM_LINTER_RULES}" LINTER_COMMANDS_ARRAY['TERRAFORM_TERRASCAN']="terrascan scan -p /root/.terrascan/pkg/policies/opa/rego/ -t aws -f " LINTER_COMMANDS_ARRAY['TERRAGRUNT']="terragrunt hclfmt --terragrunt-check --terragrunt-hclfmt-file " @@ -1160,7 +1195,6 @@ LINTER_COMMANDS_ARRAY['TYPESCRIPT_STANDARD']="standard --parser @typescript-esli LINTER_COMMANDS_ARRAY['XML']="xmllint" LINTER_COMMANDS_ARRAY['YAML']="yamllint -c ${YAML_LINTER_RULES}" - ################################## # Get and print all version info # ################################## diff --git a/lib/linterVersions.sh b/lib/linterVersions.sh index 8b2a92c2..d21a2dc3 100755 --- a/lib/linterVersions.sh +++ b/lib/linterVersions.sh @@ -25,7 +25,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'bash-exec' 'black' 'cfn- 'dotnet-format' 'dart' 'dockerfilelint' 'dotenv-linter' 'editorconfig-checker' 'eslint' 'flake8' 'golangci-lint' 'hadolint' 'htmlhint' 'jsonlint' 'kubeval' 'ktlint' 'lintr' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'shfmt' 'spectral' 'standard' 'stylelint' 'sql-lint' - 'terrascan' 'tflint' 'xmllint' 'yamllint') + 'tekton-lint' 'terrascan' 'tflint' 'xmllint' 'yamllint') ################################################################################ ########################## FUNCTIONS BELOW ##################################### diff --git a/lib/worker.sh b/lib/worker.sh index 018d1c3e..1dbfffac 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -692,6 +692,7 @@ function RunTestCases() { TestCodebase "SNAKEMAKE_SNAKEFMT" "snakefmt" "snakefmt --config ${SNAKEMAKE_SNAKEFMT_LINTER_RULES} --check --compact-diff" ".*\.\(smk\)\$" "snakemake" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" TestCodebase "SQL" "sql-lint" "sql-lint --config ${SQL_LINTER_RULES}" ".*\.\(sql\)\$" "sql" + TestCodebase "TEKTON" "tekton-lint" "tekton-lint" ".*\.\(yml\|yaml\)\$" "tekton" TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan scan -p /root/.terrascan/pkg/policies/opa/rego/ -t aws -f " ".*\.\(tf\)\$" "terraform_terrascan" TestCodebase "TERRAGRUNT" "terragrunt" "terragrunt hclfmt --terragrunt-check --terragrunt-hclfmt-file " ".*\.\(hcl\)\$" "terragrunt"