Skip to content

Commit

Permalink
fix snapshot builds
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Feb 5, 2023
1 parent 33fb3e2 commit b0fc172
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
12 changes: 7 additions & 5 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -uo pipefail

SNAPSHOT_DIR=$1

# Based on https://gist.github.com/eduncan911/68775dba9d3c028181e4 and https://gist.github.com/makeworld-the-better-one/e1bb127979ae4195f43aaa3ad46b1097
# but improved to use the `go` command so it never goes out of date.

Expand All @@ -11,10 +13,10 @@ contains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
}

mkdir -p snapshot
rm -f snapshot/*
mkdir -p "${SNAPSHOT_DIR}"

OUTPUT=snapshot/stereoscope-example
BUILD_TARGET=./examples
OUTPUT=${SNAPSHOT_DIR}/stereoscope-example
FAILURES=""

# You can set your own flags on the command line
Expand Down Expand Up @@ -60,14 +62,14 @@ while IFS= read -r target; do
for GOARM in $arms; do
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} $@"
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} ${BUILD_TARGET}"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
done
else
# Build non-arm here
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} $@"
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build $FLAGS -o ${BIN_FILENAME} ${BUILD_TARGET}"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}"
fi
Expand Down
38 changes: 27 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ SUCCESS := $(BOLD)$(GREEN)
# Test variables #################################
COVERAGE_THRESHOLD := 55 # the quality gate lower threshold for unit test total % coverage (by function statements)

ifeq "$(strip $(VERSION))" ""
override VERSION = $(shell git describe --always --tags --dirty)
## Build variables #################################
SNAPSHOT_DIR := ./snapshot
VERSION := $(shell git describe --dirty --always --tags)

ifndef VERSION
$(error VERSION is not set)
endif

ifndef TEMP_DIR
$(error TEMP_DIR is not set)
endif

ifndef REF_NAME
REF_NAME = $(VERSION)
endif

define title
@printf '$(TITLE)$(1)$(RESET)\n'
endef

define safe_rm_rf
bash -c 'test -z "$(1)" && false || rm -rf $(1)'
endef

define safe_rm_rf_children
bash -c 'test -z "$(1)" && false || rm -rf $(1)/*'
endef

.PHONY: all
all: static-analysis test ## Run all linux-based checks (linting, license check, unit, integration, and linux compare tests)
@printf '$(SUCCESS)All checks pass!$(RESET)\n'
Expand Down Expand Up @@ -122,10 +130,10 @@ integration: integration-tools ## Run integration tests
.PHONY: benchmark
benchmark: $(TEMP_DIR) ## Run benchmark tests and compare against the baseline (if available)
$(call title,Running benchmark tests)
go test -cpu 2 -p 1 -run=^Benchmark -bench=. -count=5 -benchmem ./... | tee $(TEMP_DIR)/benchmark-$(REF_NAME).txt
go test -cpu 2 -p 1 -run=^Benchmark -bench=. -count=5 -benchmem ./... | tee $(TEMP_DIR)/benchmark-$(VERSION).txt
(test -s $(TEMP_DIR)/benchmark-main.txt && \
$(TEMP_DIR)/benchstat $(TEMP_DIR)/benchmark-main.txt $(TEMP_DIR)/benchmark-$(REF_NAME).txt || \
$(TEMP_DIR)/benchstat $(TEMP_DIR)/benchmark-$(REF_NAME).txt) \
$(TEMP_DIR)/benchstat $(TEMP_DIR)/benchmark-main.txt $(TEMP_DIR)/benchmark-$(VERSION).txt || \
$(TEMP_DIR)/benchstat $(TEMP_DIR)/benchmark-$(VERSION).txt) \
| tee $(TEMP_DIR)/benchstat.txt


Expand Down Expand Up @@ -159,12 +167,20 @@ integration-tools-save:
## Build-related targets #################################

.PHONY: snapshot
snapshot: ## Build the binary
snapshot: clean-snapshot ## Build the binary
$(call title,Build compatability test)
@.github/scripts/build.sh
@.github/scripts/build.sh $(SNAPSHOT_DIR)

## Cleanup targets #################################

.PHONY: clean
clean: clear-test-cache clean-snapshot ## Delete all generated artifacts
$(call safe_rm_rf_children,$(TEMP_DIR))

.PHONY: clean-snapshot
clean-snapshot: ## Delete all snapshot builds
$(call safe_rm_rf,$(SNAPSHOT_DIR))

.PHONY: clear-test-cache
clear-test-cache: ## Delete all test cache (built docker image tars)
find . -type f -wholename "**/test-fixtures/cache/*.tar" -delete
Expand Down
3 changes: 1 addition & 2 deletions pkg/file/get_xid.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin || netbsd
// +build linux darwin netbsd
//go:build !windows

package file

Expand Down
1 change: 0 additions & 1 deletion pkg/file/get_xid_win.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package file

Expand Down

0 comments on commit b0fc172

Please sign in to comment.