Merge pull request #152 from Hanse00/support-any-default

Support any default branch
This commit is contained in:
Zack Koppert 2020-06-18 16:57:38 -07:00 committed by GitHub
commit 9f9b4d2a60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -104,6 +104,7 @@ RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/r
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} \

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`) branches
- 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
@ -113,6 +113,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. |

View file

@ -69,6 +69,7 @@ LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
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
@ -1154,10 +1155,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 #
@ -1169,7 +1170,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
@ -1180,14 +1181,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 comits #
################################################ ################################################
# 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 #
@ -1910,7 +1911,7 @@ 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