-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts to validate and test code locally
Signed-off-by: Volker Theile <[email protected]>
- Loading branch information
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.dapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM registry.suse.com/bci/golang:1.21 | ||
|
||
ARG DAPPER_HOST_ARCH | ||
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} | ||
|
||
RUN zypper -n rm container-suseconnect && \ | ||
zypper -n install git curl docker gzip tar wget awk | ||
|
||
## install golangci | ||
RUN if [ "${ARCH}" == "amd64" ]; then \ | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1; \ | ||
fi | ||
|
||
ENV DAPPER_ENV REPO TAG DRONE_TAG | ||
ENV DAPPER_SOURCE /go/src/github.com/harvester/go-common/ | ||
ENV DAPPER_DOCKER_SOCKET true | ||
ENV HOME ${DAPPER_SOURCE} | ||
WORKDIR ${DAPPER_SOURCE} | ||
|
||
ENTRYPOINT ["./scripts/entry"] | ||
CMD ["ci"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
TARGETS := $(shell ls scripts) | ||
|
||
.dapper: | ||
@echo Downloading dapper | ||
@curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp | ||
@@chmod +x .dapper.tmp | ||
@./.dapper.tmp -v | ||
@mv .dapper.tmp .dapper | ||
|
||
$(TARGETS): .dapper | ||
./.dapper $@ | ||
|
||
.DEFAULT_GOAL := default | ||
|
||
.PHONY: $(TARGETS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
mkdir -p bin dist | ||
if [ -e ./scripts/$1 ]; then | ||
./scripts/"$@" | ||
else | ||
exec "$@" | ||
fi | ||
|
||
chown -R $DAPPER_UID:$DAPPER_GID . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
cd $(dirname $0)/.. | ||
|
||
echo Running tests | ||
go test -cover -tags=test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
cd $(dirname $0)/.. | ||
|
||
echo Running validation | ||
|
||
PACKAGES="$(go list ./...)" | ||
|
||
if ! command -v golangci-lint; then | ||
echo Skipping validation: no golangci-lint available | ||
exit | ||
fi | ||
|
||
echo Running validation | ||
|
||
echo Running: golangci-lint | ||
golangci-lint run | ||
|
||
echo Running: go fmt | ||
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then | ||
DIRTY="-dirty" | ||
fi | ||
|
||
COMMIT=$(git rev-parse --short HEAD) | ||
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} | ||
|
||
if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then | ||
VERSION=$GIT_TAG | ||
else | ||
VERSION="${COMMIT}${DIRTY}" | ||
fi | ||
|
||
if [ -z "$ARCH" ]; then | ||
ARCH=$(go env GOHOSTARCH) | ||
fi | ||
|
||
SUFFIX="-${ARCH}" | ||
|
||
TAG=${TAG:-${VERSION}${SUFFIX}} | ||
REPO=${REPO:-harvester} | ||
|
||
if echo $TAG | grep -q dirty; then | ||
TAG=dev | ||
fi |