resolve conflicts

Signed-off-by: Zack Koppert <zkoppert@github.com>
This commit is contained in:
Zack Koppert 2020-06-29 11:47:56 -07:00
commit f532456430
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 9D0BA682F8B27A0D
53 changed files with 2506 additions and 1933 deletions

View file

@ -0,0 +1,13 @@
# Clojure Test Cases
This folder holds the test cases for **Clojure**.
## 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.

View file

@ -0,0 +1,64 @@
(ns foo
(:require
[clojure.string :as str]
;; We're never using this namespace. Also, the namespaces aren't sorted.
[clojure.set :as set]))
;; Here we made a typo, so the symbol is unresolved:
(but-last [1 2 3])
;; Clj-kondo knows about arities of clojure namespaces, but you can also teach
;; it about your libraries or own namespaces
(str/join)
;; foo has an arity of 2, but we're not actually using y
(defn foo-fn [x y]
;; this do is redundant:
(do
;; this is handy for debugging, but please remove it before pushing your code:
(def tmp_x x)
(let [y (fn [] (inc x))]
;; the next let can be squashed together with the previous:
(let [z y]
;; whoopsy, calling a local function with an incorrect number of args:
(y x)
;; also wrong:
(recur)))))
(letfn
[(f [] (h 1))
(h [] (f 1))])
(defn- private-fn [])
;; redefining it...
(defn- private-fn [])
(defn foo [] :foo)
;; Type error, because foo doesn't return a number!
(inc (foo))
;; I'm tired now, let's sleep...
;; Oops, not happening because of wrong amount of args:
(Thread/sleep 1000 1 2)
;; Here we switch to another namespace and require the previous:
(ns bar (:require [foo :as f]))
;; Wrong arity when calling a function from the previous namespace:
(f/foo-fn)
;; private:
(f/private-fn)
;; this won't pass the reader:
{:a 1 :a 2}
;; and neither will this:
#{1 1}
;; nor this:
{:a 1 :b}
(ns bar-test (:require [clojure.test :as t]))
(t/deftest my-tests
;; you're not actually testing something here:
(odd? (inc 1)))

View file

@ -0,0 +1,34 @@
(ns foo
(:require
[clojure.string :as str]))
(butlast [1 2 3])
(str/join "" "")
(defn foo-fn [x]
(let [y (fn [] (inc x))]
(y)))
(letfn
[(f [g] (h g))
(h [i] (f i))])
(defn foo [] 1)
(inc (foo))
(Thread/sleep 1000 1)
;; Here we switch to another namespace and require the previous:
(ns bar (:require [foo :as f]))
(f/foo-fn 1)
{:a 1 :b 2}
#{1 2}
{:a 1 :b 2}
(ns bar-test (:require [clojure.test :as t]))
(t/deftest my-tests
(t/is (odd? (inc 1))))

View file

@ -0,0 +1,14 @@
# OpenAPI Test Cases
This folder holds the test cases for **OpenAPI**.
## Additional Docs
The `_bad_` tests are valid `.yml`/`.json` but invalid OpenAPI specs.
The test extensions used are `.ymlopenapi`/`.jsonopenapi` instead of `.yml`/`.json`. This is to prevent the [YAML] and [JSON] tests from picking them up.
## 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.

View file

@ -0,0 +1 @@
openapi: '3.0.0'

View file

@ -0,0 +1,3 @@
{
"openapi": "3.0.0"
}

View file

@ -0,0 +1,13 @@
openapi: 3.0.0
info:
title: Example
version: '1.0'
contact:
name: Justin Kalland
email: justin@kalland.com
description: Test for super-linter
servers:
- url: 'http://localhost:3000'
paths: {}
tags:
- name: example

View file

@ -0,0 +1,23 @@
{
"openapi": "3.0.0",
"info": {
"title": "Example",
"version": "1.0",
"contact": {
"name": "Justin Kalland",
"email": "justin@kalland.com"
},
"description": "Test for super-linter"
},
"servers": [
{
"url": "http://localhost:3000"
}
],
"paths": {},
"tags": [
{
"name": "example"
}
]
}

View file

@ -0,0 +1,19 @@
# Protobuf Test Cases
This folder holds the test cases for **Protobuf**.
## 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.

View file

@ -0,0 +1,48 @@
syntax = "proto3";
// A broken example of the official reference
// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file
package examplePb;
option java_package = "com.example.foo";
import "other.proto";
import public "new.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "myproject/other_protos.proto";
import "myproject/main_protos.proto";
enum enumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 2 [(custom_option) = "hello world"];
}
message outer {
option (my_option).a = true;
// inner is an inner message.
message inner { // Level 2
int64 ival = 1;
}
repeated inner inner_message = 2;
EnumAllowingAlias enum_field =3;
map<int32, string> my_map = 4;
string reason_for_error = 5;
string end_of_support_version= 6;
message AccountForAdmin {}
message SpecialEndOfSupport {}
required inner inner_message = 7;
group Result = 8 {
string url = 9;
}
repeated group Result = 10 {
}
repeated inner paper = 11;
repeated group Regular = 12 {
}
}
service SearchApi {
rpc search (SearchRequest) returns (SearchResponse) {};
};

View file

@ -0,0 +1,18 @@
syntax = "proto3";
import public "other.proto";
option java_package = "com.example.foo";
enum EnumAllowingAlias {
option allow_alias = true;
ALLOWING_UNSPECIFIED = 0;
STARTED = 1;
RUNNING = 2 [(custom_option) = "hello world"];
}
message Outer {
option (my_option).a = true;
message Inner { // Level 2
int64 ival = 1;
}
inner inner_message = 2;
EnumAllowingAlias enum_field =3;
map<int32, string> my_map = 4;
}

View file

@ -26,6 +26,8 @@ REGISTRY="${REGISTRY}" # What registry to upload | <GPR> or <Do
IMAGE_REPO="${IMAGE_REPO}" # Image repo to upload the image
IMAGE_VERSION="${IMAGE_VERSION}" # Version to tag the image
DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded
MAJOR_TAG='' # Major tag version if we need to update it
UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as well
################################################################################
############################ FUNCTIONS BELOW ###################################
@ -149,7 +151,7 @@ ValidateInput()
# Need to see if GPR registry and update name #
###############################################
if [[ "$REGISTRY" == "GPR" ]]; then
NAME="docker.pkg.github/$IMAGE_REPO"
NAME="docker.pkg.github.com/$IMAGE_REPO"
IMAGE_REPO="$NAME"
echo "Updated [IMAGE_REPO] to:[$IMAGE_REPO] for GPR"
fi
@ -194,6 +196,30 @@ ValidateInput()
echo "Successfully found:[IMAGE_VERSION], value:[$IMAGE_VERSION]"
fi
##################################
# Set regex for getting tag info #
##################################
REGEX='(v[0-9]+\.[0-9]+\.[0-9]+)' # Matches 'v1.2.3'
######################################################################
# Check if this is a latest to a versioned release at create new tag #
######################################################################
if [[ "$IMAGE_VERSION" =~ $REGEX ]]; then
# Need to get the major version, and set flag to update
#####################
# Set the major tag #
#####################
MAJOR_TAG=$(echo "$IMAGE_VERSION" | cut -d '.' -f1)
###################################
# Set flag for updating major tag #
###################################
UPDATE_MAJOR_TAG=1
echo "- Also deploying a major tag of:[$MAJOR_TAG]"
fi
############################
# Validate DOCKERFILE_PATH #
############################
@ -293,7 +319,31 @@ BuildImage()
else
# SUCCESS
echo "Successfully Built image!"
echo "Info:[$BUILD_CMD]"
fi
########################################################
# Need to see if we need to tag a major update as well #
########################################################
if [ $UPDATE_MAJOR_TAG -eq 1 ]; then
# Tag the image with the major tag as well
docker build -t "$IMAGE_REPO:$MAJOR_TAG" -f "$DOCKERFILE_PATH" . 2>&1
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# ERROR
echo "ERROR! failed to [tag] Dockerfile!"
exit 1
else
# SUCCESS
echo "Successfully tagged image!"
fi
fi
}
################################################################################
@ -328,7 +378,7 @@ UploadImage()
exit 1
else
# SUCCESS
echo "Successfully Uploaded Docker image to $REGISTRY!"
echo "Successfully Uploaded Docker image:[$IMAGE_VERSION] to $REGISTRY!"
fi
#########################
@ -371,6 +421,33 @@ UploadImage()
echo "Size:[$SIZE]"
echo "----------------------------------------------"
fi
###############################################################
# Check if we need to upload the major tagged version as well #
###############################################################
if [ $UPDATE_MAJOR_TAG -eq 1 ]; then
############################################
# Upload the docker image that was created #
############################################
docker push "$IMAGE_REPO:$MAJOR_TAG" 2>&1
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# ERROR
echo "ERROR! failed to [upload] MAJOR_TAG:[$MAJOR_TAG] Dockerfile!"
exit 1
else
# SUCCESS
echo "Successfully Uploaded TAGOR_TAG:[$MAJOR_TAG] Docker image to $REGISTRY!"
fi
fi
}
################################################################################
#### Function Footer ###########################################################

10
.devcontainer/README.md Normal file
View file

@ -0,0 +1,10 @@
# Devcontainer
This file specifies to vscode how to run the container
For format details, see [documentation](https://aka.ms/vscode-remote/devcontainer.json) or this file's [README](https://github.com/microsoft/vscode-dev-containers/tree/v0.123.0/containers/docker-existing-dockerfile)
context: Sets the run context to one level up instead of the .devcontainer folder.
dockerFile: Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
settings: Set *default* container specific settings.json values on container create.
extensions: Add the IDs of extensions you want installed when the container is created.

View file

@ -0,0 +1,12 @@
{
"name": "SUPER-LINTER",
"context": "..",
"dockerFile": "..//Dockerfile",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"github.vscode-pull-request-github",
"rogalmic.bash-debug"
]
}

3
.gitattributes vendored Normal file
View file

@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

View file

@ -33,9 +33,10 @@ Draft pull requests are also welcome to get feedback early on, or if there is so
If you are the current maintainer of this action:
1. Update `README.md` and the wiki to reflect new version number in the example workflow file sections
2. Draft [Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) with a summarized changelog
3. A GitHub Action will Publish the Docker image to GitHub Package Registry once a Release is created
4. A GitHub Action will Publish the Docker image to Docker Hub once a Release is created
5. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners)
3. Ensure you check the box for [publishing to the marketplace](https://help.github.com/en/actions/creating-actions/publishing-actions-in-github-marketplace#publishing-an-action)
4. A GitHub Action will Publish the Docker image to GitHub Package Registry once a Release is created
5. A GitHub Action will Publish the Docker image to Docker Hub once a Release is created
6. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners)
## Resources
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)

View file

@ -1,7 +0,0 @@
musl
nvq
rdoc
setuptools
uninstall
wget
WORKDIR

View file

@ -1 +0,0 @@
alnum

View file

@ -1,3 +0,0 @@
noqa
toc
todo

View file

@ -1,2 +0,0 @@
configcheck
nohup

View file

@ -1,2 +0,0 @@
args
pid

View file

@ -1 +0,0 @@
initialconfig

View file

@ -1,2 +0,0 @@
ldapconfig
openldap

View file

@ -1,8 +0,0 @@
cov
eslintcache
jscoverage
jspm
nyc
tgz
typings
wscript

View file

@ -1,7 +0,0 @@
cw
Mstrict
printenv
rcfile
tf
tolower
whoami

View file

@ -1,8 +0,0 @@
Autobots
basemap
cas
cn
crt
rsa
tlsv
tmp

View file

@ -1,4 +0,0 @@
dotcom
identicons
oauth
timezone

View file

@ -1,158 +0,0 @@
admiralawkbar
ansible
api
apk
aws
baz
beardofedu
certs
changeset
codebase
CODEOWNERS
coffeelint
coffeescript
collectd
concat
config
configs
css
dest
devops
dirname
dockerfile
dockerfilelint
dockerfilelintrc
dotenv
elif
emails
entrypoint
Errorf
eslint
eslintrc
filetype
func
gcc
getenv
ghe
GHES
ghl
github
globals
golang
golangci
Google
gpg
gql
Grafana
graphql
grep
homepage
hookshot
hostname
hostvars
http
https
hubot
idp
ip
Jani
javascript
jq
json
jsonlint
jwiebalk
JWT
ldap
len
lfs
libxml
linted
linting
loadbalancer
localhost
loglevel
markdownlint
millis
mkdir
nodejs
NONINFRINGEMENT
noproxy
noreply
npm
ntp
opensource
opensourcefriday
perl
plugin
posix
pprint
Prego
prettyjson
Println
probot
px
py
pylint
rb
readlines
README
regex
regexp
resqued
rgba
rien
Rubo
rubocop
saml
screenshots
shellcheck
signup
smtp
snmp
socio
splunk
src
ssh
ssl
sso
stackoverflow
stacktraces
standardjs
stringify
stylelint
stylelintrc
subdomain
subfolders
sudo
sys
syslog
taz
terraform
tflint
tileserver
tls
typeof
ubuntu
udp
uid
undef
uniq
uri
url
urlencode
username
usr
utils
Vape
vnd
webhook
wiki
wildcards
workflow
xml
xmllint
yaml
yamllint
yml
yq
zkoppert

View file

@ -1,2 +0,0 @@
^\.github/linters/
^TEMPLATES/\.\S*

View file

@ -1,40 +0,0 @@
cdxml
changelog
chmod
Dockerhub
EOL
GPR
IAm
icu
jre
kotlin
krb
ktlint
libgcc
libintl
libssl
libstdc
linux
lttng
microsoft
ncurses
nq
openjdk
php
powershell
println
psd
psm
psrc
pssc
psscriptanalyzer
pwsh
rcu
rhc
ry
tada
terminfo
tzdata
userspace
xargs
zlib

View file

@ -1,7 +0,0 @@
https?:\S*
# ignore long runs of a single character:
([A-Za-z])\1{3,}
# Any CLI args (-xzf -aef)
\ -\w+\b
# Hex colors (dummy group to not be treated as comment)
(?:#)([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})

2
.github/linters/.clj-kondo/config.edn vendored Normal file
View file

@ -0,0 +1,2 @@
{:linters {:unresolved-symbol {:exclude [(compojure.api.sweet/defroutes)]}
:refer-all {:exclude [clj-time.jdbc]}}}

9
.github/linters/.openapirc.yml vendored Normal file
View file

@ -0,0 +1,9 @@
---
##########################
##########################
## OpenAPI Linter rules ##
##########################
##########################
extends: spectral:oas

7
.github/linters/.protolintrc.yml vendored Normal file
View file

@ -0,0 +1,7 @@
# Lint directives.
lint:
# Linter rules.
# Run `protolint list` to see all available rules.
rules:
# Set the default to all linters.
all_default: false

View file

@ -1,4 +1,5 @@
[MASTER]
errors-only=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
@ -157,7 +158,7 @@ output-format=text
reports=no
# Activate the evaluation score.
score=yes
score=no
[REFACTORING]

View file

@ -1,48 +0,0 @@
---
####################
## Check spelling ##
####################
#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#
name: Spell checking
#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore:
- 'master'
###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Spell checking
# Set the agent to run on
runs-on: ubuntu-latest
##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
#############################
# Run check spelling action #
#############################
- name: Check spelling
uses: check-spelling/check-spelling@0.0.16-alpha
with:
bucket: .github/actions
project: spelling
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

16
.github/workflows/versioning.yml vendored Normal file
View file

@ -0,0 +1,16 @@
name: Keep the versions up-to-date
on:
release:
types: [published, edited]
jobs:
actions-tagger:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: Actions-R-Us/actions-tagger@latest
with:
publish_latest_tag: true
env:
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"

View file

@ -1,13 +0,0 @@
name: Greetings
on: [pull_request, issues]
jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thanks for opening your first issue in the **super-linter** repo! :tada:'
pr-message: 'Thanks for opening your first pr in the **super-linter** repo! :tada: This project is built on contributions just like this.'

3
.gitignore vendored
View file

@ -59,3 +59,6 @@ typings/
# next.js build output
.next
# clj-kondo cache
.cache

16
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "bashdb",
"request": "launch",
"name": "Test Linter",
"program": ".vscode/testlinter.sh",
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"presentation": {
"group": "aLinter"
}
}
]
}

26
.vscode/testlinter.sh vendored Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# At this point you can use the debug console to add export GITHUB_WORKSPACE=/path to test only a specific folder
# You can also use ln -s /path /tmp/lint as an alternative
# If you do neither, this will default to running against the test automation files
###########
# GLOBALS #
###########
CODE_PATH='/tmp/lint' # Path to code base
##################
# Check the path #
##################
if [ ! -L $CODE_PATH ]; then
# Create symbolic link
ln -s "$PWD"/.automation/test $CODE_PATH
fi
#########################
# Export to run locally #
#########################
export RUN_LOCAL=true
# shellcheck disable=SC1091,SC1090
source "$PWD"/lib/linter.sh

View file

@ -72,6 +72,7 @@ RUN npm config set package-lock false \
eslint-plugin-jest \
stylelint \
stylelint-config-standard \
@stoplight/spectral \
&& npm --no-cache install \
markdownlint-cli \
jsonlint prettyjson \
@ -125,12 +126,29 @@ RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/maste
RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip \
&& mv "tflint" /usr/bin/
######################
# Install protolint #
######################
RUN curl -LsS "$(curl -Ls https://api.github.com/repos/yoheimuta/protolint/releases/latest | grep -o -E "https://.+?_Linux_x86_64.tar.gz")" -o protolint.tar.gz \
&& tar -xzf protolint.tar.gz \
&& rm protolint.tar.gz \
&& mv "protolint" /usr/bin/
#########################
# Install dotenv-linter #
#########################
RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz" -O - -q | tar -xzf - \
&& mv "dotenv-linter" /usr/bin
#####################
# Install clj-kondo #
#####################
ARG CLJ_KONDO_VERSION='2020.06.12'
RUN curl -sLO https://github.com/borkdude/clj-kondo/releases/download/v${CLJ_KONDO_VERSION}/clj-kondo-${CLJ_KONDO_VERSION}-linux-static-amd64.zip \
&& unzip clj-kondo-${CLJ_KONDO_VERSION}-linux-static-amd64.zip \
&& rm clj-kondo-${CLJ_KONDO_VERSION}-linux-static-amd64.zip \
&& mv clj-kondo /usr/bin/
##################
# Install ktlint #
##################
@ -166,8 +184,11 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
VALIDATE_CSS=${VALIDATE_CSS} \
VALIDATE_ENV=${VALIDATE_ENV} \
VALIDATE_CLOJURE=${VALIDATE_CLOJURE} \
VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \
VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \
VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \
VALIDATE_PROTOBUF=${VALIDATE_PROTOBUF} \
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
RUN_LOCAL=${RUN_LOCAL} \
TEST_CASE_RUN=${TEST_CASE_RUN} \

View file

@ -8,6 +8,20 @@ The end goal of this tool:
- Build guidelines for code layout and format
- Automate the process to help streamline code reviews
## Table of Contents
- [How it works](#how-it-works)
- [Supported linters](#supported-linters)
- [Usage](#how-to-use)
- [Environment variables](#environment-variables)
- [Disable rules](#disabling-rules)
- [Docker Hub](#docker-hub)
- [Run Super-Linter locally](#running-super-linter-locally-troubleshootingdebuggingenhancements)
- [CI / CT/ CD](#cictcd)
- [Limitations](#limitations)
- [Contributing](#how-to-contribute)
## How it Works
The super-linter finds issues and reports them to the console output. Fixes are suggested in the console output but not automatically fixed, and a status check will show up as failed on the pull request.
@ -22,6 +36,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
| --- | --- |
| **Ansible** | [ansible-lint](https://github.com/ansible/ansible-lint) |
| **CSS** | [stylelint](https://stylelint.io/) |
| **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) |
| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) |
| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) |
| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) |
@ -40,6 +55,8 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
| **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) |
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) |
| **OpenAPI** | [spectral](https://github.com/stoplightio/spectral) |
| **Protocol Buffers** | [protolint](https://github.com/yoheimuta/protolint) |
## How to use
To use this **GitHub** Action you will need to complete the following:
@ -100,14 +117,14 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://github/super-linter:v2.2.0
uses: docker://github/super-linter:v3
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_ANSIBLE: false
...
```
**NOTE:** Using the line:`uses: docker://github/super-linter:v2.2.0` will pull the image down from **DockerHub** and run the **GitHub Super-Linter**. Using the line: `uses: github/super-linter@v2.2.0` will build and compile the **GitHub Super-Linter** at build time. This can be far more costly in time...
**NOTE:** Using the line:`uses: docker://github/super-linter:v3` will pull the image down from **DockerHub** and run the **GitHub Super-Linter**. Using the line: `uses: github/super-linter@v3` will build and compile the **GitHub Super-Linter** at build time. This can be far more costly in time...
## Environment variables
The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality.
@ -133,11 +150,14 @@ and won't run anything unexpected.
| **VALIDATE_PHP** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the language. |
| **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`)|
| **VALIDATE_COFFEE** | `true` | Flag to enable or disable the linting process of the language . |
| **VALIDATE_ANSIBLE** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_JAVASCRIPT_ES** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: eslint) |
| **JAVASCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [eslint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`)|
| **VALIDATE_JAVASCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: standard) |
| **VALIDATE_TYPESCRIPT_ES** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: eslint) |
| **TYPESCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [eslint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`)|
| **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: standard) |
| **VALIDATE_DOCKER** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the language. |
@ -145,7 +165,10 @@ and won't run anything unexpected.
| **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_CSS** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_CLOJURE** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_PROTOBUF** | `true` | Flag to enable or disable the linting process of the language. |
| **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). |
| **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. |
| **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. |
@ -185,6 +208,12 @@ Below are a list of the known limitations for the **GitHub Super-Linter**:
## How to contribute
If you would like to help contribute to this **GitHub** Action, please see [CONTRIBUTING](https://github.com/github/super-linter/blob/master/.github/CONTRIBUTING.md)
### Visual Studio Code
You can checkout this repository using [Container Remote Development](https://code.visualstudio.com/docs/remote/containers), and debug the linter using the `Test Linter` task.
![Example](https://user-images.githubusercontent.com/15258962/85165778-2d2ce700-b21b-11ea-803e-3f6709d8e609.gif)
We will also support [Github Codespaces](https://github.com/features/codespaces/) once it becomes available
--------------------------------------------------------------------------------
### License

View file

@ -0,0 +1,2 @@
{:linters {:unresolved-symbol {:exclude [(compojure.api.sweet/defroutes)]}
:refer-all {:exclude [clj-time.jdbc]}}}

9
TEMPLATES/.openapirc.yml Normal file
View file

@ -0,0 +1,9 @@
---
##########################
##########################
## OpenAPI Linter rules ##
##########################
##########################
extends: spectral:oas

View file

@ -0,0 +1,7 @@
# Lint directives.
lint:
# Linter rules.
# Run `protolint list` to see all available rules.
rules:
# Set the default to all linters.
all_default: false

View file

@ -1,4 +1,5 @@
[MASTER]
errors-only=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
@ -157,7 +158,7 @@ output-format=text
reports=no
# Activate the evaluation score.
score=yes
score=no
[REFACTORING]

View file

@ -24,6 +24,8 @@ Below are examples and documentation for each language and the various methods t
- [CSS](#stylelint)
- [ENV](#dotenv-linter)
- [Kotlin](#kotlin)
- [OpenAPI](#openapi)
- [Protocol Buffers](#protocol-buffers)
<!-- toc -->
@ -607,3 +609,91 @@ import package.b.*
### ktlint disable entire file
- There is currently **No** way to disable rules inline of the file(s)
--------------------------------------------------------------------------------
## OpenAPI
- [spectral](https://github.com/stoplightio/spectral)
### OpenAPI Config file
- `.github/linters/.openapirc.yml`
- You can add, extend, and disable rules
- Documentation at [Spectral Custom Rulesets](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/4-custom-rulesets.md)
- File should be located at: `.github/linters/.openapirc.yml`
### OpenAPI disable single line
- There is currently **No** way to disable rules inline of the file(s)
### OpenAPI disable code block
- There is currently **No** way to disable rules inline of the file(s)
### OpenAPI disable entire file
- There is currently **No** way to disable rules inline of the file(s)
- However, you can make [rule exceptions](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/guides/6-exceptions.md?srn=gh/stoplightio/spectral/docs/guides/6-exceptions.md) in the config for individual file(s).
--------------------------------------------------------------------------------
## Protocol Buffers
- [protolint](https://github.com/yoheimuta/protolint)
### protolint Config file
- `.github/linters/.protolintrc.yml`
- You can add, extend, and disable rules
- Documentation at [Rules](https://github.com/yoheimuta/protolint#rules) and [Configuring](https://github.com/yoheimuta/protolint#configuring)
### protolint disable single line
```protobuf
enum Foo {
// protolint:disable:next ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
firstValue = 0;
second_value = 1; // protolint:disable:this ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
THIRD_VALUE = 2;
}
```
### protolint disable code block
```protobuf
// protolint:disable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
enum Foo {
firstValue = 0;
second_value = 1;
THIRD_VALUE = 2;
}
// protolint:enable ENUM_FIELD_NAMES_UPPER_SNAKE_CASE
```
### protolint disable entire file
- You can disable entire files with the `lint.files.exclude` property in `.protolintrc.yml`
```yaml
# Lint directives.
lint:
# Linter files to walk.
files:
# The specific files to exclude.
exclude:
- path/to/file
```
## Clojure
- [clj-kondo](https://github.com/borkdude/clj-kondo)
- Since clj-kondo approaches static analysis in a very Clojure way, it is advised to read the [configuration docs](https://github.com/borkdude/clj-kondo/blob/master/doc/config.md)
### clj-kondo standard Config file
- `.github/linters/.clj-kondo/config.edn`
### clj-kondo disable single line
- There is currently **No** way to disable rules in a single line
### clj-kondo disable code block
- There is currently **No** way to disable rules in a code block
### clj-kondo disable entire file
```clojure
{:output {:exclude-files ["path/to/file"]}}
```

15
lib/README.md Normal file
View file

@ -0,0 +1,15 @@
# Super-Linter Library
## Main script
The file `linter.sh` is the main script that is called for the process and loads all other scripts as functions.
## Functions
The additional files in the folder are functions to help streamline the main build process and allow for easier maintenance.
- `possum.sh`
- Official mascot of the **Super-Linter**
- `buildFileList.sh`
- Functions to help find files that were modified, or need to be scanned
- `validation.sh`
- Logic to see what linters are enabled
- `worker.sh`
- Calls to the various linters and the test cases for each

421
lib/buildFileList.sh Executable file
View file

@ -0,0 +1,421 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034
################################################################################
################################################################################
########### Super-Linter Build File List Functions @admiralawkbar ##############
################################################################################
################################################################################
########################## FUNCTION CALLS BELOW ################################
################################################################################
################################################################################
#### Function BuildFileList ####################################################
function BuildFileList()
{
# Need to build a list of all files changed
# This can be pulled from the GITHUB_EVENT_PATH payload
################
# print header #
################
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo ""
echo "----------------------------------------------"
echo "Pulling in code history and branches..."
fi
#################################################################################
# Switch codebase back to the default branch to get a list of all files changed #
#################################################################################
SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull --quiet; git checkout "$DEFAULT_BRANCH" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Error
echo "Failed to switch to $DEFAULT_BRANCH branch to get files changed!"
echo "ERROR:[$SWITCH_CMD]"
exit 1
fi
################
# print header #
################
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo ""
echo "----------------------------------------------"
echo "Generating Diff with:[git diff --name-only '$DEFAULT_BRANCH..$GITHUB_SHA' --diff-filter=d]"
fi
#################################################
# Get the Array of files changed in the commits #
#################################################
# shellcheck disable=SC2207
RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "$DEFAULT_BRANCH..$GITHUB_SHA" --diff-filter=d 2>&1))
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Error
echo "ERROR! Failed to gain a list of all files changed!"
echo "ERROR:[${RAW_FILE_ARRAY[*]}]"
exit 1
fi
################################################
# Iterate through the array of all files found #
################################################
echo ""
echo "----------------------------------------------"
echo "Files that have been modified in the commit(s):"
for FILE in "${RAW_FILE_ARRAY[@]}"
do
##############
# Print file #
##############
echo "File:[$FILE]"
###########################
# Get the files extension #
###########################
# Extract just the file and extension, reverse it, cut off extension,
# reverse it back, substitute to lowercase
FILE_TYPE=$(basename "$FILE" | rev | cut -f1 -d'.' | rev | awk '{print tolower($0)}')
#########
# DEBUG #
#########
#echo "FILE_TYPE:[$FILE_TYPE]"
#####################
# Get the YML files #
#####################
if [ "$FILE_TYPE" == "yml" ] || [ "$FILE_TYPE" == "yaml" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_YML+=("$FILE")
############################
# Check if file is OpenAPI #
############################
if DetectOpenAPIFile "$FILE"; then
FILE_ARRAY_OPENAPI+=("$FILE")
fi
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
######################
# Get the JSON files #
######################
elif [ "$FILE_TYPE" == "json" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JSON+=("$FILE")
############################
# Check if file is OpenAPI #
############################
if DetectOpenAPIFile "$FILE"; then
FILE_ARRAY_OPENAPI+=("$FILE")
fi
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
#####################
# Get the XML files #
#####################
elif [ "$FILE_TYPE" == "xml" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_XML+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
##########################
# Get the MARKDOWN files #
##########################
elif [ "$FILE_TYPE" == "md" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_MD+=("$FILE")
######################
# Get the BASH files #
######################
elif [ "$FILE_TYPE" == "sh" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_BASH+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
######################
# Get the PERL files #
######################
elif [ "$FILE_TYPE" == "pl" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PERL+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
######################
# Get the PHP files #
######################
elif [ "$FILE_TYPE" == "php" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PHP+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
######################
# Get the RUBY files #
######################
elif [ "$FILE_TYPE" == "rb" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_RUBY+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
########################
# Get the PYTHON files #
########################
elif [ "$FILE_TYPE" == "py" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PYTHON+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
########################
# Get the COFFEE files #
########################
elif [ "$FILE_TYPE" == "coffee" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_COFFEESCRIPT+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
############################
# Get the JavaScript files #
############################
elif [ "$FILE_TYPE" == "js" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_JAVASCRIPT_ES+=("$FILE")
FILE_ARRAY_JAVASCRIPT_STANDARD+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
############################
# Get the TypeScript files #
############################
elif [ "$FILE_TYPE" == "ts" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TYPESCRIPT_ES+=("$FILE")
FILE_ARRAY_TYPESCRIPT_STANDARD+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
########################
# Get the Golang files #
########################
elif [ "$FILE_TYPE" == "go" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_GO+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
###########################
# Get the Terraform files #
###########################
elif [ "$FILE_TYPE" == "tf" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_TERRAFORM+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
###########################
# Get the Powershell files #
###########################
elif [ "$FILE_TYPE" == "ps1" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_POWERSHELL+=("$FILE")
elif [ "$FILE_TYPE" == "css" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CSS+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [ "$FILE_TYPE" == "env" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_ENV+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [ "$FILE_TYPE" == "kt" ] || [ "$FILE_TYPE" == "kts" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_KOTLIN+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
############################
# Get the Protocol Buffers files #
############################
elif [ "$FILE_TYPE" == "proto" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_PROTOBUF+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [ "$FILE" == "Dockerfile" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_DOCKER+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [ "$FILE_TYPE" == "clj" ] || [ "$FILE_TYPE" == "cljs" ] || [ "$FILE_TYPE" == "cljc" ] || [ "$FILE_TYPE" == "edn" ]; then
################################
# Append the file to the array #
################################
FILE_ARRAY_CLOJURE+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
else
##############################################
# Use file to see if we can parse what it is #
##############################################
GET_FILE_TYPE_CMD=$(file "$FILE" 2>&1)
#################
# Check if bash #
#################
if [[ "$GET_FILE_TYPE_CMD" == *"Bourne-Again shell script"* ]]; then
#######################
# It is a bash script #
#######################
echo "WARN! Found bash script without extension:[.sh]"
echo "Please update file with proper extensions."
################################
# Append the file to the array #
################################
FILE_ARRAY_BASH+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [[ "$GET_FILE_TYPE_CMD" == *"Ruby script"* ]]; then
#######################
# It is a Ruby script #
#######################
echo "WARN! Found ruby script without extension:[.rb]"
echo "Please update file with proper extensions."
################################
# Append the file to the array #
################################
FILE_ARRAY_RUBY+=("$FILE")
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
else
############################
# Extension was not found! #
############################
echo " - WARN! Failed to get filetype for:[$FILE]!"
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
fi
fi
done
#########################################
# Need to switch back to branch of code #
#########################################
SWITCH2_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git checkout --progress --force "$GITHUB_SHA" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Error
echo "Failed to switch back to branch!"
echo "ERROR:[$SWITCH2_CMD]"
exit 1
fi
################
# Footer print #
################
echo ""
echo "----------------------------------------------"
echo "Successfully gathered list of files..."
}

File diff suppressed because it is too large Load diff

669
lib/validation.sh Executable file
View file

@ -0,0 +1,669 @@
#!/usr/bin/env bash
################################################################################
################################################################################
########### Super-Linter Validation Functions @admiralawkbar ###################
################################################################################
################################################################################
########################## FUNCTION CALLS BELOW ################################
################################################################################
################################################################################
#### Function GetValidationInfo ################################################
function GetValidationInfo()
{
############################################
# Print headers for user provided env vars #
############################################
echo ""
echo "--------------------------------------------"
echo "Gathering user validation information..."
###########################################
# Skip validation if were running locally #
###########################################
if [[ "$RUN_LOCAL" != "true" ]]; then
###############################
# Convert string to lowercase #
###############################
VALIDATE_ALL_CODEBASE=$(echo "$VALIDATE_ALL_CODEBASE" | awk '{print tolower($0)}')
######################################
# Validate we should check all files #
######################################
if [[ "$VALIDATE_ALL_CODEBASE" != "false" ]]; then
# Set to true
VALIDATE_ALL_CODEBASE="$DEFAULT_VALIDATE_ALL_CODEBASE"
echo "- Validating ALL files in code base..."
else
# Its false
echo "- Only validating [new], or [edited] files in code base..."
fi
fi
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################################
# Convert strings to lowercase #
################################
VALIDATE_YAML=$(echo "$VALIDATE_YAML" | awk '{print tolower($0)}')
VALIDATE_JSON=$(echo "$VALIDATE_JSON" | awk '{print tolower($0)}')
VALIDATE_XML=$(echo "$VALIDATE_XML" | awk '{print tolower($0)}')
VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}')
VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}')
VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}')
VALIDATE_PHP=$(echo "$VALIDATE_PHP" | awk '{print tolower($0)}')
VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}')
VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}')
VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}')
VALIDATE_ANSIBLE=$(echo "$VALIDATE_ANSIBLE" | awk '{print tolower($0)}')
VALIDATE_JAVASCRIPT_ES=$(echo "$VALIDATE_JAVASCRIPT_ES" | awk '{print tolower($0)}')
VALIDATE_JAVASCRIPT_STANDARD=$(echo "$VALIDATE_JAVASCRIPT_STANDARD" | awk '{print tolower($0)}')
VALIDATE_TYPESCRIPT_ES=$(echo "$VALIDATE_TYPESCRIPT_ES" | awk '{print tolower($0)}')
VALIDATE_TYPESCRIPT_STANDARD=$(echo "$VALIDATE_TYPESCRIPT_STANDARD" | awk '{print tolower($0)}')
VALIDATE_DOCKER=$(echo "$VALIDATE_DOCKER" | awk '{print tolower($0)}')
VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}')
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
VALIDATE_POWERSHELL=$(echo "$VALIDATE_POWERSHELL" | awk '{print tolower($0)}')
VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}')
VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)}')
VALIDATE_CLOJURE=$(echo "$VALIDATE_CLOJURE" | awk '{print tolower($0)')
VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}')
VALIDATE_PROTOBUF=$(echo "$VALIDATE_PROTOBUF" | awk '{print tolower($0)}')
VALIDATE_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}')
################################################
# Determine if any linters were explicitly set #
################################################
ANY_SET="false"
if [[ -n "$VALIDATE_YAML" || \
-n "$VALIDATE_JSON" || \
-n "$VALIDATE_XML" || \
-n "$VALIDATE_MD" || \
-n "$VALIDATE_BASH" || \
-n "$VALIDATE_PERL" || \
-n "$VALIDATE_PHP" || \
-n "$VALIDATE_PYTHON" || \
-n "$VALIDATE_RUBY" || \
-n "$VALIDATE_COFFEE" || \
-n "$VALIDATE_ANSIBLE" || \
-n "$VALIDATE_JAVASCRIPT_ES" || \
-n "$VALIDATE_JAVASCRIPT_STANDARD" || \
-n "$VALIDATE_TYPESCRIPT_ES" || \
-n "$VALIDATE_TYPESCRIPT_STANDARD" || \
-n "$VALIDATE_DOCKER" || \
-n "$VALIDATE_GO" || \
-n "$VALIDATE_TERRAFORM" || \
-n "$VALIDATE_POWERSHELL" || \
-n "$VALIDATE_CSS" || \
-n "$VALIDATE_ENV" || \
-n "$VALIDATE_CLOJURE" || \
-n "$VALIDATE_PROTOBUF" || \
-n "$VALIDATE_OPENAPI" || \
-n "$VALIDATE_KOTLIN" ]]; then
ANY_SET="true"
fi
####################################
# Validate if we should check YAML #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_YAML" ]]; then
# YAML flag was not set - default to false
VALIDATE_YAML="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_YAML="true"
fi
####################################
# Validate if we should check JSON #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_JSON" ]]; then
# JSON flag was not set - default to false
VALIDATE_JSON="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_JSON="true"
fi
###################################
# Validate if we should check XML #
###################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_XML" ]]; then
# XML flag was not set - default to false
VALIDATE_XML="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_XML="true"
fi
########################################
# Validate if we should check MARKDOWN #
########################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_MD" ]]; then
# MD flag was not set - default to false
VALIDATE_MD="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_MD="true"
fi
####################################
# Validate if we should check BASH #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_BASH" ]]; then
# BASH flag was not set - default to false
VALIDATE_BASH="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_BASH="true"
fi
####################################
# Validate if we should check PERL #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_PERL" ]]; then
# PERL flag was not set - default to false
VALIDATE_PERL="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_PERL="true"
fi
####################################
# Validate if we should check PHP #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_PHP" ]]; then
# PHP flag was not set - default to false
VALIDATE_PHP="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_PHP="true"
fi
######################################
# Validate if we should check PYTHON #
######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_PYTHON" ]]; then
# PYTHON flag was not set - default to false
VALIDATE_PYTHON="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_PYTHON="true"
fi
####################################
# Validate if we should check RUBY #
####################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_RUBY" ]]; then
# RUBY flag was not set - default to false
VALIDATE_RUBY="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_RUBY="true"
fi
######################################
# Validate if we should check COFFEE #
######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_COFFEE" ]]; then
# COFFEE flag was not set - default to false
VALIDATE_COFFEE="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_COFFEE="true"
fi
#######################################
# Validate if we should check ANSIBLE #
#######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_ANSIBLE" ]]; then
# ANSIBLE flag was not set - default to false
VALIDATE_ANSIBLE="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_ANSIBLE="true"
fi
#############################################
# Validate if we should check JAVASCRIPT_ES #
#############################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_JAVASCRIPT_ES" ]]; then
# JAVASCRIPT_ES flag was not set - default to false
VALIDATE_JAVASCRIPT_ES="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_JAVASCRIPT_ES="true"
fi
###################################################
# Validate if we should check JAVASCRIPT_STANDARD #
###################################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_JAVASCRIPT_STANDARD" ]]; then
# JAVASCRIPT_STANDARD flag was not set - default to false
VALIDATE_JAVASCRIPT_STANDARD="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_JAVASCRIPT_STANDARD="true"
fi
#############################################
# Validate if we should check TYPESCRIPT_ES #
#############################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_TYPESCRIPT_ES" ]]; then
# TYPESCRIPT_ES flag was not set - default to false
VALIDATE_TYPESCRIPT_ES="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_TYPESCRIPT_ES="true"
fi
###################################################
# Validate if we should check TYPESCRIPT_STANDARD #
###################################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_TYPESCRIPT_STANDARD" ]]; then
# TYPESCRIPT_STANDARD flag was not set - default to false
VALIDATE_TYPESCRIPT_STANDARD="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_TYPESCRIPT_STANDARD="true"
fi
######################################
# Validate if we should check DOCKER #
######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_DOCKER" ]]; then
# DOCKER flag was not set - default to false
VALIDATE_DOCKER="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_DOCKER="true"
fi
##################################
# Validate if we should check GO #
##################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_GO" ]]; then
# GO flag was not set - default to false
VALIDATE_GO="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_GO="true"
fi
#########################################
# Validate if we should check TERRAFORM #
#########################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_TERRAFORM" ]]; then
# TERRAFORM flag was not set - default to false
VALIDATE_TERRAFORM="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_TERRAFORM="true"
fi
#########################################
# Validate if we should check POWERSHELL #
#########################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_POWERSHELL" ]]; then
# POWERSHELL flag was not set - default to false
VALIDATE_POWERSHELL="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_POWERSHELL="true"
fi
###################################
# Validate if we should check CSS #
###################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_CSS" ]]; then
# CSS flag was not set - default to false
VALIDATE_CSS="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_CSS="true"
fi
###################################
# Validate if we should check ENV #
###################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_ENV" ]]; then
# ENV flag was not set - default to false
VALIDATE_ENV="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_ENV="true"
fi
######################################
# Validate if we should check KOTLIN #
######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_KOTLIN" ]]; then
# ENV flag was not set - default to false
VALIDATE_KOTLIN="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_KOTLIN="true"
fi
#######################################
# Validate if we should check OPENAPI #
#######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_OPENAPI" ]]; then
# OPENAPI flag was not set - default to false
VALIDATE_OPENAPI="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_OPENAPI="true"
fi
#######################################
# Validate if we should check PROTOBUF #
#######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_PROTOBUF" ]]; then
# PROTOBUF flag was not set - default to false
VALIDATE_PROTOBUF="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_PROTOBUF="true"
fi
#######################################
# Validate if we should check Clojure #
#######################################
if [[ "$ANY_SET" == "true" ]]; then
# Some linter flags were set - only run those set to true
if [[ -z "$VALIDATE_CLOJURE" ]]; then
# Clojure flag was not set - default to false
VALIDATE_CLOJURE="false"
fi
else
# No linter flags were set - default all to true
VALIDATE_CLOJURE="true"
fi
#######################################
# Print which linters we are enabling #
#######################################
if [[ "$VALIDATE_YAML" == "true" ]]; then
PRINT_ARRAY+=("- Validating [YAML] files in code base...")
else
PRINT_ARRAY+=("- Excluding [YAML] files in code base...")
fi
if [[ "$VALIDATE_JSON" == "true" ]]; then
PRINT_ARRAY+=("- Validating [JSON] files in code base...")
else
PRINT_ARRAY+=("- Excluding [JSON] files in code base...")
fi
if [[ "$VALIDATE_XML" == "true" ]]; then
PRINT_ARRAY+=("- Validating [XML] files in code base...")
else
PRINT_ARRAY+=("- Excluding [XML] files in code base...")
fi
if [[ "$VALIDATE_MD" == "true" ]]; then
PRINT_ARRAY+=("- Validating [MARKDOWN] files in code base...")
else
PRINT_ARRAY+=("- Excluding [MARKDOWN] files in code base...")
fi
if [[ "$VALIDATE_BASH" == "true" ]]; then
PRINT_ARRAY+=("- Validating [BASH] files in code base...")
else
PRINT_ARRAY+=("- Excluding [BASH] files in code base...")
fi
if [[ "$VALIDATE_PERL" == "true" ]]; then
PRINT_ARRAY+=("- Validating [PERL] files in code base...")
else
PRINT_ARRAY+=("- Excluding [PERL] files in code base...")
fi
if [[ "$VALIDATE_PHP" == "true" ]]; then
PRINT_ARRAY+=("- Validating [PHP] files in code base...")
else
PRINT_ARRAY+=("- Excluding [PHP] files in code base...")
fi
if [[ "$VALIDATE_PYTHON" == "true" ]]; then
PRINT_ARRAY+=("- Validating [PYTHON] files in code base...")
else
PRINT_ARRAY+=("- Excluding [PYTHON] files in code base...")
fi
if [[ "$VALIDATE_RUBY" == "true" ]]; then
PRINT_ARRAY+=("- Validating [RUBY] files in code base...")
else
PRINT_ARRAY+=("- Excluding [RUBY] files in code base...")
fi
if [[ "$VALIDATE_COFFEE" == "true" ]]; then
PRINT_ARRAY+=("- Validating [COFFEE] files in code base...")
else
PRINT_ARRAY+=("- Excluding [COFFEE] files in code base...")
fi
if [[ "$VALIDATE_ANSIBLE" == "true" ]]; then
PRINT_ARRAY+=("- Validating [ANSIBLE] files in code base...")
else
PRINT_ARRAY+=("- Excluding [ANSIBLE] files in code base...")
fi
if [[ "$VALIDATE_JAVASCRIPT_ES" == "true" ]]; then
PRINT_ARRAY+=("- Validating [JAVASCRIPT(eslint)] files in code base...")
else
PRINT_ARRAY+=("- Excluding [JAVASCRIPT(eslint)] files in code base...")
fi
if [[ "$VALIDATE_JAVASCRIPT_STANDARD" == "true" ]]; then
PRINT_ARRAY+=("- Validating [JAVASCRIPT(standard)] files in code base...")
else
PRINT_ARRAY+=("- Excluding [JAVASCRIPT(standard)] files in code base...")
fi
if [[ "$VALIDATE_TYPESCRIPT_ES" == "true" ]]; then
PRINT_ARRAY+=("- Validating [TYPESCRIPT(eslint)] files in code base...")
else
PRINT_ARRAY+=("- Excluding [TYPESCRIPT(eslint)] files in code base...")
fi
if [[ "$VALIDATE_TYPESCRIPT_STANDARD" == "true" ]]; then
PRINT_ARRAY+=("- Validating [TYPESCRIPT(standard)] files in code base...")
else
PRINT_ARRAY+=("- Excluding [TYPESCRIPT(standard)] files in code base...")
fi
if [[ "$VALIDATE_DOCKER" == "true" ]]; then
PRINT_ARRAY+=("- Validating [DOCKER] files in code base...")
else
PRINT_ARRAY+=("- Excluding [DOCKER] files in code base...")
fi
if [[ "$VALIDATE_GO" == "true" ]]; then
PRINT_ARRAY+=("- Validating [GOLANG] files in code base...")
else
PRINT_ARRAY+=("- Excluding [GOLANG] files in code base...")
fi
if [[ "$VALIDATE_TERRAFORM" == "true" ]]; then
PRINT_ARRAY+=("- Validating [TERRAFORM] files in code base...")
else
PRINT_ARRAY+=("- Excluding [TERRAFORM] files in code base...")
fi
if [[ "$VALIDATE_POWERSHELL" == "true" ]]; then
PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...")
else
PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...")
fi
if [[ "$VALIDATE_CSS" == "true" ]]; then
PRINT_ARRAY+=("- Validating [CSS] files in code base...")
else
PRINT_ARRAY+=("- Excluding [CSS] files in code base...")
fi
if [[ "$VALIDATE_CLOJURE" == "true" ]]; then
PRINT_ARRAY+=("- Validating [CLOJURE] files in code base...")
else
PRINT_ARRAY+=("- Excluding [CLOJURE] files in code base...")
fi
if [[ "$VALIDATE_ENV" == "true" ]]; then
PRINT_ARRAY+=("- Validating [ENV] files in code base...")
else
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
fi
if [[ "$VALIDATE_KOTLIN" == "true" ]]; then
PRINT_ARRAY+=("- Validating [KOTLIN] files in code base...")
else
PRINT_ARRAY+=("- Excluding [KOTLIN] files in code base...")
fi
if [[ "$VALIDATE_OPENAPI" == "true" ]]; then
PRINT_ARRAY+=("- Validating [OPENAPI] files in code base...")
else
PRINT_ARRAY+=("- Excluding [OPENAPI] files in code base...")
fi
if [[ "$VALIDATE_PROTOBUF" == "true" ]]; then
PRINT_ARRAY+=("- Validating [PROTOBUF] files in code base...")
else
PRINT_ARRAY+=("- Excluding [PROTOBUF] files in code base...")
fi
##############################
# Validate Ansible Directory #
##############################
if [ -z "$ANSIBLE_DIRECTORY" ]; then
# No Value, need to default
ANSIBLE_DIRECTORY="$DEFAULT_ANSIBLE_DIRECTORY"
else
# Check if first char is '/'
if [[ ${ANSIBLE_DIRECTORY:0:1} == "/" ]]; then
# Remove first char
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:1}"
fi
# Need to give it full path
TEMP_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/$ANSIBLE_DIRECTORY"
# Set the value
ANSIBLE_DIRECTORY="$TEMP_ANSIBLE_DIRECTORY"
fi
###############################
# Get the disable errors flag #
###############################
if [ -z "$DISABLE_ERRORS" ]; then
##################################
# No flag passed, set to default #
##################################
DISABLE_ERRORS="$DEFAULT_DISABLE_ERRORS"
fi
###############################
# Convert string to lowercase #
###############################
DISABLE_ERRORS=$(echo "$DISABLE_ERRORS" | awk '{print tolower($0)}')
############################
# Set to false if not true #
############################
if [ "$DISABLE_ERRORS" != "true" ]; then
DISABLE_ERRORS="false"
fi
############################
# Get the run verbose flag #
############################
if [ -z "$ACTIONS_RUNNER_DEBUG" ]; then
##################################
# No flag passed, set to default #
##################################
ACTIONS_RUNNER_DEBUG="$DEFAULT_ACTIONS_RUNNER_DEBUG"
fi
###############################
# Convert string to lowercase #
###############################
ACTIONS_RUNNER_DEBUG=$(echo "$ACTIONS_RUNNER_DEBUG" | awk '{print tolower($0)}')
############################
# Set to true if not false #
############################
if [ "$ACTIONS_RUNNER_DEBUG" != "false" ]; then
ACTIONS_RUNNER_DEBUG="true"
fi
###################
# Debug on runner #
###################
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
###########################
# Print the validate info #
###########################
for LINE in "${PRINT_ARRAY[@]}"
do
echo "$LINE"
done
echo "--- DEBUG INFO ---"
echo "---------------------------------------------"
RUNNER=$(whoami)
echo "Runner:[$RUNNER]"
echo "ENV:"
printenv
echo "---------------------------------------------"
fi
}

658
lib/worker.sh Executable file
View file

@ -0,0 +1,658 @@
#!/usr/bin/env bash
################################################################################
################################################################################
########### Super-Linter linting Functions @admiralawkbar ######################
################################################################################
################################################################################
########################## FUNCTION CALLS BELOW ################################
################################################################################
################################################################################
#### Function LintCodebase #####################################################
function LintCodebase()
{
####################
# Pull in the vars #
####################
FILE_TYPE="$1" && shift # Pull the variable and remove from array path (Example: JSON)
LINTER_NAME="$1" && shift # Pull the variable and remove from array path (Example: jsonlint)
LINTER_COMMAND="$1" && shift # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file)
FILE_EXTENSIONS="$1" && shift # Pull the variable and remove from array path (Example: *.json)
FILE_ARRAY=("$@") # Array of files to validate (Example: $FILE_ARRAY_JSON)
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################
# print header #
################
PRINT_ARRAY+=("")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("Linting [$FILE_TYPE] files...")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("----------------------------------------------")
#######################################
# Validate we have jsonlint installed #
#######################################
# shellcheck disable=SC2230
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Failed
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
exit 1
else
# Success
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo "Successfully found binary in system"
echo "Location:[$VALIDATE_INSTALL_CMD]"
fi
fi
##########################
# Initialize empty Array #
##########################
LIST_FILES=()
################
# Set the flag #
################
SKIP_FLAG=0
############################################################
# Check to see if we need to go through array or all files #
############################################################
if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
# No files found in commit and user has asked to not validate code base
SKIP_FLAG=1
# echo " - No files found in changeset to lint for language:[$FILE_TYPE]"
elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then
# We have files added to array of files to check
LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list
else
###############################################################################
# Set the file seperator to newline to allow for grabbing objects with spaces #
###############################################################################
IFS=$'\n'
#################################
# Get list of all files to lint #
#################################
# shellcheck disable=SC2207,SC2086
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1))
###########################
# Set IFS back to default #
###########################
IFS="$DEFAULT_IFS"
############################################################
# Set it back to empty if loaded with blanks from scanning #
############################################################
if [ ${#LIST_FILES[@]} -lt 1 ]; then
######################
# Set to empty array #
######################
LIST_FILES=()
#############################
# Skip as we found no files #
#############################
SKIP_FLAG=1
fi
fi
###############################
# Check if any data was found #
###############################
if [ $SKIP_FLAG -eq 0 ]; then
######################
# Print Header array #
######################
for LINE in "${PRINT_ARRAY[@]}"
do
#########################
# Print the header info #
#########################
echo "$LINE"
done
##################
# Lint the files #
##################
for FILE in "${LIST_FILES[@]}"
do
#####################
# Get the file name #
#####################
FILE_NAME=$(basename "$FILE" 2>&1)
#####################################################
# Make sure we dont lint node modules or test cases #
#####################################################
if [[ $FILE == *"node_modules"* ]]; then
# This is a node modules file
continue
elif [[ $FILE == *"$TEST_CASE_FOLDER"* ]]; then
# This is the test cases, we should always skip
continue
fi
##############
# File print #
##############
echo "---------------------------"
echo "File:[$FILE]"
####################
# Set the base Var #
####################
LINT_CMD=''
#######################################
# Corner case for Powershell subshell #
#######################################
if [[ "$FILE_TYPE" == "POWERSHELL" ]]; then
################################
# Lint the file with the rules #
################################
# Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1)
else
################################
# Lint the file with the rules #
################################
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1)
fi
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
#########
# Error #
#########
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
echo "ERROR:[$LINT_CMD]"
# Increment the error count
(("ERRORS_FOUND_$FILE_TYPE++"))
else
###########
# Success #
###########
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
fi
done
fi
}
################################################################################
#### Function TestCodebase #####################################################
function TestCodebase()
{
####################
# Pull in the vars #
####################
FILE_TYPE="$1" # Pull the variable and remove from array path (Example: JSON)
LINTER_NAME="$2" # Pull the variable and remove from array path (Example: jsonlint)
LINTER_COMMAND="$3" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file)
FILE_EXTENSIONS="$4" # Pull the variable and remove from array path (Example: *.json)
################
# print header #
################
echo ""
echo "----------------------------------------------"
echo "----------------------------------------------"
echo "Testing Codebase [$FILE_TYPE] files..."
echo "----------------------------------------------"
echo "----------------------------------------------"
echo ""
#####################################
# Validate we have linter installed #
#####################################
# shellcheck disable=SC2230
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Failed
echo "ERROR! Failed to find [$LINTER_NAME] in system!"
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
exit 1
else
# Success
echo "Successfully found binary in system"
echo "Location:[$VALIDATE_INSTALL_CMD]"
fi
##########################
# Initialize empty Array #
##########################
LIST_FILES=()
############################################
# Check if its ansible, as its the outlier #
############################################
if [[ "$FILE_TYPE" == "ANSIBLE" ]]; then
#################################
# Get list of all files to lint #
#################################
# shellcheck disable=SC2207,SC2086,SC2010
LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; ls ansible/ | grep ".yml" 2>&1))
else
###############################################################################
# Set the file seperator to newline to allow for grabbing objects with spaces #
###############################################################################
IFS=$'\n'
#################################
# Get list of all files to lint #
#################################
# shellcheck disable=SC2207,SC2086
LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; find . -type f -regex "$FILE_EXTENSIONS" ! -path "*./ansible*" 2>&1))
###########################
# Set IFS back to default #
###########################
IFS="$DEFAULT_IFS"
fi
##################
# Lint the files #
##################
for FILE in "${LIST_FILES[@]}"
do
#####################
# Get the file name #
#####################
FILE_NAME=$(basename "$FILE" 2>&1)
############################
# Get the file pass status #
############################
# Example: markdown_good_1.md -> good
FILE_STATUS=$(echo "$FILE_NAME" |cut -f2 -d'_')
#########################################################
# If not found, assume it should be linted successfully #
#########################################################
if [ -z "$FILE_STATUS" ] || [[ "$FILE" == *"README"* ]]; then
##################################
# Set to good for proper linting #
##################################
FILE_STATUS="good"
fi
##############
# File print #
##############
echo "---------------------------"
echo "File:[$FILE]"
########################
# Set the lint command #
########################
LINT_CMD=''
#######################################
# Check if docker and get folder name #
#######################################
if [[ "$FILE_TYPE" == "DOCKER" ]]; then
if [[ "$FILE" == *"good"* ]]; then
#############
# Good file #
#############
FILE_STATUS='good'
else
############
# Bad file #
############
FILE_STATUS='bad'
fi
fi
#####################
# Check for ansible #
#####################
if [[ "$FILE_TYPE" == "ANSIBLE" ]]; then
########################################
# Make sure we dont lint certain files #
########################################
if [[ $FILE == *"vault.yml"* ]] || [[ $FILE == *"galaxy.yml"* ]]; then
# This is a file we dont look at
continue
fi
################################
# Lint the file with the rules #
################################
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/ansible" || exit; $LINTER_COMMAND "$FILE" 2>&1)
elif [[ "$FILE_TYPE" == "POWERSHELL" ]]; then
################################
# Lint the file with the rules #
################################
# Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1)
else
################################
# Lint the file with the rules #
################################
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" 2>&1)
fi
#######################
# Load the error code #
#######################
ERROR_CODE=$?
########################################
# Check for if it was supposed to pass #
########################################
if [[ "$FILE_STATUS" == "good" ]]; then
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
#########
# Error #
#########
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
echo "ERROR:[$LINT_CMD]"
echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]"
# Increment the error count
(("ERRORS_FOUND_$FILE_TYPE++"))
else
###########
# Success #
###########
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
fi
else
#######################################
# File status = bad, this should fail #
#######################################
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -eq 0 ]; then
#########
# Error #
#########
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
echo "ERROR! This file should have failed test case!"
echo "ERROR:[$LINT_CMD]"
echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]"
# Increment the error count
(("ERRORS_FOUND_$FILE_TYPE++"))
else
###########
# Success #
###########
echo " - File:[$FILE_NAME] failed test case with [$LINTER_NAME] successfully"
fi
fi
done
}
################################################################################
#### Function RunTestCases #####################################################
function RunTestCases()
{
# This loop will run the test cases and exclude user code
# This is called from the automation process to validate new code
# When a PR is opened, the new code is validated with the default branch
# version of linter.sh, and a new container is built with the latest codebase
# for testing. That container is spun up, and ran,
# with the flag: TEST_CASE_RUN=true
# So that the new code can be validated against the test cases
#################
# Header prints #
#################
echo ""
echo "----------------------------------------------"
echo "-------------- TEST CASE RUN -----------------"
echo "----------------------------------------------"
echo ""
#######################
# Test case languages #
#######################
TestCodebase "YML" "yamllint" "yamllint -c $YAML_LINTER_RULES" ".*\.\(yml\|yaml\)\$"
TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$"
TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$"
TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c $MD_LINTER_RULES" ".*\.\(md\)\$"
TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$"
TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES" ".*\.\(py\)\$"
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$"
TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$"
TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$"
TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$"
TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$"
TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES" ".*\.\(js\)\$"
TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard $JAVASCRIPT_STANDARD_LINTER_RULES" ".*\.\(js\)\$"
TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES" ".*\.\(ts\)\$"
TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$"
TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint -c $DOCKER_LINTER_RULES" ".*\(Dockerfile\)\$"
TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint"
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
TestCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$"
TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$"
TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$"
TestCodebase "CLOJURE" "clj-kondo" "clj-kondo --config $CLOJURE_LINTER_RULES --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$"
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$"
TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path $PROTOBUF_LINTER_RULES" ".*\.\(proto\)\$"
TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$"
#################
# Footer prints #
#################
# Call the footer to display run information
# and exit with error code
Footer
}
################################################################################
#### Function LintAnsibleFiles #################################################
function LintAnsibleFiles()
{
######################
# Create Print Array #
######################
PRINT_ARRAY=()
################
# print header #
################
PRINT_ARRAY+=("")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("Linting [Ansible] files...")
PRINT_ARRAY+=("----------------------------------------------")
PRINT_ARRAY+=("----------------------------------------------")
######################
# Name of the linter #
######################
LINTER_NAME="ansible-lint"
###########################################
# Validate we have ansible-lint installed #
###########################################
# shellcheck disable=SC2230
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
# Failed
echo "ERROR! Failed to find $LINTER_NAME in system!"
echo "ERROR:[$VALIDATE_INSTALL_CMD]"
exit 1
else
# Success
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
# Success
echo "Successfully found binary in system"
echo "Location:[$VALIDATE_INSTALL_CMD]"
fi
fi
##########################
# Initialize empty Array #
##########################
LIST_FILES=()
#######################
# Create flag to skip #
#######################
SKIP_FLAG=0
######################################################
# Only go into ansible linter if we have base folder #
######################################################
if [ -d "$ANSIBLE_DIRECTORY" ]; then
############################################################
# Check to see if we need to go through array or all files #
############################################################
if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
# We need to only check the ansible playbooks that have updates
#LIST_FILES=("${ANSIBLE_ARRAY[@]}")
# shellcheck disable=SC2164,SC2010,SC2207
LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1))
else
#################################
# Get list of all files to lint #
#################################
# shellcheck disable=SC2164,SC2010,SC2207
LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1))
fi
###############################################################
# Set the list to empty if only MD and TXT files were changed #
###############################################################
# No need to run the full ansible checks on read only file changes
if [ "$READ_ONLY_CHANGE_FLAG" -eq 0 ]; then
##########################
# Set the array to empty #
##########################
LIST_FILES=()
###################################
# Send message that were skipping #
###################################
#echo "- Skipping Ansible lint run as file(s) that were modified were read only..."
############################
# Create flag to skip loop #
############################
SKIP_FLAG=1
fi
####################################
# Check if we have data to look at #
####################################
if [ $SKIP_FLAG -eq 0 ]; then
for LINE in "${PRINT_ARRAY[@]}"
do
#########################
# Print the header line #
#########################
echo "$LINE"
done
fi
##################
# Lint the files #
##################
for FILE in "${LIST_FILES[@]}"
do
########################################
# Make sure we dont lint certain files #
########################################
if [[ $FILE == *"vault.yml"* ]] || [[ $FILE == *"galaxy.yml"* ]]; then
# This is a file we dont look at
continue
fi
####################
# Get the filename #
####################
FILE_NAME=$(basename "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
##############
# File print #
##############
echo "---------------------------"
echo "File:[$FILE]"
################################
# Lint the file with the rules #
################################
LINT_CMD=$("$LINTER_NAME" -v -c "$ANSIBLE_LINTER_RULES" "$ANSIBLE_DIRECTORY/$FILE" 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ]; then
#########
# Error #
#########
echo "ERROR! Found errors in [$LINTER_NAME] linter!"
echo "ERROR:[$LINT_CMD]"
# Increment error count
((ERRORS_FOUND_ANSIBLE++))
else
###########
# Success #
###########
echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully"
fi
done
else # No ansible directory found in path
###############################
# Check to see if debug is on #
###############################
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
########################
# No Ansible dir found #
########################
echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]"
echo "skipping ansible lint"
fi
fi
}