Skip to content

Commit

Permalink
Squashed 'tools/' changes from ec369f58d..d6cc704a2
Browse files Browse the repository at this point in the history
d6cc704a2 Fix comment
7139116ae Revert "Push comments to the left so they don't appear in scripts"
e47e58f7b Push comments to the left so they don't appear in scripts
3945fcec8 Remove nonexistent env var GIT_TAG
cd6299284 Merge pull request #156 from weaveworks/drop-quay
af0eb5119 Merge pull request #157 from weaveworks/fix-image-tag-prefix-length
0b9aee4f2 Fix image-tag object name prefix length to 8 chars.
813c28fe7 Move from CircleCI 1.0 to 2.0
425cf4ef1 Move from quay.io to Dockerhub
87ccf4fd1 Merge pull request #155 from weaveworks/go-1-12
c31bc2865 Update lint script to work with Go 1.12
ed8e380d7 Update to Go 1.12.1

git-subtree-dir: tools
git-subtree-split: d6cc704a2892e8d85aa8fa4d201c1a404f02dfa4
  • Loading branch information
bboreham committed Oct 1, 2019
1 parent 5e3c8ab commit e4b3f6f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 57 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2
jobs:
build:
# Use 'machine' type so we can run the lint step with directory mounted
machine:
docker_layer_caching: true
working_directory: /home/circleci/src/github.com/weaveworks/build-tools
environment:
GOPATH: /home/circleci/
steps:
- checkout
- run: cd build; make
- run: docker run --rm -v "$PWD:$PWD" -w "$PWD" --entrypoint sh weaveworks/build-golang -c ./lint .
- run: cd cover; make
# Socks makefile needs to overwrite Go std library
- run: sudo chmod a+wr --recursive /usr/local/go/pkg
- run: cd socks; make
- run: cd runner; make

- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
cd build
docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORD
for image in $(make images); do
# Push all tags - latest and git-tag
docker push "${image}"
# Tag the built images with something derived from the base images in
# their respective Dockerfiles. So "FROM golang:1.8.0-stretch" as a
# base image would lead to a tag of "1.8.0-stretch"
IMG_TAG=$(make "imagetag-${image#weaveworks/build-}")
docker tag "${image}:latest" "${image}:${IMG_TAG}"
docker push "${image}:${IMG_TAG}"
done
fi
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Boiler plate for bulding Docker containers.
# All this must go at top of file I'm afraid.
IMAGE_PREFIX := quay.io/weaveworks/build-
IMAGE_PREFIX := weaveworks/build-
IMAGE_TAG := $(shell ../image-tag)
GIT_REVISION := $(shell git rev-parse HEAD)
UPTODATE := .uptodate
Expand Down
2 changes: 1 addition & 1 deletion build/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11.1-stretch
FROM golang:1.12.1-stretch
RUN apt-get update && \
apt-get install -y \
curl \
Expand Down
44 changes: 0 additions & 44 deletions circle.yml

This file was deleted.

5 changes: 4 additions & 1 deletion image-tag
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ set -o pipefail

WORKING_SUFFIX=$(if git status --porcelain | grep -qE '^(?:[^?][^ ]|[^ ][^?])\s'; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"

# Fix the object name prefix length to 8 characters to have it consistent across the system.
# See https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---shortlength
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short=8 HEAD)$WORKING_SUFFIX"
36 changes: 26 additions & 10 deletions lint
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ spell_check() {
}

lint_go() {
# This function is called on a whole directory containing Go files
local filename="$1"
local lint_result=0

Expand All @@ -73,7 +74,7 @@ lint_go() {
echo "${filename}: run gofmt -s -w ${filename}"
fi

go tool vet "${filename}" || lint_result=$?
go vet "${filename}" || lint_result=$?

# golint is completely optional. If you don't like it
# don't have it installed.
Expand Down Expand Up @@ -185,7 +186,7 @@ lint() {

case "$mimetype.$ext" in
text/x-shellscript.*) lint_sh "${filename}" || lint_result=1 ;;
*.go) lint_go "${filename}" || lint_result=1 ;;
*.go) ;; # done at directory level
*.tf) lint_tf "${filename}" || lint_result=1 ;;
*.md) lint_md "${filename}" || lint_result=1 ;;
*.py) lint_py "${filename}" || lint_result=1 ;;
Expand All @@ -208,7 +209,7 @@ lint_files() {
while read -r filename; do
lint "${filename}" || lint_result=1
done
exit $lint_result
return $lint_result
}

matches_any() {
Expand Down Expand Up @@ -239,18 +240,33 @@ filter_out() {
fi
}

list_files() {
lint_directory() {
local dirname="$1"
local lint_result=0
# This test is just checking if there are any Go files in the directory
if compgen -G "$dirname/*.go" >/dev/null; then
lint_go "${dirname}" || lint_result=1
fi
ls $dirname/* | filter_out "$LINT_IGNORE_FILE" | lint_files
return $lint_result
}

lint_directories() {
local lint_result=0
while read -r dirname; do
lint_directory "${dirname}" || lint_result=1
done
exit $lint_result
}

list_directories() {
if [ $# -gt 0 ]; then
find "$@" \( -name vendor -o -name .git \) -prune -o -type f
else
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
find "$@" \( -name vendor -o -name .git -o -name .cache -o -name .pkg \) -prune -o -type d
fi
}

if [ $# = 1 ] && [ -f "$1" ]; then
lint "$1"
elif [ -n "$PARALLEL" ]; then
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | xargs -n1 -P16 "$0"
else
list_files "$@" | filter_out "$LINT_IGNORE_FILE" | lint_files
list_directories "$@" | lint_directories
fi

0 comments on commit e4b3f6f

Please sign in to comment.