2020-07-24 00:54:04 +00:00
BIN = syft
2020-05-12 14:45:18 +00:00
TEMPDIR = ./.tmp
2020-07-06 10:58:34 +00:00
RESULTSDIR = $( TEMPDIR) /results
COVER_REPORT = $( RESULTSDIR) /cover.report
COVER_TOTAL = $( RESULTSDIR) /cover.total
2020-05-12 14:45:18 +00:00
LINTCMD = $( TEMPDIR) /golangci-lint run --tests= false --config .golangci.yaml
2020-07-23 14:52:44 +00:00
ACC_TEST_IMAGE = centos:8.2.2004
ACC_DIR = ./test/acceptance
2020-07-06 10:58:34 +00:00
BOLD := $( shell tput -T linux bold)
PURPLE := $( shell tput -T linux setaf 5)
GREEN := $( shell tput -T linux setaf 2)
CYAN := $( shell tput -T linux setaf 6)
RED := $( shell tput -T linux setaf 1)
RESET := $( shell tput -T linux sgr0)
2020-05-12 14:45:18 +00:00
TITLE := $( BOLD) $( PURPLE)
SUCCESS := $( BOLD) $( GREEN)
2020-07-06 10:58:34 +00:00
# the quality gate lower threshold for unit test total % coverage (by function statements)
2020-07-17 17:32:45 +00:00
COVERAGE_THRESHOLD := 72
2020-05-12 14:45:18 +00:00
2020-07-23 14:52:44 +00:00
## Build variables
DISTDIR = ./dist
SNAPSHOTDIR = ./snapshot
GITTREESTATE = $( if $( shell git status --porcelain) ,dirty,clean)
2020-08-10 14:33:44 +00:00
SNAPSHOT_CMD = $( shell realpath $( shell pwd ) /$( SNAPSHOTDIR) /syft_linux_amd64/syft)
2020-07-23 14:52:44 +00:00
i f e q "$(strip $(VERSION))" ""
override VERSION = $( shell git describe --always --tags --dirty)
e n d i f
## Variable assertions
2020-05-21 13:37:20 +00:00
i f n d e f T E M P D I R
2020-07-23 14:52:44 +00:00
$( error TEMPDIR is not set )
e n d i f
i f n d e f R E S U L T S D I R
$( error RESULTSDIR is not set )
e n d i f
i f n d e f A C C _ D I R
$( error ACC_DIR is not set )
e n d i f
i f n d e f D I S T D I R
$( error DISTDIR is not set )
e n d i f
i f n d e f S N A P S H O T D I R
$( error SNAPSHOTDIR is not set )
2020-05-21 13:37:20 +00:00
e n d i f
2020-07-06 10:58:34 +00:00
d e f i n e t i t l e
@printf '$(TITLE)$(1)$(RESET)\n'
e n d e f
2020-05-12 14:45:18 +00:00
2020-07-23 14:52:44 +00:00
## Tasks
2020-07-06 10:58:34 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : all
2020-07-25 20:40:37 +00:00
all : clean static -analysis test ## Run all linux-based checks (linting, license check, unit, integration, and linux acceptance tests)
2020-05-12 14:45:18 +00:00
@printf '$(SUCCESS)All checks pass!$(RESET)\n'
2020-07-23 14:52:44 +00:00
.PHONY : test
2020-08-27 23:12:45 +00:00
test : unit validate -cyclonedx -schema integration acceptance -linux ## Run all tests (currently unit, integration, and linux acceptance tests)
2020-07-06 10:58:34 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : help
2020-07-06 10:58:34 +00:00
help :
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $( MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)$(CYAN)%-25s$(RESET)%s\n", $$1, $$2}'
2020-07-23 14:52:44 +00:00
.PHONY : ci -bootstrap
ci-bootstrap : bootstrap
2020-08-27 23:12:45 +00:00
DEBIAN_FRONTEND = noninteractive sudo apt update && sudo -E apt install -y bc jq libxml2-utils
2020-07-06 10:58:34 +00:00
2020-08-04 22:22:43 +00:00
.PHONY : bootstrap
2020-07-23 14:52:44 +00:00
bootstrap : ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
2020-08-04 22:22:43 +00:00
$( call title,Bootstrapping dependencies)
2020-07-23 14:52:44 +00:00
@pwd
2020-07-06 10:58:34 +00:00
# prep temp dirs
mkdir -p $( TEMPDIR)
mkdir -p $( RESULTSDIR)
2020-07-23 14:52:44 +00:00
# install go dependencies
go mod download
# install utilities
[ -f " $( TEMPDIR) /golangci " ] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $( TEMPDIR) / v1.26.0
2020-07-25 20:55:41 +00:00
[ -f " $( TEMPDIR) /bouncer " ] || curl -sSfL https://raw.githubusercontent.com/wagoodman/go-bouncer/master/bouncer.sh | sh -s -- -b $( TEMPDIR) / v0.2.0
2020-07-23 14:52:44 +00:00
[ -f " $( TEMPDIR) /goreleaser " ] || curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b $( TEMPDIR) / v0.140.0
2020-07-25 20:40:37 +00:00
.PHONY : static -analysis
static-analysis : lint check -licenses
2020-07-23 14:52:44 +00:00
.PHONY : lint
2020-07-06 10:58:34 +00:00
lint : ## Run gofmt + golangci lint checks
$( call title,Running linters)
2020-07-23 17:08:31 +00:00
# ensure there are no go fmt differences
2020-07-06 10:58:34 +00:00
@printf " files with gofmt issues: [ $( shell gofmt -l -s .) ]\n "
@test -z " $( shell gofmt -l -s .) "
2020-07-23 17:08:31 +00:00
# run all golangci-lint rules
2020-05-12 14:45:18 +00:00
$( LINTCMD)
2020-07-23 17:08:31 +00:00
# go tooling does not play well with certain filename characters, ensure the common cases don't result in future "go get" failures
$( eval MALFORMED_FILENAMES := $( shell find . | grep -e ':' ) )
@bash -c " [[ ' $( MALFORMED_FILENAMES) ' == '' ]] || (printf '\nfound unsupported filename characters:\n $( MALFORMED_FILENAMES) \n\n' && false) "
2020-07-23 14:52:44 +00:00
.PHONY : lint -fix
2020-07-06 10:58:34 +00:00
lint-fix : ## Auto-format all source code + run golangci lint fixers
$( call title,Running lint fixers)
2020-05-21 13:37:20 +00:00
gofmt -w -s .
2020-05-12 14:45:18 +00:00
$( LINTCMD) --fix
2020-07-23 14:52:44 +00:00
.PHONY : check -licenses
check-licenses :
$( TEMPDIR) /bouncer check
2020-08-27 23:12:45 +00:00
.PHONY : validate -cyclonedx -schema
validate-cyclonedx-schema :
cd schema/cyclonedx && make
2020-07-23 14:52:44 +00:00
.PHONY : unit
2020-07-25 14:06:52 +00:00
unit : fixtures ## Run unit tests (with coverage)
2020-07-06 10:58:34 +00:00
$( call title,Running unit tests)
2020-07-25 14:06:52 +00:00
go test -coverprofile $( COVER_REPORT) ./...
2020-07-06 10:58:34 +00:00
@go tool cover -func $( COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $( COVER_TOTAL)
@echo " Coverage: $$ (cat $( COVER_TOTAL) ) "
@if [ $$ ( echo " $$ (cat $( COVER_TOTAL) ) >= $( COVERAGE_THRESHOLD) " | bc -l) -ne 1 ] ; then echo " $( RED) $( BOLD) Failed coverage quality gate (> $( COVERAGE_THRESHOLD) %) $( RESET) " && false; fi
2020-05-12 14:45:18 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : integration
2020-07-06 10:58:34 +00:00
integration : ## Run integration tests
$( call title,Running integration tests)
2020-07-23 14:52:44 +00:00
go test -v -tags= integration ./test/integration
2020-05-12 14:45:18 +00:00
2020-08-10 14:33:44 +00:00
# note: this is used by CI to determine if the integration test fixture cache (docker image tars) should be busted
integration-fingerprint :
2020-09-25 14:24:24 +00:00
find test/integration/test-fixtures/image-* -type f -exec md5sum { } + | awk '{print $1}' | sort | md5sum | tee test/integration/test-fixtures/cache.fingerprint
2020-07-07 22:04:27 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : java -packages -fingerprint
2020-07-13 16:11:11 +00:00
java-packages-fingerprint :
2020-07-24 00:54:04 +00:00
@cd syft/cataloger/java/test-fixtures/java-builds && \
2020-07-13 16:11:11 +00:00
make packages.fingerprint
2020-07-25 14:06:52 +00:00
.PHONY : fixtures
fixtures :
$( call title,Generating test fixtures)
cd syft/cataloger/java/test-fixtures/java-builds && make
2020-08-04 20:05:53 +00:00
.PHONY : generate -json -schema
generate-json-schema : clean -json -schema -examples integration ## Generate a new json schema for the json presenter, derived from integration test cases
docker run \
-i \
--rm \
2020-08-27 23:12:45 +00:00
-v $( shell pwd ) /schema/json:/work \
2020-08-04 20:05:53 +00:00
-w /work \
python:3.8 \
bash -x -c " \
pip install -r requirements.txt && \
python generate.py \
"
2020-07-23 14:52:44 +00:00
.PHONY : clear -test -cache
2020-07-06 10:58:34 +00:00
clear-test-cache : ## Delete all test cache (built docker image tars)
2020-09-25 14:24:24 +00:00
find . -type f -wholename "**/test-fixtures/cache/*.tar" -delete
2020-05-12 14:45:18 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : check -pipeline
2020-07-06 10:58:34 +00:00
check-pipeline : ## Run local CircleCI pipeline locally (sanity check)
$( call title,Check pipeline)
# note: this is meant for local development & testing of the pipeline, NOT to be run in CI
mkdir -p $( TEMPDIR)
circleci config process .circleci/config.yml > .tmp/circleci.yml
circleci local execute -c .tmp/circleci.yml --job "Static Analysis"
circleci local execute -c .tmp/circleci.yml --job "Unit & Integration Tests (go-latest)"
@printf '$(SUCCESS)Pipeline checks pass!$(RESET)\n'
2020-05-12 14:45:18 +00:00
2020-07-23 14:52:44 +00:00
.PHONY : build
build : $( SNAPSHOTDIR ) ## Build release snapshot binaries and packages
$(SNAPSHOTDIR) : ## Build snapshot release binaries and packages
$( call title,Building snapshot artifacts)
# create a config with the dist dir overridden
echo " dist: $( SNAPSHOTDIR) " > $( TEMPDIR) /goreleaser.yaml
cat .goreleaser.yaml >> $( TEMPDIR) /goreleaser.yaml
# build release snapshots
BUILD_GIT_TREE_STATE = $( GITTREESTATE) \
$( TEMPDIR) /goreleaser release --skip-publish --rm-dist --snapshot --config $( TEMPDIR) /goreleaser.yaml
.PHONY : acceptance -mac
acceptance-mac : $( SNAPSHOTDIR ) ## Run acceptance tests on build snapshot binaries and packages (Mac)
$( call title,Running acceptance test: Run on Mac)
$( ACC_DIR) /mac.sh \
$( SNAPSHOTDIR) \
2020-07-24 21:41:22 +00:00
$( ACC_DIR) \
$( ACC_TEST_IMAGE) \
$( RESULTSDIR)
2020-07-23 14:52:44 +00:00
.PHONY : acceptance -linux
acceptance-linux : acceptance -test -deb -package -install acceptance -test -rpm -package -install ## Run acceptance tests on build snapshot binaries and packages (Linux)
2020-08-10 14:33:44 +00:00
# note: this is used by CI to determine if the inline-scan report cache should be busted for the inline-compare tests
.PHONY : compare -fingerprint
compare-fingerprint :
find test/inline-compare/* -type f -exec md5sum { } + | grep -v '\-reports' | grep -v 'fingerprint' | awk '{print $1}' | sort | md5sum | tee test/inline-compare/inline-compare.fingerprint
.PHONY : compare -snapshot
compare-snapshot : $( SNAPSHOTDIR ) ## Compare the reports of a run of a snapshot build of syft against inline-scan
chmod 755 $( SNAPSHOT_CMD)
@cd test/inline-compare && SYFT_CMD = $( SNAPSHOT_CMD) make
.PHONY : compare
compare : ## Compare the reports of a run of a main-branch build of syft against inline-scan
@cd test/inline-compare && make
2020-07-23 14:52:44 +00:00
.PHONY : acceptance -test -deb -package -install
acceptance-test-deb-package-install : $( SNAPSHOTDIR )
$( call title,Running acceptance test: DEB install)
$( ACC_DIR) /deb.sh \
$( SNAPSHOTDIR) \
2020-07-24 21:41:22 +00:00
$( ACC_DIR) \
$( ACC_TEST_IMAGE) \
$( RESULTSDIR)
2020-07-23 14:52:44 +00:00
.PHONY : acceptance -test -rpm -package -install
acceptance-test-rpm-package-install : $( SNAPSHOTDIR )
$( call title,Running acceptance test: RPM install)
$( ACC_DIR) /rpm.sh \
$( SNAPSHOTDIR) \
2020-07-24 21:41:22 +00:00
$( ACC_DIR) \
$( ACC_TEST_IMAGE) \
$( RESULTSDIR)
2020-07-23 14:52:44 +00:00
2020-08-27 12:10:56 +00:00
.PHONY : changlog
changelog :
mkdir -p $( DISTDIR)
@docker run -it --rm \
-v " $( shell pwd ) " :/usr/local/src/your-app ferrarimarco/github-changelog-generator \
--user anchore \
--project $( BIN) \
-t ${ GITHUB_TOKEN } \
--no-pr-wo-labels \
--no-issues-wo-labels \
--unreleased-only \
--future-release $( VERSION)
2020-07-23 14:52:44 +00:00
.PHONY : release
2020-08-27 12:10:56 +00:00
release : clean -dist changelog ## Build and publish final binaries and packages
2020-07-23 14:52:44 +00:00
$( call title,Publishing release artifacts)
# create a config with the dist dir overridden
echo " dist: $( DISTDIR) " > $( TEMPDIR) /goreleaser.yaml
cat .goreleaser.yaml >> $( TEMPDIR) /goreleaser.yaml
# release
BUILD_GIT_TREE_STATE = $( GITTREESTATE) \
2020-08-27 12:10:56 +00:00
$( TEMPDIR) /goreleaser \
--rm-dist \
--config $( TEMPDIR) /goreleaser.yaml \
--release-notes <( cat CHANGELOG.md)
2020-07-23 14:52:44 +00:00
2020-07-25 11:47:14 +00:00
# verify checksum signatures
2020-07-25 13:05:19 +00:00
.github/scripts/verify-signature.sh " $( DISTDIR) "
2020-07-25 11:47:14 +00:00
2020-07-29 18:54:47 +00:00
# upload the version file that supports the application version update check (excluding pre-releases)
.github/scripts/update-version-file.sh " $( DISTDIR) " " $( VERSION) "
2020-07-23 14:52:44 +00:00
.PHONY : clean
2020-08-04 20:05:53 +00:00
clean : clean -dist clean -snapshot clean -json -schema -examples ## Remove previous builds and result reports
2020-07-23 14:52:44 +00:00
rm -rf $( RESULTSDIR) /*
2020-07-24 21:41:22 +00:00
.PHONY : clean -snapshot
clean-snapshot :
2020-07-23 14:52:44 +00:00
rm -rf $( SNAPSHOTDIR) $( TEMPDIR) /goreleaser.yaml
.PHONY : clean -dist
clean-dist :
2020-07-27 13:30:05 +00:00
rm -rf $( DISTDIR) $( TEMPDIR) /goreleaser.yaml
2020-08-04 20:05:53 +00:00
.PHONY : clean -json -schema -examples
clean-json-schema-examples :
2020-08-27 23:12:45 +00:00
rm -f schema/json/examples/*