Skip to content

Commit

Permalink
Merge pull request #111 from dnephin/use-plsdo
Browse files Browse the repository at this point in the history
Replace dobi with plsdo
  • Loading branch information
dnephin committed May 15, 2020
2 parents 729c5b2 + 454e0db commit 2ddfdd2
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
.dobi/
dist/
junit.xml
.plsdo/
75 changes: 75 additions & 0 deletions .plsdo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# plsdo.sh, version 0.1.1
set -o errexit -o nounset -o pipefail

_plsdo_run() {
case "${1-}" in
""|help)
_plsdo_help "${2-}" ;;
*)
"$@" ;;
esac
}

declare -A help

help[list]="Print the list of tasks"
list() {
declare -F | awk '{print $3}' | grep -v '^_'
}

_plsdo_help_task_name_width="${_plsdo_help_task_name_width:-12}"

_plsdo_help() {
local topic="${1-}"
# print help for the topic
if [ -n "$topic" ]; then
if ! command -v "$topic" > /dev/null ; then
_plsdo_error "No such task: $topic"
return 1
fi

printf "\nUsage:\n %s %s\n\n%s\n" "$0" "$topic" "${help[$topic]-}"
return 0
fi

# print list of tasks and their help line.
[ -n "${banner-}" ] && echo "$banner" && echo
for i in $(list); do
printf "%-${_plsdo_help_task_name_width}s\t%s\n" "$i" "${help[$i]-}" | head -1
done
}

_plsdo_error() {
>&2 echo "$@"
}

# shellcheck disable=SC2016
help[_plsdo_completion]='Print tab completion for $SHELL.
Redirect the output to a file that will be run when the shell starts,
such as ~/.bashrc.
$ ./do _pldsdo_completion >> ~/.bash_complete/do
'
_plsdo_completion() {
local shell; shell="$(basename "$SHELL" 2> /dev/null)"
case "$shell" in
bash)
cat <<+++
_dotslashdo_completions() {
if ! command -v $0 > /dev/null; then return; fi
if [ "\${#COMP_WORDS[@]}" != "2" ]; then return; fi
COMPREPLY=(\$(compgen -W "\$($0 list)" "\${COMP_WORDS[1]}"))
}
complete -F _dotslashdo_completions $0
+++
;;
"")
_plsdo_error "Set \$SHELL to select tab completion."
return 1 ;;
*)
_plsdo_error "No completetion for shell: $shell"
return 1 ;;
esac
}
11 changes: 8 additions & 3 deletions dobifiles/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

ARG GOLANG_VERSION
FROM golang:${GOLANG_VERSION:-1.12-alpine} as golang
FROM golang:${GOLANG_VERSION:-1.14-alpine} as golang
RUN apk add -U curl git bash
ENV CGO_ENABLED=0 \
PS1="# " \
GO111MODULE=on
WORKDIR /go/src/gotest.tools/gotestsum
ARG UID=1000
RUN adduser --uid=${UID} --disabled-password devuser
USER ${UID}:${UID}


FROM golang as tools
RUN go get github.com/dnephin/filewatcher@v0.3.2
RUN wget -O- -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s && \
RUN wget -O- -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s && \
mv bin/golangci-lint /go/bin


FROM golang as dev
COPY --from=tools /go/bin/filewatcher /usr/bin/filewatcher
COPY --from=tools /go/bin/golangci-lint /usr/bin/golangci-lint


FROM dev as dev-with-source
COPY . .
55 changes: 55 additions & 0 deletions do
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

source .plsdo.sh

binary() {
mkdir -p dist
go build -o dist/gotestsum .
}

update-golden() {
gotestsum -- ./testjson ./internal/junitxml -test.update-golden
}

lint() {
golangci-lint run -v
}

go-mod-tidy() {
go mod tidy
git diff --stat --exit-code go.mod go.sum
}

shell() {
local tag; tag="$(_docker-build-dev)"
docker run \
--tty --interactive --rm \
-v "$PWD:/work" \
-v ~/.cache/go-build:/root/.cache/go-build \
-v ~/go/pkg/mod:/go/pkg/mod \
-w /work \
"$tag" bash
}

_docker-build-dev() {
set -e
local idfile=.plsdo/docker-build-dev-image-id
local dockerfile=Dockerfile
local tag=gotest.tools/gotestsum/builder
if [ -f "$idfile" ] && [ "$dockerfile" -ot "$idfile" ]; then
echo "$tag"
return 0
fi

mkdir -p .plsdo
>&2 docker build \
--iidfile "$idfile" \
--file "$dockerfile" \
--tag "$tag" \
--build-arg "UID=$UID" \
--target "dev" \
.plsdo
echo "$tag"
}

_plsdo_run "$@"
56 changes: 0 additions & 56 deletions dobi.yaml

This file was deleted.

0 comments on commit 2ddfdd2

Please sign in to comment.