2024-01-30 14:24:55 -05:00
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
2024-08-07 09:36:16 -04:00
# shellcheck source=/dev/null
source "test/testUtils.sh"
2024-01-30 14:24:55 -05:00
SUPER_LINTER_TEST_CONTAINER_URL = " ${ 1 } "
TEST_FUNCTION_NAME = " ${ 2 } "
2024-07-11 04:01:11 -04:00
SUPER_LINTER_CONTAINER_IMAGE_TYPE = " ${ 3 } "
2024-08-12 06:31:38 -04:00
debug " Super-linter container image type: ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } "
2024-01-30 14:24:55 -05:00
2024-04-18 02:48:55 -04:00
DEFAULT_BRANCH = "main"
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN = ( docker run --rm -t -e DEFAULT_BRANCH = " ${ DEFAULT_BRANCH } " -e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = "true" )
2024-04-18 02:48:55 -04:00
2024-04-30 11:58:11 -04:00
ignore_test_cases( ) {
COMMAND_TO_RUN += ( -e FILTER_REGEX_EXCLUDE = ".*(/test/linters/|CHANGELOG.md).*" )
}
2024-08-12 06:31:38 -04:00
configure_typescript_for_test_cases( ) {
COMMAND_TO_RUN += ( --env TYPESCRIPT_STANDARD_TSCONFIG_FILE = ".github/linters/tsconfig.json" )
}
2024-04-18 02:48:55 -04:00
configure_linters_for_test_cases( ) {
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN += ( -e TEST_CASE_RUN = "true" -e JSCPD_CONFIG_FILE = ".jscpd-test-linters.json" -e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES = "default.json,hoge.json" )
2024-08-12 06:31:38 -04:00
configure_typescript_for_test_cases
2024-04-18 02:48:55 -04:00
}
2024-01-30 14:24:55 -05:00
run_test_cases_expect_failure( ) {
2024-04-18 02:48:55 -04:00
configure_linters_for_test_cases
2024-01-30 14:24:55 -05:00
COMMAND_TO_RUN += ( -e ANSIBLE_DIRECTORY = "/test/linters/ansible/bad" -e CHECKOV_FILE_NAME = ".checkov-test-linters-failure.yaml" -e FILTER_REGEX_INCLUDE = ".*bad.*" )
EXPECTED_EXIT_CODE = 1
2024-07-30 02:35:14 -04:00
EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH = " test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-failure- ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } .md "
2024-01-30 14:24:55 -05:00
}
run_test_cases_expect_success( ) {
2024-04-18 02:48:55 -04:00
configure_linters_for_test_cases
2024-01-30 14:24:55 -05:00
COMMAND_TO_RUN += ( -e ANSIBLE_DIRECTORY = "/test/linters/ansible/good" -e CHECKOV_FILE_NAME = ".checkov-test-linters-success.yaml" -e FILTER_REGEX_INCLUDE = ".*good.*" )
2024-07-30 02:35:14 -04:00
EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH = " test/data/super-linter-summary/markdown/table/expected-summary-test-linters-expect-success- ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } .md "
2024-01-30 14:24:55 -05:00
}
2024-02-09 13:43:58 -05:00
run_test_cases_log_level( ) {
run_test_cases_expect_success
LOG_LEVEL = "NOTICE"
}
2024-02-10 04:16:31 -05:00
run_test_cases_expect_failure_notice_log( ) {
run_test_cases_expect_failure
LOG_LEVEL = "NOTICE"
}
2024-02-09 17:57:01 -05:00
run_test_cases_non_default_home( ) {
run_test_cases_expect_success
COMMAND_TO_RUN += ( -e HOME = /tmp)
}
2024-02-27 13:17:22 -05:00
run_test_case_bash_exec_library_expect_failure( ) {
run_test_cases_expect_failure
COMMAND_TO_RUN += ( -e BASH_EXEC_IGNORE_LIBRARIES = "true" )
}
run_test_case_bash_exec_library_expect_success( ) {
run_test_cases_expect_success
COMMAND_TO_RUN += ( -e BASH_EXEC_IGNORE_LIBRARIES = "true" )
}
2024-08-16 10:23:52 -04:00
run_test_case_dont_save_super_linter_log_file( ) {
run_test_cases_expect_success
CREATE_LOG_FILE = "false"
}
run_test_case_dont_save_super_linter_output( ) {
run_test_cases_expect_success
SAVE_SUPER_LINTER_OUTPUT = "false"
}
2024-08-02 04:37:27 -04:00
initialize_git_repository_and_test_args( ) {
local GIT_REPOSITORY_PATH = " ${ 1 } "
2024-04-18 02:48:55 -04:00
# shellcheck disable=SC2064 # Once the path is set, we don't expect it to change
2024-08-12 06:31:38 -04:00
trap " sudo rm -fr ' ${ GIT_REPOSITORY_PATH } ' " EXIT
debug " GIT_REPOSITORY_PATH: ${ GIT_REPOSITORY_PATH } "
2024-04-18 02:48:55 -04:00
2024-08-02 04:37:27 -04:00
local GITHUB_EVENT_FILE_PATH = " ${ 2 } "
2024-04-18 02:48:55 -04:00
git -C " ${ GIT_REPOSITORY_PATH } " init --initial-branch= " ${ DEFAULT_BRANCH } "
git -C " ${ GIT_REPOSITORY_PATH } " config user.name "Super-linter Test"
git -C " ${ GIT_REPOSITORY_PATH } " config user.email "super-linter-test@example.com"
2024-08-02 04:37:27 -04:00
# Put an arbitrary JSON file in the repository to trigger some validation
cp -v " ${ GITHUB_EVENT_FILE_PATH } " " ${ GIT_REPOSITORY_PATH } / "
2024-04-18 02:48:55 -04:00
git -C " ${ GIT_REPOSITORY_PATH } " add .
git -C " ${ GIT_REPOSITORY_PATH } " commit -m "feat: initial commit"
RUN_LOCAL = false
SUPER_LINTER_WORKSPACE = " ${ GIT_REPOSITORY_PATH } "
COMMAND_TO_RUN += ( -e GITHUB_WORKSPACE = "/tmp/lint" )
COMMAND_TO_RUN += ( -e GITHUB_EVENT_NAME = "push" )
2024-08-02 04:37:27 -04:00
COMMAND_TO_RUN += ( -e GITHUB_EVENT_PATH = " /tmp/lint/ $( basename " ${ GITHUB_EVENT_FILE_PATH } " ) " )
2024-04-18 02:48:55 -04:00
COMMAND_TO_RUN += ( -e MULTI_STATUS = false )
COMMAND_TO_RUN += ( -e VALIDATE_ALL_CODEBASE = false )
2024-08-12 06:31:38 -04:00
}
initialize_github_sha( ) {
local GIT_REPOSITORY_PATH = " ${ 1 } "
local TEST_GITHUB_SHA
TEST_GITHUB_SHA = " $( git -C " ${ GIT_REPOSITORY_PATH } " rev-parse HEAD) "
COMMAND_TO_RUN += ( -e GITHUB_SHA = " ${ TEST_GITHUB_SHA } " )
2024-04-18 02:48:55 -04:00
}
2024-08-02 04:37:27 -04:00
run_test_case_git_initial_commit( ) {
local GIT_REPOSITORY_PATH
GIT_REPOSITORY_PATH = " $( mktemp -d) "
initialize_git_repository_and_test_args " ${ GIT_REPOSITORY_PATH } " "test/data/github-event/github-event-push.json"
2024-08-12 06:31:38 -04:00
initialize_github_sha " ${ GIT_REPOSITORY_PATH } "
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN += ( -e VALIDATE_JSON = "true" )
2024-08-02 04:37:27 -04:00
}
run_test_case_merge_commit_push( ) {
local GIT_REPOSITORY_PATH
GIT_REPOSITORY_PATH = " $( mktemp -d) "
initialize_git_repository_and_test_args " ${ GIT_REPOSITORY_PATH } " "test/data/github-event/github-event-push-merge-commit.json"
local NEW_BRANCH_NAME = "branch-1"
git -C " ${ GIT_REPOSITORY_PATH } " switch --create " ${ NEW_BRANCH_NAME } "
cp -v "test/data/github-event/github-event-push-merge-commit.json" " ${ GIT_REPOSITORY_PATH } /new-file-1.json "
git -C " ${ GIT_REPOSITORY_PATH } " add .
git -C " ${ GIT_REPOSITORY_PATH } " commit -m "feat: add new file 1"
cp -v "test/data/github-event/github-event-push-merge-commit.json" " ${ GIT_REPOSITORY_PATH } /new-file-2.json "
git -C " ${ GIT_REPOSITORY_PATH } " add .
git -C " ${ GIT_REPOSITORY_PATH } " commit -m "feat: add new file 2"
cp -v "test/data/github-event/github-event-push-merge-commit.json" " ${ GIT_REPOSITORY_PATH } /new-file-3.json "
git -C " ${ GIT_REPOSITORY_PATH } " add .
git -C " ${ GIT_REPOSITORY_PATH } " commit -m "feat: add new file 3"
git -C " ${ GIT_REPOSITORY_PATH } " switch " ${ DEFAULT_BRANCH } "
# Force the creation of a merge commit
git -C " ${ GIT_REPOSITORY_PATH } " merge \
-m "Merge commit" \
--no-ff \
" ${ NEW_BRANCH_NAME } "
git -C " ${ GIT_REPOSITORY_PATH } " branch -d " ${ NEW_BRANCH_NAME } "
git -C " ${ GIT_REPOSITORY_PATH } " log --all --graph --abbrev-commit --decorate --format= oneline
2024-08-12 06:31:38 -04:00
initialize_github_sha " ${ GIT_REPOSITORY_PATH } "
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN += ( -e VALIDATE_JSON = "true" )
2024-08-02 04:37:27 -04:00
}
2024-04-30 11:58:11 -04:00
run_test_case_use_find_and_ignore_gitignored_files( ) {
ignore_test_cases
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN += ( -e IGNORE_GITIGNORED_FILES = "true" )
COMMAND_TO_RUN += ( -e USE_FIND_ALGORITHM = "true" )
2024-04-30 11:58:11 -04:00
}
2024-07-01 08:50:52 -04:00
run_test_cases_save_super_linter_output( ) {
run_test_cases_expect_success
}
run_test_cases_save_super_linter_output_custom_path( ) {
run_test_cases_save_super_linter_output
SUPER_LINTER_OUTPUT_DIRECTORY_NAME = "custom-super-linter-output-directory-name"
}
2024-07-28 15:34:40 -04:00
run_test_case_custom_summary( ) {
run_test_cases_expect_success
SUPER_LINTER_SUMMARY_FILE_NAME = "custom-github-step-summary.md"
}
2024-08-14 08:54:16 -04:00
run_test_case_gitleaks_custom_log_level( ) {
run_test_cases_expect_success
COMMAND_TO_RUN += ( --env GITLEAKS_LOG_LEVEL = "warn" )
}
2024-08-07 09:36:16 -04:00
run_test_case_fix_mode( ) {
2024-08-12 12:01:40 -04:00
VERIFY_FIX_MODE = "true"
2024-08-07 09:36:16 -04:00
2024-08-12 06:31:38 -04:00
GIT_REPOSITORY_PATH = " $( mktemp -d) "
initialize_git_repository_and_test_args " ${ GIT_REPOSITORY_PATH } " "test/data/github-event/github-event-push.json"
2024-08-12 12:01:40 -04:00
# Remove leftovers before copying test files because other tests might have
# created temporary files and caches as the root user, so commands that
# need access to those files might fail if they run as a non-root user.
RemoveTestLeftovers
2024-08-12 06:31:38 -04:00
local LINTERS_TEST_CASES_FIX_MODE_DESTINATION_PATH = " ${ GIT_REPOSITORY_PATH } / ${ LINTERS_TEST_CASE_DIRECTORY } "
mkdir -p " ${ LINTERS_TEST_CASES_FIX_MODE_DESTINATION_PATH } "
for LANGUAGE in " ${ LANGUAGES_WITH_FIX_MODE [@] } " ; do
if [ [ " ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } " = = "slim" ] ] &&
! IsLanguageInSlimImage " ${ LANGUAGE } " ; then
debug " Skip ${ LANGUAGE } because it's not available in the Super-linter ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } image "
continue
fi
local -l LOWERCASE_LANGUAGE = " ${ LANGUAGE } "
cp -rv " ${ LINTERS_TEST_CASE_DIRECTORY } / ${ LOWERCASE_LANGUAGE } " " ${ LINTERS_TEST_CASES_FIX_MODE_DESTINATION_PATH } / "
eval " COMMAND_TO_RUN+=(--env FIX_ ${ LANGUAGE } =\"true\") "
eval " COMMAND_TO_RUN+=(--env VALIDATE_ ${ LANGUAGE } =\"true\") "
done
# Copy gitignore so we don't commit eventual leftovers from previous runs
cp -v ".gitignore" " ${ GIT_REPOSITORY_PATH } / "
# Copy fix mode linter configuration files because default ones are not always
# suitable for fix mode
local FIX_MODE_LINTERS_CONFIG_DIR = " ${ GIT_REPOSITORY_PATH } /.github/linters "
mkdir -p " ${ FIX_MODE_LINTERS_CONFIG_DIR } "
cp -rv "test/linters-config/fix-mode/." " ${ FIX_MODE_LINTERS_CONFIG_DIR } / "
cp -rv ".github/linters/tsconfig.json" " ${ FIX_MODE_LINTERS_CONFIG_DIR } / "
git -C " ${ GIT_REPOSITORY_PATH } " add .
git -C " ${ GIT_REPOSITORY_PATH } " commit --no-verify -m "feat: add fix mode test cases"
initialize_github_sha " ${ GIT_REPOSITORY_PATH } "
# Enable test mode so we run linters and formatters only against their test
# cases
2024-08-16 10:23:52 -04:00
COMMAND_TO_RUN += ( --env FIX_MODE_TEST_CASE_RUN = "true" )
COMMAND_TO_RUN += ( --env TEST_CASE_RUN = "true" )
2024-08-12 06:31:38 -04:00
COMMAND_TO_RUN += ( --env ANSIBLE_DIRECTORY = "/test/linters/ansible/bad" )
configure_typescript_for_test_cases
# Some linters report a non-zero exit code even if they fix all the issues
EXPECTED_EXIT_CODE = 2
2024-08-16 10:23:52 -04:00
EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH = " test/data/super-linter-summary/markdown/table/expected-summary-test-linters-fix-mode- ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } .md "
2024-08-07 09:36:16 -04:00
}
2024-01-30 14:24:55 -05:00
# Run the test setup function
${ TEST_FUNCTION_NAME }
2024-08-16 10:23:52 -04:00
CREATE_LOG_FILE = " ${ CREATE_LOG_FILE :- "true" } "
debug " CREATE_LOG_FILE: ${ CREATE_LOG_FILE } "
SAVE_SUPER_LINTER_OUTPUT = " ${ SAVE_SUPER_LINTER_OUTPUT :- true } "
2024-07-01 08:50:52 -04:00
2024-08-12 06:31:38 -04:00
SUPER_LINTER_WORKSPACE = " ${ SUPER_LINTER_WORKSPACE :- $( pwd ) } "
COMMAND_TO_RUN += ( -v " ${ SUPER_LINTER_WORKSPACE } " :"/tmp/lint" )
2024-07-01 08:50:52 -04:00
if [ -n " ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME :- } " ] ; then
COMMAND_TO_RUN += ( -e SUPER_LINTER_OUTPUT_DIRECTORY_NAME = " ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME } " )
fi
2024-07-28 15:34:40 -04:00
SUPER_LINTER_OUTPUT_DIRECTORY_NAME = " ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME :- "super-linter-output" } "
2024-08-12 06:31:38 -04:00
SUPER_LINTER_MAIN_OUTPUT_PATH = " ${ SUPER_LINTER_WORKSPACE } / ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME } "
debug " Super-linter main output path: ${ SUPER_LINTER_MAIN_OUTPUT_PATH } "
2024-07-28 15:34:40 -04:00
SUPER_LINTER_OUTPUT_PATH = " ${ SUPER_LINTER_MAIN_OUTPUT_PATH } /super-linter "
2024-08-12 06:31:38 -04:00
debug " Super-linter output path: ${ SUPER_LINTER_OUTPUT_PATH } "
2024-04-20 05:18:14 -04:00
COMMAND_TO_RUN += ( -e CREATE_LOG_FILE = " ${ CREATE_LOG_FILE } " )
2024-02-09 13:43:58 -05:00
COMMAND_TO_RUN += ( -e LOG_LEVEL = " ${ LOG_LEVEL :- "DEBUG" } " )
2024-04-18 02:48:55 -04:00
COMMAND_TO_RUN += ( -e RUN_LOCAL = " ${ RUN_LOCAL :- true } " )
2024-07-01 08:50:52 -04:00
COMMAND_TO_RUN += ( -e SAVE_SUPER_LINTER_OUTPUT = " ${ SAVE_SUPER_LINTER_OUTPUT } " )
2024-07-28 15:34:40 -04:00
2024-08-12 06:31:38 -04:00
SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH = " ${ SUPER_LINTER_WORKSPACE } /github-step-summary.md "
2024-07-28 15:34:40 -04:00
# We can't put this inside SUPER_LINTER_MAIN_OUTPUT_PATH because it doesn't exist
# before Super-linter creates it, and we want to verify that as well.
2024-08-12 06:31:38 -04:00
debug " SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH: ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } "
2024-07-28 15:34:40 -04:00
if [ -n " ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH :- } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Expected Super-linter step summary file path: ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } "
2024-07-11 04:01:11 -04:00
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = "true"
2024-07-28 15:34:40 -04:00
SAVE_SUPER_LINTER_SUMMARY = "true"
COMMAND_TO_RUN += ( -e GITHUB_STEP_SUMMARY = " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " )
COMMAND_TO_RUN += ( -v " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " :" ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " )
fi
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY :- "false" } "
COMMAND_TO_RUN += ( -e ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " )
COMMAND_TO_RUN += ( -e SAVE_SUPER_LINTER_SUMMARY = " ${ SAVE_SUPER_LINTER_SUMMARY :- "false" } " )
if [ -n " ${ SUPER_LINTER_SUMMARY_FILE_NAME :- } " ] ; then
COMMAND_TO_RUN += ( -e SUPER_LINTER_SUMMARY_FILE_NAME = " ${ SUPER_LINTER_SUMMARY_FILE_NAME } " )
2024-07-11 04:01:11 -04:00
fi
2024-07-28 15:34:40 -04:00
SUPER_LINTER_SUMMARY_FILE_NAME = " ${ SUPER_LINTER_SUMMARY_FILE_NAME :- "super-linter-summary.md" } "
2024-08-12 06:31:38 -04:00
debug " SUPER_LINTER_SUMMARY_FILE_NAME: ${ SUPER_LINTER_SUMMARY_FILE_NAME } "
2024-07-28 15:34:40 -04:00
SUPER_LINTER_SUMMARY_FILE_PATH = " ${ SUPER_LINTER_MAIN_OUTPUT_PATH } / ${ SUPER_LINTER_SUMMARY_FILE_NAME } "
2024-08-12 06:31:38 -04:00
debug " Super-linter summary output path: ${ SUPER_LINTER_SUMMARY_FILE_PATH } "
2024-07-28 15:34:40 -04:00
2024-08-12 06:31:38 -04:00
LOG_FILE_PATH = " ${ SUPER_LINTER_WORKSPACE } /super-linter.log "
2024-08-12 12:01:40 -04:00
debug " Super-linter log file path: ${ LOG_FILE_PATH } "
2024-07-11 04:01:11 -04:00
2024-01-30 14:24:55 -05:00
COMMAND_TO_RUN += ( " ${ SUPER_LINTER_TEST_CONTAINER_URL } " )
declare -i EXPECTED_EXIT_CODE
EXPECTED_EXIT_CODE = ${ EXPECTED_EXIT_CODE :- 0 }
2024-08-12 12:01:40 -04:00
RemoveTestLeftovers
2024-07-28 15:34:40 -04:00
if [ [ " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " = = "true" ] ] ; then
2024-08-12 06:31:38 -04:00
debug " Creating GitHub Actions step summary file: ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } "
2024-07-28 15:34:40 -04:00
touch " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } "
fi
2024-08-12 06:31:38 -04:00
debug " Command to run: ${ COMMAND_TO_RUN [*] } "
2024-01-30 14:24:55 -05:00
2024-08-12 06:31:38 -04:00
# Disable failures on error so we can continue with tests regardless
# of the Super-linter exit code
set +o errexit
2024-01-30 14:24:55 -05:00
" ${ COMMAND_TO_RUN [@] } "
SUPER_LINTER_EXIT_CODE = $?
2024-08-12 06:31:38 -04:00
# Enable the errexit option that we check later
2024-01-30 14:24:55 -05:00
set -o errexit
2024-08-12 06:31:38 -04:00
debug " Super-linter workspace: ${ SUPER_LINTER_WORKSPACE } "
debug " Super-linter exit code: ${ SUPER_LINTER_EXIT_CODE } "
2024-01-30 14:24:55 -05:00
2024-04-20 05:18:14 -04:00
if [ [ " ${ CREATE_LOG_FILE } " = = true ] ] ; then
if [ ! -e " ${ LOG_FILE_PATH } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Log file was requested but it's not available at ${ LOG_FILE_PATH } "
2024-04-20 05:18:14 -04:00
exit 1
else
sudo chown -R " $( id -u) " :" $( id -g) " " ${ LOG_FILE_PATH } "
2024-08-12 06:31:38 -04:00
debug " Log file path: ${ LOG_FILE_PATH } "
if [ [ " ${ CI :- } " = = "true" ] ] ; then
debug "Log file contents:"
cat " ${ LOG_FILE_PATH } "
else
debug " Not in CI environment, skip emitting log file ( ${ LOG_FILE_PATH } ) contents "
fi
if [ [ " ${ SUPER_LINTER_WORKSPACE } " != " $( pwd ) " ] ] ; then
debug " Copying Super-linter log from the workspace ( ${ SUPER_LINTER_WORKSPACE } ) to the current working directory for easier inspection "
cp -v " ${ LOG_FILE_PATH } " " $( pwd ) / "
fi
2024-04-20 05:18:14 -04:00
fi
else
2024-08-12 06:31:38 -04:00
debug " Log file was not requested. CREATE_LOG_FILE: ${ CREATE_LOG_FILE } "
2024-04-20 05:18:14 -04:00
fi
2024-07-01 08:50:52 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_OUTPUT } " = = true ] ] ; then
if [ ! -d " ${ SUPER_LINTER_OUTPUT_PATH } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter output was requested but it's not available at ${ SUPER_LINTER_OUTPUT_PATH } "
2024-07-01 08:50:52 -04:00
exit 1
else
sudo chown -R " $( id -u) " :" $( id -g) " " ${ SUPER_LINTER_OUTPUT_PATH } "
2024-08-12 06:31:38 -04:00
if [ [ " ${ CI :- } " = = "true" ] ] ; then
debug " Super-linter output path ( ${ SUPER_LINTER_OUTPUT_PATH } ) contents: "
ls -alhR " ${ SUPER_LINTER_OUTPUT_PATH } "
else
debug " Not in CI environment, skip emitting ${ SUPER_LINTER_OUTPUT_PATH } contents "
fi
if [ [ " ${ SUPER_LINTER_WORKSPACE } " != " $( pwd ) " ] ] ; then
debug " Copying Super-linter output from the workspace ( ${ SUPER_LINTER_WORKSPACE } ) to the current working directory for easier inspection "
SUPER_LINTER_OUTPUT_PATH_PWD = " $( pwd ) /super-linter-output/ "
mkdir -p " ${ SUPER_LINTER_OUTPUT_PATH_PWD } "
cp -r " ${ SUPER_LINTER_OUTPUT_PATH } " " ${ SUPER_LINTER_OUTPUT_PATH_PWD } "
fi
2024-07-01 08:50:52 -04:00
fi
else
2024-08-12 06:31:38 -04:00
debug " Super-linter output was not requested. SAVE_SUPER_LINTER_OUTPUT: ${ SAVE_SUPER_LINTER_OUTPUT } "
2024-07-28 15:34:40 -04:00
if [ -e " ${ SUPER_LINTER_OUTPUT_PATH } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter output was not requested but it's available at ${ SUPER_LINTER_OUTPUT_PATH } "
2024-07-28 15:34:40 -04:00
exit 1
fi
2024-07-01 08:50:52 -04:00
fi
2024-07-28 15:34:40 -04:00
if [ -n " ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH :- } " ] ; then
2024-08-25 13:43:33 -04:00
if ! AssertFileContentsMatchIgnoreHtmlComments " ${ SUPER_LINTER_SUMMARY_FILE_PATH } " " ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } " ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter summary ( ${ SUPER_LINTER_SUMMARY_FILE_PATH } ) contents don't match with the expected contents ( ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } ) "
2024-07-28 15:34:40 -04:00
exit 1
else
2024-08-12 06:31:38 -04:00
debug " Super-linter summary ( ${ SUPER_LINTER_SUMMARY_FILE_PATH } ) contents match with the expected contents ( ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } ) "
2024-07-28 15:34:40 -04:00
fi
2024-08-25 13:43:33 -04:00
if ! AssertFileContentsMatchIgnoreHtmlComments " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " " ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } " ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter GitHub step summary ( ${ SUPER_LINTER_SUMMARY_FILE_PATH } ) contents don't match with the expected contents ( ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } ) "
2024-07-11 04:01:11 -04:00
exit 1
else
2024-08-12 06:31:38 -04:00
debug " Super-linter GitHub step summary ( ${ SUPER_LINTER_SUMMARY_FILE_PATH } ) contents match with the expected contents ( ${ EXPECTED_SUPER_LINTER_SUMMARY_FILE_PATH } ) "
fi
if [ [ " ${ SUPER_LINTER_WORKSPACE } " != " $( pwd ) " ] ] ; then
debug " Copying Super-linter summary from the workspace ( ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } ) to the current working directory for easier inspection "
cp " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " " $( pwd ) / "
fi
if [ [ " ${ SUPER_LINTER_WORKSPACE } " != " $( pwd ) " ] ] ; then
debug " Copying Super-linter GitHub step summary from the workspace ( ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } ) to the current working directory for easier inspection "
cp " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " " $( pwd ) / "
2024-07-11 04:01:11 -04:00
fi
else
2024-08-12 06:31:38 -04:00
debug "Super-linter summary output was not requested."
2024-07-28 15:34:40 -04:00
if [ -e " ${ SUPER_LINTER_SUMMARY_FILE_PATH } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter summary was not requested but it's available at ${ SUPER_LINTER_SUMMARY_FILE_PATH } "
2024-07-28 15:34:40 -04:00
exit 1
fi
if [ -e " ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } " ] ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter GitHub step summary was not requested but it's available at ${ SUPER_LINTER_GITHUB_STEP_SUMMARY_FILE_PATH } "
2024-07-28 15:34:40 -04:00
exit 1
fi
2024-07-11 04:01:11 -04:00
fi
2024-01-30 14:24:55 -05:00
if [ ${ SUPER_LINTER_EXIT_CODE } -ne ${ EXPECTED_EXIT_CODE } ] ; then
2024-08-12 06:31:38 -04:00
debug " Super-linter exited with an unexpected code: ${ SUPER_LINTER_EXIT_CODE } "
2024-01-30 14:24:55 -05:00
exit 1
else
2024-08-12 06:31:38 -04:00
debug " Super-linter exited with the expected code: ${ SUPER_LINTER_EXIT_CODE } "
fi
VERIFY_FIX_MODE = " ${ VERIFY_FIX_MODE :- "false" } "
if [ [ " ${ VERIFY_FIX_MODE :- } " = = "true" ] ] ; then
debug "Verifying fix mode"
for LANGUAGE in " ${ LANGUAGES_WITH_FIX_MODE [@] } " ; do
if [ [ " ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } " = = "slim" ] ] &&
! IsLanguageInSlimImage " ${ LANGUAGE } " ; then
debug " Skip ${ LANGUAGE } because it's not available in the Super-linter ${ SUPER_LINTER_CONTAINER_IMAGE_TYPE } image "
continue
fi
declare -l LOWERCASE_LANGUAGE = " ${ LANGUAGE } "
BAD_TEST_CASE_SOURCE_PATH = " ${ LINTERS_TEST_CASE_DIRECTORY } / ${ LOWERCASE_LANGUAGE } "
debug " Source path to the ${ LANGUAGE } test case expected to fail: ${ BAD_TEST_CASE_SOURCE_PATH } "
BAD_TEST_CASE_DESTINATION_PATH = " ${ SUPER_LINTER_WORKSPACE } / ${ LINTERS_TEST_CASE_DIRECTORY } / ${ LOWERCASE_LANGUAGE } "
debug " Destination path to ${ LANGUAGE } test case expected to fail: ${ BAD_TEST_CASE_DESTINATION_PATH } "
if [ [ ! -e " ${ BAD_TEST_CASE_SOURCE_PATH } " ] ] ; then
fatal " ${ BAD_TEST_CASE_SOURCE_PATH } doesn't exist "
fi
if [ [ ! -e " ${ BAD_TEST_CASE_DESTINATION_PATH } " ] ] ; then
fatal " ${ BAD_TEST_CASE_DESTINATION_PATH } doesn't exist "
fi
if find " ${ BAD_TEST_CASE_DESTINATION_PATH } " \( -type f ! -readable -or -type d \( ! -readable -or ! -executable -or ! -writable \) \) -print | grep -q .; then
2024-08-16 10:23:52 -04:00
if [ [ " ${ LANGUAGE } " = = "DOTNET_SLN_FORMAT_ANALYZERS" ] ] ||
[ [ " ${ LANGUAGE } " = = "DOTNET_SLN_FORMAT_STYLE" ] ] ||
[ [ " ${ LANGUAGE } " = = "DOTNET_SLN_FORMAT_WHITESPACE" ] ] ||
[ [ " ${ LANGUAGE } " = = "RUST_CLIPPY" ] ] ||
2024-08-12 06:31:38 -04:00
[ [ " ${ LANGUAGE } " = = "SHELL_SHFMT" ] ] ||
[ [ " ${ LANGUAGE } " = = "SQLFLUFF" ] ] ; then
debug " ${ LANGUAGE } is a known case of a tool that doesn't preserve the ownership of files or directories in fix mode. Need to recursively change ownership of ${ BAD_TEST_CASE_DESTINATION_PATH } "
sudo chown -R " $( id -u) " :" $( id -g) " " ${ BAD_TEST_CASE_DESTINATION_PATH } "
else
ls -alR " ${ BAD_TEST_CASE_DESTINATION_PATH } "
fatal " Cannot verify fix mode for ${ LANGUAGE } : ${ BAD_TEST_CASE_DESTINATION_PATH } is not readable, or contains unreadable files. "
fi
else
debug " ${ BAD_TEST_CASE_DESTINATION_PATH } and its contents are readable "
fi
if [ [ " ${ LANGUAGE } " = = "RUST_CLIPPY" ] ] ; then
rm -rf \
" ${ BAD_TEST_CASE_DESTINATION_PATH } " /*/Cargo.lock \
" ${ BAD_TEST_CASE_DESTINATION_PATH } " /*/target
fi
2024-08-25 13:43:33 -04:00
if AssertFileAndDirContentsMatch " ${ BAD_TEST_CASE_DESTINATION_PATH } " " ${ BAD_TEST_CASE_SOURCE_PATH } " ; then
2024-08-12 06:31:38 -04:00
fatal " ${ BAD_TEST_CASE_DESTINATION_PATH } contents match ${ BAD_TEST_CASE_SOURCE_PATH } contents and they should differ because fix mode for ${ LANGUAGE } should have fixed linting and formatting issues. "
fi
done
2024-01-30 14:24:55 -05:00
fi
2024-04-22 05:40:23 -04:00
# Check if super-linter leaves leftovers behind
declare -a TEMP_ITEMS_TO_CLEAN
TEMP_ITEMS_TO_CLEAN = ( )
TEMP_ITEMS_TO_CLEAN += ( " $( pwd ) /.lintr " )
TEMP_ITEMS_TO_CLEAN += ( " $( pwd ) /.mypy_cache " )
TEMP_ITEMS_TO_CLEAN += ( " $( pwd ) /.ruff_cache " )
TEMP_ITEMS_TO_CLEAN += ( " $( pwd ) /logback.log " )
for item in " ${ TEMP_ITEMS_TO_CLEAN [@] } " ; do
2024-08-12 06:31:38 -04:00
debug " Check if ${ item } exists "
2024-04-22 05:40:23 -04:00
if [ [ -e " ${ item } " ] ] ; then
2024-08-12 06:31:38 -04:00
debug " Error: ${ item } exists and it should have been deleted "
2024-04-22 05:40:23 -04:00
exit 1
else
2024-08-12 06:31:38 -04:00
debug " ${ item } does not exist as expected "
2024-04-22 05:40:23 -04:00
fi
done
2024-08-07 09:36:16 -04:00
if ! CheckUnexpectedGitChanges " $( pwd ) " ; then
2024-08-12 06:31:38 -04:00
debug "There are unexpected modifications to the working directory after running tests."
2024-08-07 09:36:16 -04:00
exit 1
fi