mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Task: Simplify development
The base directory has all shell scripts in scripts/ and all example/test files in examples/. A Makefile provides all the commands with helpful information. If a developer simply types `make` then vendor is properly updated, the code is formatted, linted, tested, built, acceptance test run, and installed. Linting errors resolved. Ignored test case (`TestParsePath`) updated to work as expected.
This commit is contained in:
12
scripts/acceptance.sh
Executable file
12
scripts/acceptance.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# acceptance test
|
||||
X=$(./bin/yaml w ./examples/sample.yaml b.c 3 | ./bin/yaml r - b.c)
|
||||
|
||||
if [ $X != 3 ]
|
||||
then
|
||||
echo "Failed acceptance test: expected 2 but was $X"
|
||||
exit 1
|
||||
fi
|
||||
26
scripts/check.sh
Executable file
26
scripts/check.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
gometalinter \
|
||||
--skip=examples \
|
||||
--tests \
|
||||
--vendor \
|
||||
--disable=aligncheck \
|
||||
--disable=gotype \
|
||||
--disable=goconst \
|
||||
--cyclo-over=20 \
|
||||
--deadline=300s \
|
||||
./...
|
||||
|
||||
gometalinter \
|
||||
--skip=examples \
|
||||
--tests \
|
||||
--vendor \
|
||||
--disable=aligncheck \
|
||||
--disable=gotype \
|
||||
--disable=goconst \
|
||||
--disable=gocyclo \
|
||||
--deadline=300s \
|
||||
./...
|
||||
6
scripts/coverage.sh
Executable file
6
scripts/coverage.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
go test -coverprofile=coverage.out
|
||||
go tool cover -html=coverage.out -o cover/coverage.html
|
||||
9
scripts/devtools.sh
Executable file
9
scripts/devtools.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
go get -u github.com/alecthomas/gometalinter
|
||||
go get -u golang.org/x/tools/cmd/goimports
|
||||
go get -u github.com/mitchellh/gox
|
||||
go get -u github.com/kardianos/govendor
|
||||
|
||||
# install all the linters
|
||||
gometalinter --install --update
|
||||
3
scripts/format.sh
Executable file
3
scripts/format.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
find . \( -path ./vendor \) -prune -o -name "*.go" -exec goimports -w {} \;
|
||||
92
scripts/setup.sh
Executable file
92
scripts/setup.sh
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
find_mgr() {
|
||||
if hash minishift 2>/dev/null; then
|
||||
echo "minishift"
|
||||
else
|
||||
if hash docker-machine 2>/dev/null; then
|
||||
echo "docker-machine"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
get_vm_name() {
|
||||
case "$1" in
|
||||
minishift)
|
||||
echo "minishift"
|
||||
;;
|
||||
docker-machine)
|
||||
echo "${DOCKER_MACHINE_NAME}"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
is_vm_running() {
|
||||
local vm=$1
|
||||
declare -a running=($(VBoxManage list runningvms | awk '{ print $1 }'))
|
||||
local result='false'
|
||||
|
||||
for rvm in "${running[@]}"; do
|
||||
if [[ "${rvm}" == *"${vm}"* ]]; then
|
||||
result='true'
|
||||
fi
|
||||
done
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
if hash cygpath 2>/dev/null; then
|
||||
PROJECT_DIR=$(cygpath -w -a "$(pwd)")
|
||||
else
|
||||
PROJECT_DIR=$(pwd)
|
||||
fi
|
||||
|
||||
VM_MGR=$(find_mgr)
|
||||
if [[ -z $VM_MGR ]]; then
|
||||
echo "ERROR: No VM Manager found; expected one of ['minishift', 'docker-machine']"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VM_NAME=$(get_vm_name "$VM_MGR")
|
||||
if [[ -z $VM_NAME ]]; then
|
||||
echo "ERROR: No VM found; try running 'eval $(docker-machine env)'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! hash VBoxManage 2>/dev/null; then
|
||||
echo "VirtualBox executable 'VBoxManage' not found in path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
avail=$(is_vm_running "$VM_NAME")
|
||||
if [[ "$avail" == *"true"* ]]; then
|
||||
res=$(VBoxManage sharedfolder add "${VM_NAME}" --name "${PROJECT}" --hostpath "${PROJECT_DIR}" --transient 2>&1)
|
||||
if [[ -z $res || $res == *"already exists"* ]]; then
|
||||
# no need to show that it already exists
|
||||
:
|
||||
else
|
||||
echo "$res"
|
||||
exit 1
|
||||
fi
|
||||
echo "VM: [${VM_NAME}] -- Added Sharedfolder [${PROJECT}] @Path [${PROJECT_DIR}]"
|
||||
else
|
||||
echo "$VM_NAME is not currently running; please start your VM and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SSH_CMD="sudo mkdir -p /${PROJECT} ; sudo mount -t vboxsf ${PROJECT} /${PROJECT}"
|
||||
case "${VM_MGR}" in
|
||||
minishift)
|
||||
minishift ssh "${SSH_CMD}"
|
||||
echo "VM: [${VM_NAME}] -- Mounted Sharedfolder [${PROJECT}] @VM Path [/${PROJECT}]"
|
||||
;;
|
||||
docker-machine)
|
||||
docker-machine ssh "${VM_NAME}" "${SSH_CMD}"
|
||||
echo "VM: [${VM_NAME}] -- Mounted Sharedfolder [${PROJECT}] @VM Path [/${PROJECT}]"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
3
scripts/test.sh
Executable file
3
scripts/test.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
go test -v $(go list ./... | grep -v -E 'vendor|examples')
|
||||
8
scripts/vendor.sh
Executable file
8
scripts/vendor.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
govendor fetch github.com/op/go-logging
|
||||
govendor fetch github.com/spf13/cobra
|
||||
govendor fetch gopkg.in/yaml.v2
|
||||
govendor sync
|
||||
8
scripts/xcompile.sh
Executable file
8
scripts/xcompile.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This assumes that gonative and gox is installed as per the 'one time setup' instructions
|
||||
# at https://github.com/inconshreveable/gonative
|
||||
|
||||
rm build/*
|
||||
gox -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
||||
|
||||
Reference in New Issue
Block a user