#!/bin/sh # script/lint: run golangci-lint, in Docker only. Builds the lint stage of # the Dockerfile, whose build runs the linter, so a successful build is a # clean lint. --no-cache because a cached build runs no linter. The image # is removed afterwards, whatever the outcome. set -eu SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)" main() { cd "$ROOT" # Tagged per run, so concurrent runs never remove each other's image. image="$("$SCRIPT_DIR/projectname")-lint:$$" # A failed build leaves no image, so there is nothing to remove then. trap 'docker image rm "$image" >/dev/null 2>&1 || true' EXIT INT TERM docker build --no-cache --target lint -t "$image" . } main "$@"