2021-04-22 14:56:18 -04:00
# Inspired by https://github.com/jessfraz/dotfiles
.PHONY : all
2023-10-19 17:03:14 -04:00
all : info docker test ## Run all targets.
2021-04-22 14:56:18 -04:00
.PHONY : test
2024-01-06 12:39:39 -05:00
test : info validate -container -image -labels test -lib inspec lint -codebase test -default -config -files test -find lint -subset -files test -linters ## Run the test suite
2021-04-22 14:56:18 -04:00
# if this session isn't interactive, then we don't want to allocate a
# TTY, which would fail, but if it is interactive, we do want to attach
# so that the user can send e.g. ^C through.
INTERACTIVE := $( shell [ -t 0 ] && echo 1 || echo 0)
i f e q ( $( INTERACTIVE ) , 1 )
DOCKER_FLAGS += -t
e n d i f
.PHONY : info
info : ## Gather information about the runtime environment
echo " whoami: $$ (whoami) " ; \
echo " pwd: $$ (pwd) " ; \
echo " ls -ahl: $$ (ls -ahl) " ; \
2021-04-30 12:29:15 -04:00
docker images; \
docker ps
2021-04-22 14:56:18 -04:00
.PHONY : help
help : ## Show help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2021-04-30 12:29:15 -04:00
.PHONY : inspec -check
inspec-check : ## Validate inspec profiles
docker run $( DOCKER_FLAGS) \
--rm \
-v " $( CURDIR) " :/workspace \
-w= "/workspace" \
chef/inspec check \
--chef-license= accept \
test/inspec/super-linter
SUPER_LINTER_TEST_CONTAINER_NAME := "super-linter-test"
2023-10-19 17:03:14 -04:00
SUPER_LINTER_TEST_CONTAINER_URL := $( CONTAINER_IMAGE_ID)
2021-05-25 11:14:43 -04:00
DOCKERFILE := ''
2023-10-19 17:03:14 -04:00
IMAGE := $( CONTAINER_IMAGE_TARGET)
# Default to stadard
i f e q ( $( IMAGE ) , )
IMAGE := "standard"
e n d i f
# Default to latest
i f e q ( $( SUPER_LINTER_TEST_CONTAINER_URL ) , )
SUPER_LINTER_TEST_CONTAINER_URL := "ghcr.io/super-linter/super-linter:latest"
2021-05-25 11:14:43 -04:00
e n d i f
2021-04-30 12:29:15 -04:00
2023-12-07 09:18:47 -05:00
i f e q ( $( BUILD_DATE ) , )
BUILD_DATE := $( shell date -u +'%Y-%m-%dT%H:%M:%SZ' )
e n d i f
i f e q ( $( BUILD_REVISION ) , )
BUILD_REVISION := $( shell git rev-parse HEAD)
e n d i f
i f e q ( $( BUILD_VERSION ) , )
BUILD_VERSION := $( shell git rev-parse HEAD)
e n d i f
2023-12-19 13:37:16 -05:00
i f e q ( $( FROM_INTERVAL_COMMITLINT ) , )
FROM_INTERVAL_COMMITLINT := "HEAD~1"
e n d i f
i f e q ( $( TO_INTERVAL_COMMITLINT ) , )
TO_INTERVAL_COMMITLINT := "HEAD"
e n d i f
2023-12-12 13:53:48 -05:00
GITHUB_TOKEN_PATH := " $( CURDIR) /.github-personal-access-token "
2023-12-21 09:03:14 -05:00
DEV_CONTAINER_URL := "super-linter/dev-container:latest"
2023-12-19 13:37:16 -05:00
2023-12-21 09:03:14 -05:00
i f e q ( $( GITHUB_HEAD_REF ) , )
RELEASE_PLEASE_TARGET_BRANCH := " $( shell git branch --show-current) "
e l s e
RELEASE_PLEASE_TARGET_BRANCH := " ${ GITHUB_HEAD_REF } "
e n d i f
.phony : check -github -token
check-github-token :
@if [ ! -f " ${ GITHUB_TOKEN_PATH } " ] ; then echo " Cannot find the file to load the GitHub access token: $( GITHUB_TOKEN_PATH) . Create a readable file there, and populate it with a GitHub personal access token. " ; exit 1; fi
.phony : inspec
2021-04-30 12:29:15 -04:00
inspec : inspec -check ## Run InSpec tests
2023-10-19 17:03:14 -04:00
DOCKER_CONTAINER_STATE = " $$ (docker inspect --format " { { .State.Running} } " $( SUPER_LINTER_TEST_CONTAINER_NAME) 2>/dev/null || echo " ")" ; \
if [ " $$ DOCKER_CONTAINER_STATE " = "true" ] ; then docker kill $( SUPER_LINTER_TEST_CONTAINER_NAME) ; fi && \
docker tag $( SUPER_LINTER_TEST_CONTAINER_URL) $( SUPER_LINTER_TEST_CONTAINER_NAME) && \
SUPER_LINTER_TEST_CONTAINER_ID = " $$ (docker run -d --name $( SUPER_LINTER_TEST_CONTAINER_NAME) --rm -it --entrypoint /bin/ash $( SUPER_LINTER_TEST_CONTAINER_NAME) -c " while true; do sleep 1; done ")" \
2021-04-30 12:29:15 -04:00
&& docker run $( DOCKER_FLAGS) \
--rm \
-v " $( CURDIR) " :/workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
2021-05-25 11:14:43 -04:00
-e IMAGE = $( IMAGE) \
2021-04-30 12:29:15 -04:00
-w= "/workspace" \
2023-12-15 05:59:36 -05:00
chef/inspec exec test/inspec/super-linter \
2021-04-30 12:29:15 -04:00
--chef-license= accept \
--diagnose \
--log-level= debug \
-t " docker:// $$ {SUPER_LINTER_TEST_CONTAINER_ID} " \
&& docker ps \
2023-10-19 17:03:14 -04:00
&& docker kill $( SUPER_LINTER_TEST_CONTAINER_NAME)
2022-12-29 12:56:54 -05:00
.phony : docker
2023-12-21 09:03:14 -05:00
docker : check -github -token ## Build the container image
2023-01-04 01:00:02 -05:00
DOCKER_BUILDKIT = 1 docker buildx build --load \
2023-12-07 09:18:47 -05:00
--build-arg BUILD_DATE = $( BUILD_DATE) \
--build-arg BUILD_REVISION = $( BUILD_REVISION) \
--build-arg BUILD_VERSION = $( BUILD_VERSION) \
2023-12-12 13:53:48 -05:00
--secret id = GITHUB_TOKEN,src= $( GITHUB_TOKEN_PATH) \
2024-01-10 05:09:53 -05:00
--target $( IMAGE) \
2023-10-19 17:03:14 -04:00
-t $( SUPER_LINTER_TEST_CONTAINER_URL) .
.phony : docker -pull
docker-pull : ## Pull the container image from registry
docker pull $( SUPER_LINTER_TEST_CONTAINER_URL)
2023-12-07 09:18:47 -05:00
.phony : validate -container -image -labels
validate-container-image-labels : ## Validate container image labels
$( CURDIR) /test/validate-docker-labels.sh \
$( SUPER_LINTER_TEST_CONTAINER_URL) \
$( BUILD_DATE) \
$( BUILD_REVISION) \
$( BUILD_VERSION)
2023-12-07 14:07:22 -05:00
2023-12-20 08:58:25 -05:00
# Mount a directory that doesn't have too many files to keep this test short
2023-12-07 14:07:22 -05:00
.phony : test -find
test-find : ## Run super-linter on a subdirectory with USE_FIND_ALGORITHM=true
docker run \
-e RUN_LOCAL = true \
-e ACTIONS_RUNNER_DEBUG = true \
2023-12-12 13:53:48 -05:00
-e ERROR_ON_MISSING_EXEC_BIT = true \
2023-12-12 14:57:15 -05:00
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
-e DEFAULT_BRANCH = main \
2023-12-07 14:07:22 -05:00
-e USE_FIND_ALGORITHM = true \
2023-12-20 08:58:25 -05:00
-v " $( CURDIR) /.github " :/tmp/lint/.github \
2023-12-07 14:07:22 -05:00
$( SUPER_LINTER_TEST_CONTAINER_URL)
2023-12-12 13:53:48 -05:00
.phony : lint -codebase
lint-codebase : ## Lint the entire codebase
docker run \
-e RUN_LOCAL = true \
-e ACTIONS_RUNNER_DEBUG = true \
-e DEFAULT_BRANCH = main \
2023-12-12 14:57:15 -05:00
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
2023-12-12 13:53:48 -05:00
-e ERROR_ON_MISSING_EXEC_BIT = true \
-e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES = "default.json,hoge.json" \
2023-12-24 11:56:15 -05:00
-e VALIDATE_ALL_CODEBASE = true \
2023-12-12 13:53:48 -05:00
-v " $( CURDIR) :/tmp/lint " \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2024-01-06 12:39:39 -05:00
# This is a smoke test to check how much time it takes to lint only a small
# subset of files, compared to linting the whole codebase.
.phony : lint -subset -files
lint-subset-files : lint -subset -files -enable -only -one -type lint -subset -files -enable -expensive -io -checks
.phony : lint -subset -files -enable -only -one -type
lint-subset-files-enable-only-one-type : ## Lint a small subset of files in the codebase by enabling only one linter
time docker run \
-e RUN_LOCAL = true \
-e ACTIONS_RUNNER_DEBUG = true \
-e DEFAULT_BRANCH = main \
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
-e ERROR_ON_MISSING_EXEC_BIT = true \
-e VALIDATE_ALL_CODEBASE = true \
-e VALIDATE_MARKDOWN = true \
-v " $( CURDIR) :/tmp/lint " \
$( SUPER_LINTER_TEST_CONTAINER_URL)
.phony : lint -subset -files -enable -expensive -io -checks
lint-subset-files-enable-expensive-io-checks : ## Lint a small subset of files in the codebase and keep expensive I/O operations to check file types enabled
time docker run \
-e RUN_LOCAL = true \
-e ACTIONS_RUNNER_DEBUG = true \
-e DEFAULT_BRANCH = main \
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
-e ERROR_ON_MISSING_EXEC_BIT = true \
-e VALIDATE_ALL_CODEBASE = true \
-e VALIDATE_ARM = true \
-e VALIDATE_CLOUDFORMATION = true \
-e VALIDATE_KUBERNETES_KUBECONFORM = true \
-e VALIDATE_MARKDOWN = true \
-e VALIDATE_OPENAPI = true \
-e VALIDATE_STATES = true \
-e VALIDATE_TEKTON = true \
-v " $( CURDIR) :/tmp/lint " \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2023-12-23 13:33:53 -05:00
.phony : test -lib
2024-01-05 17:07:39 -05:00
test-lib : test -build -file -list test -github -event test -validation ## Test super-linter
2023-12-23 13:33:53 -05:00
.phony : test -build -file -list
test-build-file-list : ## Test buildFileList
docker run \
-v " $( CURDIR) :/tmp/lint " \
-w /tmp/lint \
--entrypoint /tmp/lint/test/lib/buildFileListTest.sh \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2024-01-05 17:07:39 -05:00
.phony : test -github -event
test-github-event : ## Test githubEvent
docker run \
-v " $( CURDIR) :/tmp/lint " \
-w /tmp/lint \
--entrypoint /tmp/lint/test/lib/githubEventTest.sh \
$( SUPER_LINTER_TEST_CONTAINER_URL)
.phony : test -validation
test-validation : ## Test validation
docker run \
-v " $( CURDIR) :/tmp/lint " \
-w /tmp/lint \
--entrypoint /tmp/lint/test/lib/validationTest.sh \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2024-01-02 12:03:30 -05:00
# Run this test against a small directory because we're only interested in
# loading default configuration files. The directory that we run super-linter
# against should not be .github because that includes default linter rules.
.phony : test -default -config -files
test-default-config-files : ## Test default configuration files loading
docker run \
-e RUN_LOCAL = true \
-e ACTIONS_RUNNER_DEBUG = true \
-e ERROR_ON_MISSING_EXEC_BIT = true \
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
-e DEFAULT_BRANCH = main \
-e USE_FIND_ALGORITHM = true \
-v " $( CURDIR) /docs " :/tmp/lint \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2023-12-12 13:53:48 -05:00
.phony : test -linters
test-linters : ## Run the linters test suite
docker run \
-e ACTIONS_RUNNER_DEBUG = true \
2023-12-22 07:22:15 -05:00
-e CHECKOV_FILE_NAME = ".checkov-test-linters.yaml" \
2023-12-12 13:53:48 -05:00
-e DEFAULT_BRANCH = main \
2023-12-12 14:57:15 -05:00
-e ENABLE_GITHUB_ACTIONS_GROUP_TITLE = true \
2023-12-12 13:53:48 -05:00
-e ERROR_ON_MISSING_EXEC_BIT = true \
2023-12-24 11:56:15 -05:00
-e JSCPD_CONFIG_FILE = ".jscpd-test-linters.json" \
2023-12-12 13:53:48 -05:00
-e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES = "default.json,hoge.json" \
-e RUN_LOCAL = true \
-e TEST_CASE_RUN = true \
-e TYPESCRIPT_STANDARD_TSCONFIG_FILE = ".github/linters/tsconfig.json" \
-v " $( CURDIR) :/tmp/lint " \
$( SUPER_LINTER_TEST_CONTAINER_URL)
2023-12-19 13:37:16 -05:00
2023-12-21 09:03:14 -05:00
.phony : build -dev -container -image
build-dev-container-image : ## Build commit linter container image
2023-12-19 13:37:16 -05:00
DOCKER_BUILDKIT = 1 docker buildx build --load \
2023-12-22 07:22:15 -05:00
--build-arg GID = $( shell id -g) \
--build-arg UID = $( shell id -u) \
2023-12-21 09:03:14 -05:00
-t ${ DEV_CONTAINER_URL } " ${ CURDIR } /dev-dependencies "
2023-12-19 13:37:16 -05:00
.phony : lint -commits
2023-12-21 09:03:14 -05:00
lint-commits : build -dev -container -image ## Lint commits
2023-12-19 13:37:16 -05:00
docker run \
-v " $( CURDIR) :/source-repository " \
2023-12-21 09:03:14 -05:00
${ DEV_CONTAINER_URL } \
commitlint \
2023-12-19 13:37:16 -05:00
--config .github/linters/commitlint.config.js \
--cwd /source-repository \
--from ${ FROM_INTERVAL_COMMITLINT } \
--to ${ TO_INTERVAL_COMMITLINT } \
--verbose
2023-12-21 09:03:14 -05:00
.phony : release -please -dry -run
release-please-dry-run : build -dev -container -image check -github -token ## Run release-please in dry-run mode to preview the release pull request
@echo " Running release-please against branch: ${ RELEASE_PLEASE_TARGET_BRANCH } " ; \
docker run \
-v " $( CURDIR) :/source-repository " \
${ DEV_CONTAINER_URL } \
release-please \
release-pr \
--config-file .github/release-please/release-please-config.json \
--dry-run \
--manifest-file .github/release-please/.release-please-manifest.json \
--repo-url super-linter/super-linter \
--target-branch ${ RELEASE_PLEASE_TARGET_BRANCH } \
--token " $( shell cat " ${ GITHUB_TOKEN_PATH } " ) " \
2024-01-05 17:07:39 -05:00
--trace