Merge branch 'master' into feature/tap-format

This commit is contained in:
Victor Martinez 2020-06-29 11:08:40 +01:00 committed by GitHub
commit 7cf73e5dc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 712 additions and 102 deletions

View file

@ -19,4 +19,5 @@ When the script is triggered in a branch, it will push with the tag:**NameOfBran
- **Note:** The branch name will be reduced to alphanumeric for consistency and uploading
## test
This folder holds all **Test Cases** to help run the *CI/CT/CD* process for the **Super-Linter**.

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
################################################################################
############# Cleanup Image on DockerHub @admiralawkbar ########################
@ -8,7 +8,7 @@
# Its based on being built from a GitHub Action, but could be easily updated
# To be ran in a different medium.
#
# PRE-Reqs:
# PRE-Requirements:
# - Dockerfile
# - System with Docker installed
# - Global variables met

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
################################################################################
# Script to run ghe-config-apply on the primary GHES instance
@ -35,7 +35,7 @@ CheckGHEPid()
################################################
if [ ! -f "$GHE_CONFIG_PID" ]; then
# File not found
echo "Were good to move forward, no .pid file found at:[$GHE_CONFIG_PID]"
echo "We're good to move forward, no .pid file found at:[$GHE_CONFIG_PID]"
else
# Found the pid running, need to sleep
echo "Current PID found, sleeping $SLEEP_SECONDS seconds before next check..."
@ -189,10 +189,10 @@ CheckGHEProcess
####################
RunConfigApply
##########################################
# Were going to run it again after a nap #
# to make sure there is no crazy actions #
##########################################
###########################################
# We're going to run it again after a nap #
# to make sure there is no crazy actions #
###########################################
sleep 300s
######################

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

@ -6,7 +6,7 @@
# `mona echo *` - repeats what you say
#
# Author:
# admiralAwkbar@github.com
# admiralawkbar@github.com
###############################
# Drop Hammer array of images #

View file

@ -6,7 +6,7 @@
# `mona echo *` - repeats what you say
#
# Author:
# admiralAwkbar@github.com
# admiralawkbar@github.com
###############################
# Drop Hammer array of images #

View file

@ -1,5 +1,5 @@
/* Bad */
/* Multiline */
/* Multi-line */
/* Comment */
.selector-3[type="text"] {
background: linear-gradient(#FFFFFF, rgba(0, 0, 0, 0.8));

View file

@ -16,5 +16,5 @@ ls -la
# Walk away
Were all done **here**.
We're all done **here**.
- [Link Action]https://github.com

View file

@ -16,5 +16,5 @@ ls -la
### Walk away
Were all done **here**.
We're all done **here**.
- [Link Action](https://github.com)

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

@ -1,7 +1,7 @@
#!/usr/bin/perl
################################################################################
################################################################################
######### Script action @admiralAwkbar #########################################
######### Script action @admiralawkbar #########################################
################################################################################
#############

View file

@ -1,7 +1,7 @@
#!/usr/bin/perl
################################################################################
################################################################################
######### Script action @admiralAwkbar #########################################
######### Script action @admiralawkbar #########################################
################################################################################
#############

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# CMD
HELLO_WORLD=($(echo "Hello World" | cut -f1 -d' ' 2>&1))

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# CMD
HELLO_WORLD=$(echo "Hello World" | cut -f1 -d' ' 2>&1)

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
################################################################################
############# Deploy Container to DockerHub @admiralawkbar #####################
@ -9,7 +9,7 @@
# Its based on being built from a GitHub Action, but could be easily updated
# To be ran in a different medium.
#
# PRE-Reqs:
# PRE-Requirements:
# - Dockerfile
# - System with Docker installed
# - Global variables met
@ -20,6 +20,9 @@
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace
DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub
DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub
GPR_USERNAME="${GPR_USERNAME}" # Username to login to GitHub package registry
GPR_TOKEN="${GPR_TOKEN}" # Password to login to GitHub package registry
REGISTRY="${REGISTRY}" # What registry to upload | <GPR> or <Docker>
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
@ -33,7 +36,7 @@ Header()
{
echo ""
echo "-------------------------------------------------------"
echo "------ GitHub Actions Upload image to DockerHub -------"
echo "---- GitHub Actions Upload image to [$REGISTRY] ----"
echo "-------------------------------------------------------"
echo ""
}
@ -51,9 +54,9 @@ ValidateInput()
echo "----------------------------------------------"
echo ""
############################
#############################
# Validate GITHUB_WORKSPACE #
############################
#############################
if [ -z "$GITHUB_WORKSPACE" ]; then
echo "ERROR! Failed to get [GITHUB_WORKSPACE]!"
echo "ERROR:[$GITHUB_WORKSPACE]"
@ -62,28 +65,77 @@ ValidateInput()
echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]"
fi
############################
# Validate DOCKER_USERNAME #
############################
if [ -z "$DOCKER_USERNAME" ]; then
echo "ERROR! Failed to get [DOCKER_USERNAME]!"
echo "ERROR:[$DOCKER_USERNAME]"
#####################
# Validate REGISTRY #
#####################
if [ -z "$REGISTRY" ]; then
echo "ERROR! Failed to get [REGISTRY]!"
echo "ERROR:[$REGISTRY]"
exit 1
else
echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]"
echo "Successfully found:[REGISTRY], value:[$REGISTRY]"
fi
############################
# Validate DOCKER_PASSWORD #
############################
if [ -z "$DOCKER_PASSWORD" ]; then
echo "ERROR! Failed to get [DOCKER_PASSWORD]!"
echo "ERROR:[$DOCKER_PASSWORD]"
exit 1
#####################################################
# See if we need values for GitHub package Registry #
#####################################################
if [[ "$REGISTRY" == "GPR" ]]; then
#########################
# Validate GPR_USERNAME #
#########################
if [ -z "$GPR_USERNAME" ]; then
echo "ERROR! Failed to get [GPR_USERNAME]!"
echo "ERROR:[$GPR_USERNAME]"
exit 1
else
echo "Successfully found:[GPR_USERNAME], value:[$GPR_USERNAME]"
fi
######################
# Validate GPR_TOKEN #
######################
if [ -z "$GPR_TOKEN" ]; then
echo "ERROR! Failed to get [GPR_TOKEN]!"
echo "ERROR:[$GPR_TOKEN]"
exit 1
else
echo "Successfully found:[GPR_TOKEN], value:[********]"
fi
########################################
# See if we need values for Ducker hub #
########################################
elif [[ "$REGISTRY" == "Docker" ]]; then
############################
# Validate DOCKER_USERNAME #
############################
if [ -z "$DOCKER_USERNAME" ]; then
echo "ERROR! Failed to get [DOCKER_USERNAME]!"
echo "ERROR:[$DOCKER_USERNAME]"
exit 1
else
echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]"
fi
############################
# Validate DOCKER_PASSWORD #
############################
if [ -z "$DOCKER_PASSWORD" ]; then
echo "ERROR! Failed to get [DOCKER_PASSWORD]!"
echo "ERROR:[$DOCKER_PASSWORD]"
exit 1
else
echo "Successfully found:[DOCKER_PASSWORD], value:[********]"
fi
###########################################
# We were not passed a registry to update #
###########################################
else
echo "Successfully found:[DOCKER_PASSWORD], value:[********]"
echo "ERROR! Failed to find a valid registry!"
echo "Registry:[$REGISTRY]"
exit 1
fi
#######################
# Validate IMAGE_REPO #
#######################
@ -93,6 +145,14 @@ ValidateInput()
exit 1
else
echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]"
###############################################
# Need to see if GPR registry and update name #
###############################################
if [[ "$REGISTRY" == "GPR" ]]; then
NAME="docker.pkg.github/$IMAGE_REPO"
IMAGE_REPO="$NAME"
echo "Updated [IMAGE_REPO] to:[$IMAGE_REPO] for GPR"
fi
fi
##########################
@ -146,22 +206,30 @@ ValidateInput()
fi
}
################################################################################
#### Function LoginToDocker ####################################################
LoginToDocker()
#### Function Authenticate #####################################################
Authenticate()
{
################
# Pull in Vars #
################
USERNAME="$1" # Name to auth with
PASSWORD="$2" # Password to auth with
URL="$3" # Url to auth towards
NAME="$4" # name of the service
################
# Print header #
################
echo ""
echo "----------------------------------------------"
echo "Login to DockerHub..."
echo "Login to $NAME..."
echo "----------------------------------------------"
echo ""
######################
# Login to DockerHub #
######################
LOGIN_CMD=$(docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" 2>&1)
###################
# Auth to service #
###################
LOGIN_CMD=$(docker login "$URL" --username "$USERNAME" --password "$PASSWORD" 2>&1)
#######################
# Load the error code #
@ -173,12 +241,12 @@ LoginToDocker()
##############################
if [ $ERROR_CODE -ne 0 ]; then
# ERROR
echo "ERROR! Failed to authenticate to DockerHub!"
echo "ERROR! Failed to authenticate to $NAME!"
echo "ERROR:[$LOGIN_CMD]"
exit 1
else
# SUCCESS
echo "Successfully authenticated to DockerHub!"
echo "Successfully authenticated to $NAME!"
fi
}
################################################################################
@ -194,7 +262,6 @@ BuildImage()
echo "----------------------------------------------"
echo ""
################################
# Validate the DOCKERFILE_PATH #
################################
@ -238,7 +305,7 @@ UploadImage()
################
echo ""
echo "----------------------------------------------"
echo "Uploading the DockerFile image..."
echo "Uploading the DockerFile image to $REGISTRY..."
echo "----------------------------------------------"
echo ""
@ -261,7 +328,7 @@ UploadImage()
exit 1
else
# SUCCESS
echo "Successfully Uploaded Docker image to DockerHub!"
echo "Successfully Uploaded Docker image to $REGISTRY!"
fi
#########################
@ -329,16 +396,34 @@ Header
##################
ValidateInput
######################
# Login to DockerHub #
######################
LoginToDocker
###################
# Build the image #
###################
BuildImage
######################
# Login to DockerHub #
######################
if [[ "$REGISTRY" == "Docker" ]]; then
# Authenticate "Username" "Password" "Url" "Name"
Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "" "Dockerhub"
####################################
# Login to GitHub Package Registry #
####################################
elif [[ "$REGISTRY" == "GPR" ]]; then
# Authenticate "Username" "Password" "Url" "Name"
Authenticate "$GPR_USERNAME" "$GPR_TOKEN" "https://docker.pkg.github.com" "GitHub Package Registry"
else
#########
# ERROR #
#########
echo "ERROR! Registry not set correctly!"
echo "Registry:[$REGISTRY]"
exit 1
fi
####################
# Upload the image #
####################

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. Publish the docker image to GitHub package registry
4. Publish the docker image to Docker Hub
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/)

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

View file

@ -47,7 +47,7 @@ jobs:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_REPO: admiralawkbar/super-linter
IMAGE_REPO: github/super-linter
IMAGE_VERSION: ${{ github.event.pull_request.head.ref }}
shell: bash
run: .automation/cleanup-docker.sh

View file

@ -43,13 +43,14 @@ jobs:
#####################
# Run Deploy script #
#####################
- name: Deploy image to DockerHub
- name: Deploy DEV image to DockerHub
env:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_REPO: github/super-linter
DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash
run: .automation/upload-docker.sh

View file

@ -40,7 +40,7 @@ jobs:
#####################
# Run Deploy script #
#####################
- name: Deploy image to DockerHub
- name: Deploy latest image to DockerHub
env:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
@ -48,5 +48,6 @@ jobs:
IMAGE_REPO: github/super-linter
IMAGE_VERSION: latest
DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash
run: .automation/upload-docker.sh

68
.github/workflows/deploy-RELEASE.yml vendored Normal file
View file

@ -0,0 +1,68 @@
---
#########################
#########################
## Deploy Docker Image ##
#########################
#########################
#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#
#######################################
# Start the job on all push to master #
#######################################
on:
release:
# Want to run the automation when a release is created
types: ['created']
###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Deploy Docker Image - Release
# 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 Deploy script for Dockerhub #
###################################
- name: Deploy Release image to Dockerhub
env:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_REPO: github/super-linter
IMAGE_VERSION: ${{ github.event.release.tag_name }}
DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash
run: .automation/upload-docker.sh
#############################
# Run Deploy script for GPR #
#############################
- name: Deploy Release image to GitHub Package Registry
env:
# Set the Env Vars
GPR_USERNAME: ${{ secrets.GPR_USERNAME }}
GPR_TOKEN: ${{ secrets.GPR_TOKEN }}
IMAGE_REPO: github/super-linter
IMAGE_VERSION: ${{ github.event.release.tag_name }}
DOCKERFILE_PATH: Dockerfile
REGISTRY: GPR
shell: bash
run: .automation/upload-docker.sh

7
.gitignore vendored
View file

@ -29,7 +29,7 @@ bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
# Compiled binary add-ons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
@ -60,5 +60,8 @@ typings/
# next.js build output
.next
# clj-kondo cache
.cache
# default output report
super-linter.report
super-linter.report

View file

@ -27,7 +27,7 @@ RUN apk add --no-cache \
libxml2-utils perl \
ruby ruby-dev ruby-bundler ruby-rdoc make \
py3-setuptools ansible-lint \
go \
go \
openjdk8-jre \
php7 \
ca-certificates less ncurses-terminfo-base \
@ -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 \
@ -131,6 +132,15 @@ RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/r
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 #
##################
@ -145,6 +155,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \
DEFAULT_BRANCH=${DEFAULT_BRANCH} \
VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \
LINTER_RULES_PATH=${LINTER_RULES_PATH} \
VALIDATE_YAML=${VALIDATE_YAML} \
VALIDATE_JSON=${VALIDATE_JSON} \
VALIDATE_XML=${VALIDATE_XML} \
@ -165,8 +176,10 @@ 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} \
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
RUN_LOCAL=${RUN_LOCAL} \
TEST_CASE_RUN=${TEST_CASE_RUN} \

View file

@ -8,10 +8,26 @@ 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.
The design of the **Super-Linter** is currently to allow linting to occur in **GitHub Actions** as a part of continuous integration occurring on pull requests as the commits get pushed. It works best when commits are being pushed early and often to a branch with an open or draft pull request. There is some desire to move this closer to local development for faster feedback on linting errors but this is not yet supported.
## Supported Linters
Developers on **GitHub** can call the **GitHub Action** to lint their code base with the following list of linters:
@ -20,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) |
@ -38,6 +55,7 @@ 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) |
## How to use
To use this **GitHub** Action you will need to complete the following:
@ -98,14 +116,14 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://github/super-linter:v2.1.0
uses: docker://github/super-linter:v2.2.0
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_ANSIBLE: false
...
```
**NOTE:** Using the line:`uses: docker://github/super-linter:v2.1.0` will pull the image down from **DockerHub** and run the **GitHub Super-Linter**. Using the line: `uses: github/super-linter@v2.1.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: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...
## Environment variables
The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality.
@ -121,6 +139,7 @@ and won't run anything unexpected.
| --- | --- | --- |
| **VALIDATE_ALL_CODEBASE** | `true` | Will parse the entire repository and find all files to validate across all types. **NOTE:** When set to `false`, only **new** or **edited** files will be parsed for validation. |
| **DEFAULT_BRANCH** | `master` | The name of the repository default branch. |
| **LINTER_RULES_PATH** | `.github/linters` | Directory for all linter configuration rules. |
| **VALIDATE_YAML** | `true` |Flag to enable or disable the linting process of the language. |
| **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_XML** | `true` | Flag to enable or disable the linting process of the language. |
@ -130,11 +149,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. |
@ -142,7 +164,9 @@ 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. |
| **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. |
@ -164,6 +188,8 @@ The **Docker** container that is built from this repository is located at `https
## Running Super-Linter locally (troubleshooting/debugging/enhancements)
If you find that you need to run super-linter locally, you can follow the documentation at [Running super-linter locally](https://github.com/github/super-linter/blob/master/docs/run-linter-locally.md)
Check out the [note](#how-it-works) in **How it Works** to understand more about the **Super-Linter** linting locally versus via continuous integration.
### CI/CT/CD
The **Super-Linter** has *CI/CT/CD* configured utilizing **GitHub** Actions.
- When a branch is created and code is pushed, a **GitHub** Action is triggered for building the new **Docker** container with the new codebase

View file

@ -29,9 +29,9 @@ quiet: true
################
skip_list:
- '602' # Allow compare to empty string
- '204' # Allow string length greater that 160 chars
- '204' # Allow string length greater than 160 chars
- '301' # False positives for running command shells
- '303' # Allow git commands for push add, etc...
- '303' # Allow git commands for push, add, etc...
- '305' # Allow use of shell when you want
- '503' # Allow step to run like handler

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

@ -1,6 +1,6 @@
# Disabling linters and Rules
If you find you need to ignore certain **errors** and **warnings**, you will need to know the *format* to disable the **Super-Linter** rules.
Below is examples and documentation for each language and the various methods to disable.
Below are examples and documentation for each language and the various methods to disable.
## Table of Linters
- [Ruby](#ruby)
@ -24,6 +24,7 @@ Below is examples and documentation for each language and the various methods to
- [CSS](#stylelint)
- [ENV](#dotenv-linter)
- [Kotlin](#kotlin)
- [OpenAPI](#openapi)
<!-- toc -->
@ -156,9 +157,9 @@ This line is waaaaaaaaaay too long # yamllint disable-line
### Yamllint disable code block
```yml
# yamllint disable rule:colons
- Lorem : ipsum
dolor : sit amet,
consectetur : adipiscing elit
- Key : value
dolor : sit,
foo : bar
# yamllint enable
```
@ -222,9 +223,9 @@ class Foo(object):
def meth3(self):
"""test one line disabling"""
# no error
print(self.bla) # pylint: disable=no-member
print(self.baz) # pylint: disable=no-member
# error
print(self.blop)
print(self.baz)
```
### Pylint disable entire file
@ -607,3 +608,44 @@ 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).
--------------------------------------------------------------------------------
## 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"]}}
```

View file

@ -1,9 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash
# shellcheck disable=SC1003,SC2016
################################################################################
################################################################################
########### Super-Linter (Lint all the code) @AdmiralAwkbar ####################
########### Super-Linter (Lint all the code) @admiralawkbar ####################
################################################################################
################################################################################
@ -12,7 +12,7 @@
###########
# Default Vars
DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location
LINTER_PATH='.github/linters' # Default linter path
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory
# YAML Vars
YAML_FILE_NAME='.yaml-lint.yml' # Name of the file
YAML_LINTER_RULES="$DEFAULT_RULES_LOCATION/$YAML_FILE_NAME" # Path to the yaml lint rules
@ -23,17 +23,17 @@ MD_LINTER_RULES="$DEFAULT_RULES_LOCATION/$MD_FILE_NAME" # Path to th
PYTHON_FILE_NAME='.python-lint' # Name of the file
PYTHON_LINTER_RULES="$DEFAULT_RULES_LOCATION/$PYTHON_FILE_NAME" # Path to the python lint rules
# Ruby Vars
RUBY_FILE_NAME='.ruby-lint.yml' # Name of the file
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}" # Name of the file
RUBY_LINTER_RULES="$DEFAULT_RULES_LOCATION/$RUBY_FILE_NAME" # Path to the ruby lint rules
# Coffee Vars
COFFEE_FILE_NAME='.coffee-lint.json' # Name of the file
COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to the coffescript lint rules
COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to the coffeescript lint rules
# Javascript Vars
JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
JAVASCRIPT_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file
JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules
JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Typescript Vars
TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
TYPESCRIPT_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file
TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules
TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Ansible Vars
@ -54,6 +54,12 @@ POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Pat
# CSS Vars
CSS_FILE_NAME='.stylelintrc.json' # Name of the file
CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to the CSS lint rules
# OpenAPI Vars
OPENAPI_FILE_NAME='.openapirc.yml' # Name of the file
OPENAPI_LINTER_RULES="$DEFAULT_RULES_LOCATION/$OPENAPI_FILE_NAME" # Path to the OpenAPI lint rules
# Clojure Vars
CLOJURE_FILE_NAME='.clj-kondo/config.edn'
CLOJURE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CLOJURE_FILE_NAME"
#######################################
# Linter array for information prints #
@ -61,7 +67,7 @@ CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to th
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
"stylelint" "dotenv-linter" "powershell" "ktlint")
"stylelint" "dotenv-linter" "powershell" "ktlint" "clj-kondo" "spectral")
#############################
# Language array for prints #
@ -69,7 +75,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON'
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM'
'ENV' 'POWERSHELL' 'KOTLIN')
'CSS' 'ENV' 'POWERSHELL' 'KOTLIN' 'CLOJURE' 'OPENAPI')
###################
# GitHub ENV Vars #
@ -97,11 +103,13 @@ VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to val
VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language
VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language
VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language
VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language
VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language
VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language
VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language
VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases
DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors
@ -114,16 +122,17 @@ ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG}" # Boolean to see even more info
################
# Default Vars #
################
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally
DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory
DEFAULT_RUN_LOCAL='false' # Default value for debugging locally
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output
RAW_FILE_ARRAY=() # Array of all files that were changed
READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md
TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally
DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory
DEFAULT_RUN_LOCAL='false' # Default value for debugging locally
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output
RAW_FILE_ARRAY=() # Array of all files that were changed
READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md
TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
DEFAULT_IFS="$IFS" # Get the Default IFS for updating
##############
# Format #
@ -152,10 +161,12 @@ FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check
FILE_ARRAY_DOCKER=() # Array of files to check
FILE_ARRAY_GO=() # Array of files to check
FILE_ARRAY_TERRAFORM=() # Array of files to check
FILE_ARRAY_POWERSHELL=() # Array of files to check
FILE_ARRAY_POWERSHELL=() # Array of files to check
FILE_ARRAY_CSS=() # Array of files to check
FILE_ARRAY_ENV=() # Array of files to check
FILE_ARRAY_CLOJURE=() # Array of files to check
FILE_ARRAY_KOTLIN=() # Array of files to check
FILE_ARRAY_OPENAPI=() # Array of files to check
############
# Counters #
@ -181,7 +192,9 @@ ERRORS_FOUND_TERRAFORM=0 # Count of errors found
ERRORS_FOUND_POWERSHELL=0 # Count of errors found
ERRORS_FOUND_CSS=0 # Count of errors found
ERRORS_FOUND_ENV=0 # Count of errors found
ERRORS_FOUND_CLOJURE=0 # Count of errors found
ERRORS_FOUND_KOTLIN=0 # Count of errors found
ERRORS_FOUND_OPENAPI=0 # Count of errors found
################################################################################
########################## FUNCTIONS BELOW #####################################
@ -269,14 +282,14 @@ GetLinterRules()
#####################################
# Validate we have the linter rules #
#####################################
if [ -f "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" ]; then
if [ -f "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" ]; then
echo "----------------------------------------------"
echo "User provided file:[$FILE_NAME], setting rules file..."
####################################
# Copy users into default location #
####################################
CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1)
CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1)
###################
# Load Error code #
@ -296,7 +309,7 @@ GetLinterRules()
# No user default provided, using the template default #
########################################################
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]"
echo " -> Codebase does NOT have file:[$LINTER_RULES_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]"
fi
fi
}
@ -602,6 +615,42 @@ LintAnsibleFiles()
fi
fi
}
################################################################################
#### Function DetectOpenAPIFile ################################################
DetectOpenAPIFile()
{
################
# Pull in vars #
################
FILE="$1"
###############################
# Check the file for keywords #
###############################
grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "$GITHUB_WORKSPACE/$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 GetGitHubVars ####################################################
GetGitHubVars()
@ -801,7 +850,9 @@ GetValidationInfo()
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_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}')
################################################
# Determine if any linters were explicitly set #
@ -828,6 +879,8 @@ GetValidationInfo()
-n "$VALIDATE_POWERSHELL" || \
-n "$VALIDATE_CSS" || \
-n "$VALIDATE_ENV" || \
-n "$VALIDATE_CLOJURE" || \
-n "$VALIDATE_OPENAPI" || \
-n "$VALIDATE_KOTLIN" ]]; then
ANY_SET="true"
fi
@ -1140,6 +1193,33 @@ GetValidationInfo()
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 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 #
@ -1244,6 +1324,11 @@ GetValidationInfo()
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
@ -1254,6 +1339,11 @@ GetValidationInfo()
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
##############################
# Validate Ansible Directory #
@ -1437,6 +1527,12 @@ BuildFileList()
# 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 #
##########################################################
@ -1449,6 +1545,12 @@ BuildFileList()
# 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 #
##########################################################
@ -1639,6 +1741,15 @@ BuildFileList()
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
elif [ "$FILE" == "clj" ] || [ "$FILE" == "cljs" ] || [ "$FILE" == "cljc" ] || [ "$FILE" == "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 #
@ -1792,12 +1903,22 @@ LintCodebase()
# 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 #
############################################################
@ -1883,7 +2004,7 @@ LintCodebase()
# 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)
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1)
else
################################
# Lint the file with the rules #
@ -2003,11 +2124,21 @@ TestCodebase()
# 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
##################
@ -2215,6 +2346,8 @@ Footer()
[ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
[ "$ERRORS_FOUND_CSS" -ne 0 ] || \
[ "$ERRORS_FOUND_ENV" -ne 0 ] || \
[ "$ERRORS_FOUND_OPENAPI" -ne 0 ] || \
[ "$ERRORS_FOUND_CLOJURE" -ne 0 ] || \
[ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then
# Failed exit
echo "Exiting with errors found!"
@ -2270,13 +2403,15 @@ RunTestCases()
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" ".*\(Dockerfile\)\$"
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 "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$"
#################
# Footer prints #
@ -2626,7 +2761,21 @@ if [ "$VALIDATE_DOCKER" == "true" ]; then
# Lint the docker files #
#########################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}"
LintCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint -c $DOCKER_LINTER_RULES" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}"
fi
###################
# CLOJURE LINTING #
###################
if [ "$VALIDATE_CLOJURE" == "true" ]; then
#################################
# Get Clojure standard rules #
#################################
GetStandardRules "clj-kondo"
#########################
# Lint the Clojure files #
#########################
LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config $CLOJURE_LINTER_RULES --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}"
fi
######################
@ -2640,6 +2789,39 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then
LintCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}"
fi
###################
# OPENAPI LINTING #
###################
if [ "$VALIDATE_OPENAPI" == "true" ]; then
# If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file
if [ "$VALIDATE_ALL_CODEBASE" == "true" ]; then
###############################################################################
# Set the file seperator to newline to allow for grabbing objects with spaces #
###############################################################################
IFS=$'\n'
# shellcheck disable=SC2207
LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1))
for FILE in "${LIST_FILES[@]}"
do
if DetectOpenAPIFile "$FILE"; then
FILE_ARRAY_OPENAPI+=("$FILE")
fi
done
###########################
# Set IFS back to default #
###########################
IFS="$DEFAULT_IFS"
fi
##########################
# Lint the OpenAPI files #
##########################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}"
fi
##########
# Footer #
##########

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
cat <<EOF
--------------------------------------------------------------------------------