Merge branch 'master' into PowershellSupport

This commit is contained in:
Lukas Gravley 2020-06-22 08:16:59 -05:00 committed by GitHub
commit 6682f87622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 510 additions and 253 deletions

View file

@ -1,12 +1,12 @@
# .automation # .automation
This folder holds automation scripts to help `deploy` and `cleanup` **DockerHub** images of the **Super-Linter** This folder holds automation scripts to help `deploy` and `cleanup` **DockerHub** images of the **Super-Linter**
## cleanup-docker.md ## cleanup-docker.sh
This script uses **GitHub Actions** so that when a PR is merged and closed, the **GitHub Action** is triggered. This script uses **GitHub Actions** so that when a PR is merged and closed, the **GitHub Action** is triggered.
It will then search **DockerHub** for the image that was deployed during the development, and remove it. It will then search **DockerHub** for the image that was deployed during the development, and remove it.
## upload-docker.sh ## upload-docker.sh
This script uses **GitHub Actions** so that a push to the repository is committed, it will complete the following: This script uses **GitHub Actions** so that when a push to the repository is committed, it will complete the following:
- Checkout the source code - Checkout the source code
- Build the **Docker** container for **Super-Linter** using that source code - Build the **Docker** container for **Super-Linter** using that source code
- Upload the container to **DockerHub** - Upload the container to **DockerHub**
@ -16,7 +16,7 @@ When the script is triggered in a branch, it will push with the tag:**NameOfBran
- *testing* - *testing*
- *troubleshooting* - *troubleshooting*
- *debugging* - *debugging*
- **Note:** The branch name will be reduced to AlpaNumeric for consistency and uploading - **Note:** The branch name will be reduced to alphanumeric for consistency and uploading
## test ## test
This folder holds all **Test Cases** to help run the *CI/CT/CD* process for the **Super-Linter**. This folder holds all **Test Cases** to help run the *CI/CT/CD* process for the **Super-Linter**.

View file

@ -115,9 +115,9 @@ ValidateInput()
# Check if we need to get the name of the branch # # Check if we need to get the name of the branch #
################################################## ##################################################
if [[ "$IMAGE_VERSION" != "latest" ]]; then if [[ "$IMAGE_VERSION" != "latest" ]]; then
################################### ##################################
# Remove non alpha-numberic chars # # Remove non alpha-numeric chars #
################################### ##################################
IMAGE_VERSION=$(echo "$IMAGE_VERSION" | tr -cd '[:alnum:]') IMAGE_VERSION=$(echo "$IMAGE_VERSION" | tr -cd '[:alnum:]')
else else
############################################# #############################################

View file

@ -42,9 +42,9 @@
group: admin group: admin
mode: 0644 mode: 0644
######################################################### ########################################################
# Set up Admin password, License, and Initial Setttings # # Set up Admin password, License, and Initial Settings #
######################################################### ########################################################
- name: Setup Grafana - name: Setup Grafana
# yamllint disable # yamllint disable
shell: curl --fail -Lk \ shell: curl --fail -Lk \

View file

@ -57,10 +57,10 @@
group: admin group: admin
mode: 0644 mode: 0644
######################################################### ########################################################
# Set up Admin password, License, and Initial Setttings # # Set up Admin password, License, and Initial Settings #
######################################################### ########################################################
- name: Setup License, Admin Password, and Initial Setttings - name: Setup License, Admin Password, and Initial Settings
command: curl --fail -Lk \ command: curl --fail -Lk \
-X POST "https://{{ ansible_host }}:8443/setup/api/start" \ -X POST "https://{{ ansible_host }}:8443/setup/api/start" \
-F license=@/tmp/ghe-license.ghl \ -F license=@/tmp/ghe-license.ghl \

View file

@ -42,9 +42,9 @@
group: admin group: admin
mode: 0644 mode: 0644
######################################################### ########################################################
# Set up Admin password, License, and Initial Setttings # # Set up Admin password, License, and Initial Settings #
######################################################### ########################################################
- name: Setup Splunk - name: Setup Splunk
# yamllint disable # yamllint disable
shell: curl --fail -Lk \ shell: curl --fail -Lk \

View file

@ -60,7 +60,7 @@ module.exports = (robot) -> )
# Drop the hammer # # Drop the hammer #
################### ###################
robot.respond /drop the hammer/i, (msg) -> robot.respond /drop the hammer/i, (msg) ->
msg.send "Commmencing the hammer dropping..." msg.send "Commencing the hammer dropping..."
msg.send msg.random dropHammer msg.send msg.random dropHammer
############### ###############

View file

@ -62,7 +62,7 @@ module.exports = (robot) ->
# Drop the hammer # # Drop the hammer #
################### ###################
robot.respond /drop the hammer/i, (msg) -> robot.respond /drop the hammer/i, (msg) ->
msg.send "Commmencing the hammer dropping..." msg.send "Commencing the hammer dropping..."
msg.send msg.random dropHammer msg.send msg.random dropHammer
############### ###############

View file

@ -0,0 +1,13 @@
# CSS Test Cases
This folder holds the test cases for **CSS**.
## 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,9 @@
/* Bad */
/* Multiline */
/* Comment */
.selector-3[type="text"] {
background: linear-gradient(#FFFFFF, rgba(0, 0, 0, 0.8));
box-sizing: border-box;
display: block;
color: #AAAAAA;
}

View file

@ -0,0 +1,22 @@
/**
* Multi-line comment
*/
.selector-1,
.selector-2,
.selector-3[type="text"] {
background: linear-gradient(#fff, rgba(0, 0, 0, 0.8));
box-sizing: border-box;
display: block;
color: #333;
}
.selector-a,
.selector-b:not(:first-child) {
padding: 10px !important;
top: calc(calc(1em * 2) / 3);
}
.selector-x { width: 10%; }
.selector-y { width: 20%; }
.selector-z { width: 30%; }

13
.automation/test/env/README.md vendored Normal file
View file

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

5
.automation/test/env/env_bad_1.env vendored Normal file
View file

@ -0,0 +1,5 @@
LOGGER_LEVEL=info
MY_ENV
DB-NAME=testing
DEbUG_hTTP=true
DB_NAME=development

4
.automation/test/env/env_good_1.env vendored Normal file
View file

@ -0,0 +1,4 @@
DB_NAME=development
DEBUG_HTTP=true
LOGGER_LEVEL=info
MY_ENV=

View file

@ -7,7 +7,7 @@ var userArray = [ 'user1' ]
here is some garbage = that here is some garbage = that
var teamDescription = Team of Robots var teamDescription = Team of Robots
var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
var teamName = process.env.GHES_TEAM_NAME var teamName = process.env.GHES_TEAM_NAME
var teamAccess = 'pull' // pull,push,admin options here var teamAccess = 'pull' // pull,push,admin options here

View file

@ -5,7 +5,7 @@ var handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) })
var userArray = ['user1'] var userArray = ['user1']
var teamDescription = 'Team of Robots' var teamDescription = 'Team of Robots'
var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
var teamName = process.env.GHES_TEAM_NAME var teamName = process.env.GHES_TEAM_NAME
var teamAccess = 'pull' // pull,push,admin options here var teamAccess = 'pull' // pull,push,admin options here

View file

@ -120,9 +120,9 @@ ValidateInput()
exit 1 exit 1
fi fi
################################### ##################################
# Remove non alpha-numberic chars # # Remove non alpha-numeric chars #
################################### ##################################
BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cd '[:alnum:]') BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cd '[:alnum:]')
############################################ ############################################

View file

@ -40,6 +40,6 @@ If you are the current maintainer of this action:
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com) - [GitHub Help](https://help.github.com)
[pulls]: https://github.com/github/github-demo-stack/pulls [pulls]: https://github.com/github/super-linter/pulls
[pr]: https://github.com/github/github-demo-stack/compare [pr]: https://github.com/github/super-linter/compare
[fork]: https://github.com/github/github-demo-stack/fork [fork]: https://github.com/github/super-linter/fork

View file

@ -18,3 +18,6 @@ A clear and concise description of any alternative solutions or features you've
**Additional context** **Additional context**
Add any other context or screenshots about the feature request here. Add any other context or screenshots about the feature request here.
**Note**
If this is a request to add a new language, after submitting this issue check out [the wiki](https://github.com/github/super-linter/wiki/Adding-new-language-support) for more info on how to accomplish that.

3
.github/linters/.stylelintrc.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"extends": "stylelint-config-standard"
}

View file

@ -3,7 +3,7 @@
# These are the rules used for # # These are the rules used for #
# linting all the yaml files in the stack # # linting all the yaml files in the stack #
# NOTE: # # NOTE: #
# You can disble line with: # # You can disable line with: #
# # yamllint disable-line # # # yamllint disable-line #
########################################### ###########################################
rules: rules:

View file

@ -27,7 +27,25 @@ RUN apk add --no-cache \
libxml2-utils perl \ libxml2-utils perl \
ruby ruby-dev ruby-bundler ruby-rdoc make \ ruby ruby-dev ruby-bundler ruby-rdoc make \
py3-setuptools ansible-lint \ py3-setuptools ansible-lint \
go go \
ca-certificates less ncurses-terminfo-base \
krb5-libs libgcc libintl libssl1.1 libstdc++ \
tzdata userspace-rcu zlib icu-libs lttng-ust
#########################################
# Install Powershell + PSScriptAnalyzer #
#########################################
# Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7
# Slightly modified to always retrieve latest stable Powershell version
RUN mkdir -p /opt/microsoft/powershell/7 \
&& curl -s https://api.github.com/repos/powershell/powershell/releases/latest \
| grep browser_download_url \
| grep linux-alpine-x64 \
| cut -d '"' -f 4 \
| xargs -n 1 wget -O - \
| tar -xzC /opt/microsoft/powershell/7 \
&& ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \
&& pwsh -c 'install-module psscriptanalyzer -force'
##################### #####################
# Run Pip3 Installs # # Run Pip3 Installs #
@ -43,17 +61,19 @@ RUN npm config set package-lock false \
&& npm -g --no-cache install \ && npm -g --no-cache install \
markdownlint-cli \ markdownlint-cli \
jsonlint prettyjson \ jsonlint prettyjson \
coffeelint \ @coffeelint/cli \
typescript eslint \ typescript eslint \
standard \ standard \
babel-eslint \ babel-eslint \
@typescript-eslint/eslint-plugin \ @typescript-eslint/eslint-plugin \
@typescript-eslint/parser \ @typescript-eslint/parser \
eslint-plugin-jest \ eslint-plugin-jest \
stylelint \
stylelint-config-standard \
&& npm --no-cache install \ && npm --no-cache install \
markdownlint-cli \ markdownlint-cli \
jsonlint prettyjson \ jsonlint prettyjson \
coffeelint \ @coffeelint/cli \
typescript eslint \ typescript eslint \
standard \ standard \
babel-eslint \ babel-eslint \
@ -61,7 +81,9 @@ RUN npm config set package-lock false \
eslint-config-prettier \ eslint-config-prettier \
@typescript-eslint/eslint-plugin \ @typescript-eslint/eslint-plugin \
@typescript-eslint/parser \ @typescript-eslint/parser \
eslint-plugin-jest eslint-plugin-jest \
stylelint \
stylelint-config-standard
#################################### ####################################
# Install dockerfilelint from repo # # Install dockerfilelint from repo #
@ -77,7 +99,7 @@ RUN git clone https://github.com/replicatedhq/dockerfilelint.git && cd /dockerfi
RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0
# Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default # Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default
# We then need to promot the correct verion, uninstall, and fix deps # We then need to promote the correct version, uninstall, and fix deps
RUN sh -c 'gem install --default rubocop:0.74.0; yes | gem uninstall rubocop:0.85.1 -a -x -I; gem install rubocop:0.74.0' RUN sh -c 'gem install --default rubocop:0.74.0; yes | gem uninstall rubocop:0.85.1 -a -x -I; gem install rubocop:0.74.0'
###################### ######################
@ -89,7 +111,7 @@ RUN wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/s
##################### #####################
# Install Go Linter # # Install Go Linter #
##################### #####################
ARG GO_VERSION='v1.23.7' ARG GO_VERSION='v1.27.0'
RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "$GO_VERSION" RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "$GO_VERSION"
################## ##################
@ -98,40 +120,11 @@ 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 \ 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/ && mv "tflint" /usr/bin/
######################################### ##################
# Install Powershell + PSScriptAnalyzer # # Install dotenv-linter #
######################################### ##################
# Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7 RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz" -O - -q | tar -xzf - \
# Slightly modified to always retrieve latest stable Powershell version && mv "dotenv-linter" /usr/bin
RUN apk add --no-cache \
ca-certificates \
less \
ncurses-terminfo-base \
krb5-libs \
libgcc \
libintl \
libssl1.1 \
libstdc++ \
tzdata \
userspace-rcu \
zlib \
icu-libs \
curl \
lttng-ust \
&& \
mkdir -p /opt/microsoft/powershell/7 \
&& \
curl -s https://api.github.com/repos/powershell/powershell/releases/latest \
| grep browser_download_url \
| grep linux-alpine-x64 \
| cut -d '"' -f 4 \
| xargs -n 1 wget -O - \
| tar -xzC /opt/microsoft/powershell/7 \
&& \
ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \
&& \
pwsh -c 'install-module psscriptanalyzer -force'
########################################### ###########################################
# Load GitHub Env Vars for GitHub Actions # # Load GitHub Env Vars for GitHub Actions #
@ -139,6 +132,7 @@ RUN apk add --no-cache \
ENV GITHUB_SHA=${GITHUB_SHA} \ ENV GITHUB_SHA=${GITHUB_SHA} \
GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} \ GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} \
GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \
DEFAULT_BRANCH=${DEFAULT_BRANCH} \
VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \ VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \
VALIDATE_YAML=${VALIDATE_YAML} \ VALIDATE_YAML=${VALIDATE_YAML} \
VALIDATE_JSON=${VALIDATE_JSON} \ VALIDATE_JSON=${VALIDATE_JSON} \
@ -157,10 +151,14 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
VALIDATE_TYPESCRIPT_STANDARD=${VALIDATE_TYPESCRIPT_STANDARD} \ VALIDATE_TYPESCRIPT_STANDARD=${VALIDATE_TYPESCRIPT_STANDARD} \
VALIDATE_GO=${VALIDATE_GO} \ VALIDATE_GO=${VALIDATE_GO} \
VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \
VALIDATE_CSS=${VALIDATE_CSS} \
VALIDATE_ENV=${VALIDATE_ENV} \
VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \
ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \
RUN_LOCAL=${RUN_LOCAL} \ RUN_LOCAL=${RUN_LOCAL} \
TEST_CASE_RUN=${TEST_CASE_RUN} \ TEST_CASE_RUN=${TEST_CASE_RUN} \
ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \
DISABLE_ERRORS=${DISABLE_ERRORS}
############################# #############################
# Copy scripts to container # # Copy scripts to container #

View file

@ -3,7 +3,7 @@ This repository is for the **GitHub Action** to run a **Super-Linter**.
It is a simple combination of various linters, written in `bash`, to help validate your source code. It is a simple combination of various linters, written in `bash`, to help validate your source code.
The end goal of this tool: The end goal of this tool:
- Prevent broken code from being uploaded to *master* branches - Prevent broken code from being uploaded to the default branch (Usually `master`)
- Help establish coding best practices across multiple languages - Help establish coding best practices across multiple languages
- Build guidelines for code layout and format - Build guidelines for code layout and format
- Automate the process to help streamline code reviews - Automate the process to help streamline code reviews
@ -19,7 +19,8 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
| *Language* | *Linter* | | *Language* | *Linter* |
| --- | --- | | --- | --- |
| **Ansible** | [ansible-lint](https://github.com/ansible/ansible-lint) | | **Ansible** | [ansible-lint](https://github.com/ansible/ansible-lint) |
| **CoffeeScript** | [coffeelint](http://www.coffeelint.org/) | | **CSS** | [stylelint](https://stylelint.io/) |
| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) |
| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) | | **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) |
| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | | **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) |
| **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) |
@ -33,7 +34,8 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
| **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) |
| **XML** | [LibXML](http://xmlsoft.org/) | | **XML** | [LibXML](http://xmlsoft.org/) |
| **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | | **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) |
| **Powershell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | | **PowerShell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) |
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
## How to use ## How to use
To use this **GitHub** Action you will need to complete the following: To use this **GitHub** Action you will need to complete the following:
@ -94,13 +96,15 @@ jobs:
# Run Linter against code base # # Run Linter against code base #
################################ ################################
- name: Lint Code Base - name: Lint Code Base
uses: github/super-linter@v2.0.0 uses: docker://github/super-linter:v2.1.1
env: env:
VALIDATE_ALL_CODEBASE: false VALIDATE_ALL_CODEBASE: false
VALIDATE_ANSIBLE: 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...
## Environment variables ## Environment variables
The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality. The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality.
@ -114,6 +118,7 @@ and won't run anything unexpected.
| **ENV VAR** | **Default Value** | **Notes** | | **ENV VAR** | **Default Value** | **Notes** |
| --- | --- | --- | | --- | --- | --- |
| **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. | | **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. |
| **VALIDATE_YAML** | `true` |Flag to enable or disable the linting process of the language. | | **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_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. | | **VALIDATE_XML** | `true` | Flag to enable or disable the linting process of the language. |
@ -132,13 +137,17 @@ and won't run anything unexpected.
| **VALIDATE_GO** | `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. |
| **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the language. |
| **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. | | **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. |
| **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). | | **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. | | **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. |
| **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. |
### Template rules files ### Template rules files
You can use the **GitHub** **Super-Linter** *with* or *without* your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level. You can use the **GitHub** **Super-Linter** *with* or *without* your own personal rules sets. This allows for greater flexibility for each individual code base. The Template rules all try to follow the standards we believe should be enabled at the basic level.
- Copy **any** or **all** template rules files from `TEMPLATES/` into your repository in the location: `.github/linters/` of your repository - Copy **any** or **all** template rules files from `TEMPLATES/` into your repository in the location: `.github/linters/` of your repository
- If your repository does not have rules files, they will fall back to defaults in this repositories `TEMPLATE` folder - If your repository does not have rules files, they will fall back to defaults in [this repository's `TEMPLATE` folder](https://github.com/github/super-linter/tree/master/TEMPLATES)
## Disabling rules ## Disabling rules
If you need to disable certain *rules* and *functionality*, you can view [Disable Rules](https://github.com/github/super-linter/blob/master/docs/disabling-linters.md) If you need to disable certain *rules* and *functionality*, you can view [Disable Rules](https://github.com/github/super-linter/blob/master/docs/disabling-linters.md)
@ -156,7 +165,7 @@ The **Super-Linter** has *CI/CT/CD* configured utilizing **GitHub** Actions.
- `.automation/test` contains all test cases for each language that should be validated - `.automation/test` contains all test cases for each language that should be validated
- These **GitHub** Actions utilize the Checks API and Protected Branches to help follow the SDLC - These **GitHub** Actions utilize the Checks API and Protected Branches to help follow the SDLC
- When the Pull Request is merged to master, the **Super-Linter** **Docker** container is then updated and deployed with the new codebase - When the Pull Request is merged to master, the **Super-Linter** **Docker** container is then updated and deployed with the new codebase
- **Note:** The branches **Docker** container is also removed from **DockerHub** to cleanup after itself - **Note:** The branch's **Docker** container is also removed from **DockerHub** to cleanup after itself
## Limitations ## Limitations
Below are a list of the known limitations for the **GitHub Super-Linter**: Below are a list of the known limitations for the **GitHub Super-Linter**:

View file

@ -0,0 +1,3 @@
{
"extends": "stylelint-config-standard"
}

View file

@ -3,7 +3,7 @@
# These are the rules used for # # These are the rules used for #
# linting all the yaml files in the stack # # linting all the yaml files in the stack #
# NOTE: # # NOTE: #
# You can disble line with: # # You can disable line with: #
# # yamllint disable-line # # # yamllint disable-line #
########################################### ###########################################
rules: rules:

View file

@ -2,7 +2,5 @@
The files in this folder are template rules for the linters that will run against your code base. If you chose to copy these to your local repository in the directory: `.github/` they will be used at runtime. If they are not present, they will be used by default in the linter run. The files in this folder are template rules for the linters that will run against your code base. If you chose to copy these to your local repository in the directory: `.github/` they will be used at runtime. If they are not present, they will be used by default in the linter run.
The file(s) will be parsed at run time on the local branch to load all rules needed to run the **Super-Linter** **GitHub** Action. The file(s) will be parsed at run time on the local branch to load all rules needed to run the **Super-Linter** **GitHub** Action.
The **GitHub** Action will inform the user via the **Checks API** on the status and success of the process. The **GitHub** Action will inform the user via the **Checks API** on the status and success of the process.

View file

@ -20,6 +20,8 @@ Below is examples and documentation for each language and the various methods to
- [Golang](#golang) - [Golang](#golang)
- [Dockerfile](#dockerfile) - [Dockerfile](#dockerfile)
- [Terraform](#terraform) - [Terraform](#terraform)
- [CSS](#css)
- [ENV](#env)
<!-- toc --> <!-- toc -->
@ -319,7 +321,7 @@ Here is more data
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
## Coffeescript ## Coffeescript
- [coffeelint](http://www.coffeelint.org/) - [coffeelint](https://coffeelint.github.io/)
### coffeelint Config file ### coffeelint Config file
- `.github/linters/.coffee-lint.yml` - `.github/linters/.coffee-lint.yml`
@ -511,3 +513,54 @@ alert('foo')
- There is currently **No** way to disable rules inline of the file(s) - There is currently **No** way to disable rules inline of the file(s)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
## CSS
- [stylelint](https://stylelint.io/)
### stylelint standard Config file
- `.github/linters/.stylelintrc.json`
### stylelint disable single line
```css
#id {
/* stylelint-disable-next-line declaration-no-important */
color: pink !important;
}
```
### stylelint disable code block
```css
/* stylelint-disable */
a {}
/* stylelint-enable */
```
### stylelint disable entire file
- You can disable entire files with the `ignoreFiles` property in `.stylelintrc.json`
```json
{
"ignoreFiles": [
"styles/ignored/wildcards/*.css",
"styles/ignored/specific-file.css"
]
}
```
--------------------------------------------------------------------------------
## ENV
- [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter)
### dotenv-linter Config file
- There is no top level *configuration file* available at this time
### dotenv-linter disable single line
```env
# Comment line will be ignored
```
### dotenv-linter disable code block
- There is currently **No** way to disable rules inline of the file(s)
### dotenv-linter disable entire file
- There is currently **No** way to disable rules inline of the file(s)

View file

@ -20,6 +20,7 @@ Once the container has been downloaded to your local environment, you can then b
- `docker run -e RUN_LOCAL=true -v /path/to/local/codebase:/tmp/lint github/super-linter` - `docker run -e RUN_LOCAL=true -v /path/to/local/codebase:/tmp/lint github/super-linter`
- To run against a single file you can use: `docker run -e RUN_LOCAL=true -v /path/to/local/codebase/file:/tmp/lint/file github/super-linter` - To run against a single file you can use: `docker run -e RUN_LOCAL=true -v /path/to/local/codebase/file:/tmp/lint/file github/super-linter`
- **NOTE:** You need to pass the `RUN_LOCAL` flag to bypass some of the GitHub Actions checks, as well as the mapping of your local codebase to `/tmp/lint` so that the linter can pick up the code - **NOTE:** You need to pass the `RUN_LOCAL` flag to bypass some of the GitHub Actions checks, as well as the mapping of your local codebase to `/tmp/lint` so that the linter can pick up the code
- **NOTE:** If you want to override the `/tmp/lint` folder, you can set the `DEFAULT_WORKSPACE` environment variable to point to the folder you'd prefer to scan.
- **NOTE:** The flag:`RUN_LOCAL` will set: `VALIDATE_ALL_CODEBASE` to true. This means it will scan **all** the files in the directory you have mapped. If you want to only validate a subset of your codebase, map a folder with only the files you wish to have linted - **NOTE:** The flag:`RUN_LOCAL` will set: `VALIDATE_ALL_CODEBASE` to true. This means it will scan **all** the files in the directory you have mapped. If you want to only validate a subset of your codebase, map a folder with only the files you wish to have linted
### Flags for running Locally ### Flags for running Locally

View file

@ -32,7 +32,7 @@ COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to
JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules 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 JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
# Typecript Vars # Typescript Vars
TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file
TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules 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 TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard
@ -51,28 +51,33 @@ TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path
# Powershell Vars # Powershell Vars
POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file
POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Path to the Powershell lint rules POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Path to the Powershell lint rules
# 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
####################################### #######################################
# Linter array for information prints # # Linter array for information prints #
####################################### #######################################
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" "powershell") "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
"stylelint" "dotenv-linter" "powershell")
############################# #############################
# Language array for prints # # Language array for prints #
############################# #############################
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON' LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'POWERSHELL') 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS'
'ENV' 'POWERSHELL')
################### ###################
# GitHub ENV Vars # # GitHub ENV Vars #
################### ###################
GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit
GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # GitHub Event Path GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace
DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default)
ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory
VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files
VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language
@ -93,7 +98,10 @@ VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate lang
VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language
VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # 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
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases 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
############## ##############
# Debug Vars # # Debug Vars #
@ -105,7 +113,7 @@ ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG}" # Boolean to see even more info
# Default Vars # # Default Vars #
################ ################
DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files
DEFAULT_WORKSPACE='/tmp/lint' # Default workspace if running locally DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally
DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory
DEFAULT_RUN_LOCAL='false' # Default value for debugging locally DEFAULT_RUN_LOCAL='false' # Default value for debugging locally
DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases
@ -113,6 +121,7 @@ DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugg
RAW_FILE_ARRAY=() # Array of all files that were changed 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 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 TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore
DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors
########################## ##########################
# Array of changed files # # Array of changed files #
@ -134,7 +143,8 @@ FILE_ARRAY_DOCKER=() # Array of files to check
FILE_ARRAY_GO=() # Array of files to check FILE_ARRAY_GO=() # Array of files to check
FILE_ARRAY_TERRAFORM=() # 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
############ ############
# Counters # # Counters #
@ -157,6 +167,8 @@ ERRORS_FOUND_DOCKER=0 # Count of errors found
ERRORS_FOUND_GO=0 # Count of errors found ERRORS_FOUND_GO=0 # Count of errors found
ERRORS_FOUND_TERRAFORM=0 # Count of errors found ERRORS_FOUND_TERRAFORM=0 # Count of errors found
ERRORS_FOUND_POWERSHELL=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
################################################################################ ################################################################################
########################## FUNCTIONS BELOW ##################################### ########################## FUNCTIONS BELOW #####################################
@ -217,7 +229,7 @@ GetLinterVersions()
############################## ##############################
# Check the shell for errors # # Check the shell for errors #
############################## ##############################
if [ $ERROR_CODE -ne 0 ] | [ -z "${GET_VERSION_CMD[*]}" ]; then if [ $ERROR_CODE -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then
echo "WARN! Failed to get version info for:[$LINTER]" echo "WARN! Failed to get version info for:[$LINTER]"
echo "---------------------------------------------" echo "---------------------------------------------"
else else
@ -348,9 +360,9 @@ GetStandardRules()
ENV_STRING+="--env ${ENV} " ENV_STRING+="--env ${ENV} "
done done
######################################## #########################################
# Remove trailing and ending witespace # # Remove trailing and ending whitespace #
######################################## #########################################
if [[ "$LINTER" == "javascript" ]]; then if [[ "$LINTER" == "javascript" ]]; then
JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
elif [[ "$LINTER" == "typescript" ]]; then elif [[ "$LINTER" == "typescript" ]]; then
@ -734,6 +746,8 @@ GetValidationInfo()
VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}') VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}')
VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}') VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}')
VALIDATE_POWERSHELL=$(echo "$VALIDATE_POWERSHELL" | 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)}')
################################################ ################################################
# Determine if any linters were explicitly set # # Determine if any linters were explicitly set #
@ -757,7 +771,8 @@ GetValidationInfo()
-n "$VALIDATE_GO" || \ -n "$VALIDATE_GO" || \
-n "$VALIDATE_TERRAFORM" || \ -n "$VALIDATE_TERRAFORM" || \
-n "$VALIDATE_POWERSHELL" \ -n "$VALIDATE_POWERSHELL" \
]]; then -n "$VALIDATE_CSS" || \
-n "$VALIDATE_ENV" ]]; then
ANY_SET="true" ANY_SET="true"
fi fi
@ -1011,6 +1026,33 @@ GetValidationInfo()
else else
# No linter flags were set - default all to true # No linter flags were set - default all to true
VALIDATE_POWERSHELL="true" VALIDATE_POWERSHELL="true"
###################################
# 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 fi
####################################### #######################################
@ -1105,6 +1147,15 @@ GetValidationInfo()
PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...") PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...")
else else
PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...") PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...")
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_ENV" == "true" ]]; then
PRINT_ARRAY+=("- Validating [ENV] files in code base...")
else
PRINT_ARRAY+=("- Excluding [ENV] files in code base...")
fi fi
############################## ##############################
@ -1125,6 +1176,28 @@ GetValidationInfo()
ANSIBLE_DIRECTORY="$TEMP_ANSIBLE_DIRECTORY" ANSIBLE_DIRECTORY="$TEMP_ANSIBLE_DIRECTORY"
fi 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 # # Get the run verbose flag #
############################ ############################
@ -1184,10 +1257,10 @@ BuildFileList()
echo "Pulling in code history and branches..." echo "Pulling in code history and branches..."
fi fi
##################################################################### #################################################################################
# Switch codebase back to master to get a list of all files changed # # 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 master 2>&1) SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull --quiet; git checkout "$DEFAULT_BRANCH" 2>&1)
####################### #######################
# Load the error code # # Load the error code #
@ -1199,7 +1272,7 @@ BuildFileList()
############################## ##############################
if [ $ERROR_CODE -ne 0 ]; then if [ $ERROR_CODE -ne 0 ]; then
# Error # Error
echo "Failed to switch to master branch to get files changed!" echo "Failed to switch to $DEFAULT_BRANCH branch to get files changed!"
echo "ERROR:[$SWITCH_CMD]" echo "ERROR:[$SWITCH_CMD]"
exit 1 exit 1
fi fi
@ -1210,14 +1283,14 @@ BuildFileList()
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
echo "" echo ""
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Generating Diff with:[git diff --name-only 'master..$GITHUB_SHA' --diff-filter=d]" echo "Generating Diff with:[git diff --name-only '$DEFAULT_BRANCH..$GITHUB_SHA' --diff-filter=d]"
fi fi
################################################ #################################################
# Get the Array of files changed in the comits # # Get the Array of files changed in the commits #
################################################ #################################################
# shellcheck disable=SC2207 # shellcheck disable=SC2207
RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "master..$GITHUB_SHA" --diff-filter=d 2>&1)) RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "$DEFAULT_BRANCH..$GITHUB_SHA" --diff-filter=d 2>&1))
####################### #######################
# Load the error code # # Load the error code #
@ -1234,9 +1307,9 @@ BuildFileList()
exit 1 exit 1
fi fi
################################################# ################################################
# Itterate through the array of all files found # # Iterate through the array of all files found #
################################################# ################################################
echo "" echo ""
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Files that have been modified in the commit(s):" echo "Files that have been modified in the commit(s):"
@ -1421,6 +1494,20 @@ BuildFileList()
# Append the file to the array # # Append the file to the array #
################################ ################################
FILE_ARRAY_POWERSHELL+=("$FILE") 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 # # Set the READ_ONLY_CHANGE_FLAG since this could be exec #
########################################################## ##########################################################
@ -1582,7 +1669,7 @@ LintCodebase()
if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then
# No files found in commit and user has asked to not validate code base # No files found in commit and user has asked to not validate code base
SKIP_FLAG=1 SKIP_FLAG=1
# echo " - No files found in chageset to lint for language:[$FILE_TYPE]" # echo " - No files found in changeset to lint for language:[$FILE_TYPE]"
elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then
# We have files added to array of files to check # We have files added to array of files to check
LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list
@ -1911,10 +1998,16 @@ Footer()
fi fi
done done
##################################
# Exit with 0 if errors disabled #
##################################
if [ "$DISABLE_ERRORS" == "true" ]; then
echo "WARN! Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[$DISABLE_ERRORS]"
exit 0
############################### ###############################
# Exit with 1 if errors found # # Exit with 1 if errors found #
############################### ###############################
if [ "$ERRORS_FOUND_YML" -ne 0 ] || \ elif [ "$ERRORS_FOUND_YML" -ne 0 ] || \
[ "$ERRORS_FOUND_JSON" -ne 0 ] || \ [ "$ERRORS_FOUND_JSON" -ne 0 ] || \
[ "$ERRORS_FOUND_XML" -ne 0 ] || \ [ "$ERRORS_FOUND_XML" -ne 0 ] || \
[ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \ [ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \
@ -1931,7 +2024,9 @@ Footer()
[ "$ERRORS_FOUND_GO" -ne 0 ] || \ [ "$ERRORS_FOUND_GO" -ne 0 ] || \
[ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \ [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \
[ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \ [ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \
[ "$ERRORS_FOUND_RUBY" -ne 0 ]; then [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \
[ "$ERRORS_FOUND_CSS" -ne 0 ] || \
[ "$ERRORS_FOUND_ENV" -ne 0 ]; then
# Failed exit # Failed exit
echo "Exiting with errors found!" echo "Exiting with errors found!"
exit 1 exit 1
@ -1953,11 +2048,11 @@ RunTestCases()
{ {
# This loop will run the test cases and exclude user code # This loop will run the test cases and exclude user code
# This is called from the automation process to validate new code # This is called from the automation process to validate new code
# When a PR is opened, the new code is validated with the master branch # 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 # version of linter.sh, and a new container is built with the latest codebase
# for testing. That container is spun up, and ran, # for testing. That container is spun up, and ran,
# with the flag: TEST_CASE_RUN=true # with the flag: TEST_CASE_RUN=true
# So that the new code can be validated againt the test cases # So that the new code can be validated against the test cases
################# #################
# Header prints # # Header prints #
@ -1989,6 +2084,8 @@ RunTestCases()
TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint"
TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$"
TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES'" ".*\.\(ps\.\*\)\$" TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES'" ".*\.\(ps\.\*\)\$"
TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$"
TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$"
################# #################
# Footer prints # # Footer prints #
@ -2013,9 +2110,9 @@ Header
# needed to connect back and update checks # needed to connect back and update checks
GetGitHubVars GetGitHubVars
########################################## #########################################
# Get the langugages we need to validate # # Get the languages we need to validate #
########################################## #########################################
GetValidationInfo GetValidationInfo
######################## ########################
@ -2043,9 +2140,10 @@ GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES"
GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES" GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES"
# Get Terraform rules # Get Terraform rules
GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES"
# Get Terraform rules # Get PowerShell rules
GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES" GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES"
# Get CSS rules
GetLinterRules "$CSS_FILE_NAME" "$CSS_LINTER_RULES"
################################# #################################
# Check if were in verbose mode # # Check if were in verbose mode #
@ -2261,6 +2359,31 @@ if [ "$VALIDATE_TYPESCRIPT_STANDARD" == "true" ]; then
LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}" LintCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES" ".*\.\(ts\)\$" "${FILE_ARRAY_TYPESCRIPT_STANDARD[@]}"
fi fi
###############
# CSS LINTING #
###############
if [ "$VALIDATE_CSS" == "true" ]; then
#################################
# Get CSS standard rules #
#################################
GetStandardRules "stylelint"
#############################
# Lint the CSS files #
#############################
LintCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}"
fi
################
# ENV LINTING #
################
if [ "$VALIDATE_ENV" == "true" ]; then
#######################
# Lint the env files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}"
fi
################## ##################
# DOCKER LINTING # # DOCKER LINTING #
################## ##################