Skip to content

Commit

Permalink
introduce deps
Browse files Browse the repository at this point in the history
  • Loading branch information
enr committed Sep 7, 2018
1 parent acd2f62 commit 6303cd7
Show file tree
Hide file tree
Showing 112 changed files with 17,379 additions and 7,898 deletions.
44 changes: 44 additions & 0 deletions .sdlc/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -e

TOOL_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$TOOL_SOURCE" ] ; do TOOL_SOURCE="$(readlink "$TOOL_SOURCE")"; done
SDLC_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$SDLC_DIR" )" && pwd )"

source "${SDLC_DIR}/config"

CMDS_DIR="${PRJ_HOME}/cmd"
BIN_DIR="${PRJ_HOME}/bin"
[[ -d "$BIN_DIR" ]] && rm -r "$BIN_DIR"
mkdir "$BIN_DIR"

cd "${PRJ_HOME}"

buildtime=$(TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ')
git_hash="$(git rev-parse HEAD)"
git_dirty="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
git_commit="${git_hash}${git_dirty}"
echo "building ${GH_REPO}"
echo "version : ${APP_VERSION}"
echo "git : ${git_commit}"
echo "build time : ${buildtime}"

command -v dep >/dev/null || {
echo "dep not found"
exit 1
}
echo 'Running dep ensure'
dep ensure -v

for dir in $(find "$CMDS_DIR" -mindepth 1 -maxdepth 1 -type d); do
app_name=$(basename "$dir")
echo " ===== Process ${app_name} ${dir} ====="
go build -ldflags "-s \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.Version=${APP_VERSION} \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.BuildTime=${buildtime} \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.GitCommit=${git_commit}" \
-o "${BIN_DIR}/${app_name}" \
"github.com/${GH_OWNER}/${GH_REPO}/cmd/${app_name}"
done
71 changes: 71 additions & 0 deletions .sdlc/build-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

set -e

TOOL_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$TOOL_SOURCE" ] ; do TOOL_SOURCE="$(readlink "$TOOL_SOURCE")"; done
SDLC_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$SDLC_DIR" )" && pwd )"

source "${SDLC_DIR}/config"
DIST_DIR="${PRJ_HOME}/${DIST_DIR}"
CMDS_DIR="${PRJ_HOME}/cmd"

buildtime=$(TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ')
git_hash="$(git rev-parse HEAD)"
git_dirty="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
git_commit="${git_hash}${git_dirty}"
echo "building ${GH_REPO}"
echo "version : ${APP_VERSION}"
echo "git : ${git_commit}"
echo "build time : ${buildtime}"

[[ -z "$DIST_DIR" ]] && {
echo "no dist dir set"
exit 1
}

[[ -d "${PRJ_HOME}/bin" ]] && rm -r "${PRJ_HOME}/bin"
[[ -d "$DIST_DIR" ]] && rm -r "$DIST_DIR"
mkdir -p "$DIST_DIR"

platforms="windows/amd64 linux/amd64 darwin/amd64"

for dir in $(find "$CMDS_DIR" -mindepth 1 -maxdepth 1 -type d); do
app_name=$(basename "$dir")
echo " ===== Process ${app_name} ${dir} ====="
for platform in $platforms; do
cd "$PRJ_HOME"
target_goos=$(echo $platform | cut -d/ -f1)
target_goarch=$(echo $platform | cut -d/ -f2)
echo "building for ${target_goos} ${target_goarch}"
platform_dist_basename="${GH_REPO}-${APP_VERSION}_${target_goos}_${target_goarch}"
platform_dist_dir="${DIST_DIR}/${platform_dist_basename}"
mkdir -p "$platform_dist_dir"
ext=''
[[ "windows" = "$target_goos" ]] && ext='.exe'
built="${PRJ_HOME}/bin/${app_name}-${target_goos}-${target_goarch}${ext}"
GOOS="$target_goos" GOARCH="$target_goarch" go build -ldflags "-s \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.Version=${APP_VERSION} \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.BuildTime=${buildtime} \
-X github.com/${GH_OWNER}/${GH_REPO}/lib/core.GitCommit=${git_commit}" \
-o "$built" \
"github.com/${GH_OWNER}/${GH_REPO}/cmd/${app_name}"
[[ -e "$built" ]] || {
echo "expected file not found: ${built}"
exit 1
}
mv "${PRJ_HOME}/bin/${app_name}-${target_goos}-${target_goarch}${ext}" "${platform_dist_dir}/${app_name}${ext}"
# cd "$DIST_DIR"
# zip -r "${platform_dist_basename}.zip" "$platform_dist_basename"
# rm -r "$platform_dist_basename"
done
done

cd "$DIST_DIR"
for dir in $(find "$DIST_DIR" -mindepth 1 -maxdepth 1 -type d); do
dist_folder=$(basename "$dir")
echo " ===== Create dist ${dist_folder} ${dir} ====="
zip -r "${dist_folder}.zip" "$dist_folder"
rm -r "$dist_folder"
done
49 changes: 49 additions & 0 deletions .sdlc/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -e

TOOL_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$TOOL_SOURCE" ] ; do TOOL_SOURCE="$(readlink "$TOOL_SOURCE")"; done
SDLC_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$SDLC_DIR" )" && pwd )"

source "${SDLC_DIR}/config"
app_name="$GH_REPO"

SRC_DIR="${PRJ_HOME}/src"
CMDS_DIR="${PRJ_HOME}/cmd"
BIN_DIR="${PRJ_HOME}/bin"

[[ -d "${PRJ_HOME}/bin" ]] && rm -r "${PRJ_HOME}/bin"

hash golint 2>/dev/null || {
go get -u github.com/golang/lint/golint
}

hash goimports 2>/dev/null || {
go get golang.org/x/tools/cmd/goimports
}

cd "${PRJ_HOME}"

for dir in $(find "$CMDS_DIR" -mindepth 1 -maxdepth 1 -type d); do
app_name=$(basename "$dir")
echo "===== Process ${app_name} [${dir}]"
cd "$dir"
echo "----- golint"
diff <(golint ./...) <(printf "")
echo "----- go fmt"
go fmt ./...
echo "----- go vet"
go vet ./...
echo "----- goimports"
goimports -w .
diff <(goimports -d .) <(printf "")
cd "$PRJ_HOME"
echo "----- go build"
# we need binaries for some e2e test
go build -o "${BIN_DIR}/${app_name}" "github.com/${GH_OWNER}/${GH_REPO}/cmd/${app_name}"
cd "$dir"
echo "----- go test -cover ./..."
go test -cover ./...
done
2 changes: 1 addition & 1 deletion hack/config → .sdlc/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ GH_OWNER='enr'
GH_REPO='dups'
DIST_DIR='dist'

APP_VERSION='0.2'
APP_VERSION='0.3.0'
42 changes: 21 additions & 21 deletions hack/gh-release → .sdlc/gh-release
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,59 @@ set -e

TOOL_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$TOOL_SOURCE" ] ; do TOOL_SOURCE="$(readlink "$TOOL_SOURCE")"; done
HACK_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$HACK_DIR" )" && pwd )"
SDLC_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$SDLC_DIR" )" && pwd )"

source "${HACK_DIR}/config"
source "${SDLC_DIR}/config"

git_dirty=$(git status --porcelain)
[[ -n "$git_dirty" ]] && {
echo 'uncommitted changes detected: aborting release'
exit 1
echo 'uncommitted changes detected: aborting release'
exit 1
}

[[ -z "$GH_TOKEN" ]] && {
echo "Missing GH_TOKEN"
exit 1
echo "Missing GH_TOKEN"
exit 1
}

# https://github.com/tcnksm/ghr/releases/download/v0.4.0/ghr_v0.4.0_linux_amd64.zip
# https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_linux_amd64.zip
command -v ghr >/dev/null || {
echo "ghr not found"
exit 1
echo "ghr not found"
exit 1
}

[[ -z "$GH_OWNER" ]] && {
echo "no gh owner"
exit 1
echo "no gh owner"
exit 1
}
[[ -z "$GH_REPO" ]] && {
echo "no gh repo"
exit 1
echo "no gh repo"
exit 1
}

if [ -z "$APP_VERSION" ]; then
echo 'no release version supplied. $APP_VERSION expected'
exit 1
echo 'no release version supplied. $APP_VERSION expected'
exit 1
fi

RELEASE_VERSION="v$APP_VERSION"
git tag -a "${RELEASE_VERSION}" -m "release version ${RELEASE_VERSION}"
git push origin "${RELEASE_VERSION}"

if [ "$1" = "--prod" ]; then
PRERELEASE=''
PRERELEASE=''
else
PRERELEASE='--prerelease'
PRERELEASE='--prerelease'
fi

echo "Release $PRJ_HOME version $RELEASE_VERSION $PRERELEASE"

"${HACK_DIR}/build-dist"
"${SDLC_DIR}/build-dist"

[[ -z "$DIST_DIR" ]] && {
echo "dist directory not found: ${DIST_DIR}"
exit 1
echo "dist directory not found: ${DIST_DIR}"
exit 1
}

#ghr -t "$GH_TOKEN" -u "$GH_OWNER" -r "$GH_REPO" "$PRERELEASE" "$RELEASE_VERSION" "$DIST_DIR"
Expand Down
17 changes: 17 additions & 0 deletions .sdlc/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

TOOL_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$TOOL_SOURCE" ] ; do TOOL_SOURCE="$(readlink "$TOOL_SOURCE")"; done
SDLC_DIR="$( cd -P "$( dirname "$TOOL_SOURCE" )" && pwd )"
PRJ_HOME="$( cd -P "$( dirname "$SDLC_DIR" )" && pwd )"

cd "$PRJ_HOME"

command -v dep >/dev/null || {
echo "dep not found"
exit 1
}

dep ensure -update -v
68 changes: 68 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/enr/go-commons"

[[constraint]]
branch = "master"
name = "github.com/enr/go-files"

[[constraint]]
branch = "master"
name = "github.com/enr/runcmd"

[prune]
go-tests = true
unused-packages = true
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6303cd7

Please sign in to comment.