|
| 1 | +SHELL := /bin/bash |
| 2 | +OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi) |
| 3 | + |
| 4 | +.PHONY: help |
| 5 | +help: ## Shows all targets and help from the Makefile (this message). |
| 6 | + @echo "slsa-github-generator Makefile" |
| 7 | + @echo "Usage: make [COMMAND]" |
| 8 | + @echo "" |
| 9 | + @grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \ |
| 10 | + awk 'BEGIN {FS = "(:.*?|)## ?"}; { \ |
| 11 | + if (length($$1) > 0) { \ |
| 12 | + printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \ |
| 13 | + } else { \ |
| 14 | + if (length($$2) > 0) { \ |
| 15 | + printf "%s\n", $$2; \ |
| 16 | + } \ |
| 17 | + } \ |
| 18 | + }' |
| 19 | + |
| 20 | +## Testing |
| 21 | +##################################################################### |
| 22 | + |
| 23 | +unit-test: ## Runs all unit tests. |
| 24 | + # Run unit tests for the detect-workflow action. |
| 25 | + cd .github/actions/detect-workflow |
| 26 | + go mod vendor |
| 27 | + go test -mod=vendor -v ./... |
| 28 | + # Run unit tests for the main package. |
| 29 | + cd - |
| 30 | + go mod vendor |
| 31 | + go test -mod=vendor -v ./... |
| 32 | + |
| 33 | + |
| 34 | +## Linters |
| 35 | +##################################################################### |
| 36 | + |
| 37 | +lint: ## Run all linters. |
| 38 | +lint: golangci-lint shellcheck yamllint |
| 39 | + |
| 40 | +golangci-lint: ## Runs the golangci-lint linter. |
| 41 | + @set -e;\ |
| 42 | + extraargs=""; \ |
| 43 | + if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ |
| 44 | + extraargs="--out-format github-actions"; \ |
| 45 | + fi; \ |
| 46 | + golangci-lint run -c .golangci.yml ./... $$extraargs |
| 47 | + |
| 48 | +shellcheck: ## Runs the shellcheck linter. |
| 49 | + @set -e;\ |
| 50 | + FILES=$$(find . -type f -not -iwholename '*/.git/*' -not -iwholename '*/vendor/*' -not -iwholename '*/node_modules/*' -exec bash -c 'file "$$1" | cut -d':' -f2 | grep --quiet shell' _ {} \; -print); \ |
| 51 | + if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ |
| 52 | + echo -n $$FILES | xargs shellcheck -f json --external-sources | jq -c '.[]' | while IFS="" read -r p || [ -n "$$p" ]; do \ |
| 53 | + LEVEL=$$(echo "$$p" | jq -c '.level // empty' | tr -d '"'); \ |
| 54 | + FILE=$$(echo "$$p" | jq -c '.file // empty' | tr -d '"'); \ |
| 55 | + LINE=$$(echo "$$p" | jq -c '.line // empty' | tr -d '"'); \ |
| 56 | + ENDLINE=$$(echo "$$p" | jq -c '.endLine // empty' | tr -d '"'); \ |
| 57 | + COL=$$(echo "$$p" | jq -c '.column // empty' | tr -d '"'); \ |
| 58 | + ENDCOL=$$(echo "$$p" | jq -c '.endColumn // empty' | tr -d '"'); \ |
| 59 | + MESSAGE=$$(echo "$$p" | jq -c '.message // empty' | tr -d '"'); \ |
| 60 | + case $$LEVEL in \ |
| 61 | + "info") \ |
| 62 | + echo "::notice file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ |
| 63 | + ;; \ |
| 64 | + "warning") \ |
| 65 | + echo "::warning file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ |
| 66 | + ;; \ |
| 67 | + "error") \ |
| 68 | + echo "::error file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ |
| 69 | + ;; \ |
| 70 | + esac; \ |
| 71 | + done; \ |
| 72 | + else \ |
| 73 | + echo -n $$FILES | xargs shellcheck --external-sources; \ |
| 74 | + fi |
| 75 | + |
| 76 | +yamllint: ## Runs the yamllint linter. |
| 77 | + @set -e;\ |
| 78 | + extraargs=""; \ |
| 79 | + if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ |
| 80 | + extraargs="-f github"; \ |
| 81 | + fi; \ |
| 82 | + yamllint -c .yamllint.yaml . $$extraargs |
0 commit comments