Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
enr committed Apr 11, 2016
0 parents commit 56dfc24
Show file tree
Hide file tree
Showing 136 changed files with 27,151 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
pkg/
dist/

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# zipp

Zip utilities:

- `zipls`: lists zip contents
- `zipts`: creates a zip file with a timestamp suffix in the name

![screenshot](Screenshot.png "Zipp screenshot")
Binary file added Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions hack/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

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 )"

source "${HACK_DIR}/config"

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

hash gb 2>/dev/null || {
go get -u github.com/constabulary/gb/...
}

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}"

gb build -ldflags "-s \
-X main.version=${APP_VERSION} \
-X main.buildTime=${buildtime} \
-X main.gitCommit=${git_commit}" all
74 changes: 74 additions & 0 deletions hack/build-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

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 )"

source "${HACK_DIR}/config"
SRC_DIR="${PRJ_HOME}/src"
DIST_DIR="${PRJ_HOME}/${DIST_DIR}"

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"
exit 1
}

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

hash gb 2>/dev/null || {
go get -u github.com/constabulary/gb/...
}

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

for dir in $(find "$SRC_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"
GOOS="$target_goos" GOARCH="$target_goarch" gb build -ldflags "-s \
-X main.version=${APP_VERSION} \
-X main.buildTime=${buildtime} \
-X main.gitCommit=${git_commit}" all > /dev/null
ext=''
[[ "windows" = "$target_goos" ]] && ext='.exe'
built="${PRJ_HOME}/bin/${app_name}-${target_goos}-${target_goarch}${ext}"
[[ -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
52 changes: 52 additions & 0 deletions hack/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

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 )"


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

SRC_DIR="${PRJ_HOME}/src"

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

hash gb 2>/dev/null || {
go get -u github.com/constabulary/gb/...
}

export GOPATH="${PRJ_HOME}:${PRJ_HOME}/vendor"

cd "${PRJ_HOME}"

for dir in $(find "$SRC_DIR" -mindepth 1 -maxdepth 1 -type d); do
app_name=$(basename "$dir")
echo " ===== Process ${app_name} ${dir} ====="
cd "$dir"
golint
go fmt ./...
go vet ./...
goimports -w .
# - diff <(goimports -d .) <(printf "")
# - diff <(golint ./...) <(printf "")
cd "$PRJ_HOME"
gb build "$app_name"
# echo "${d} go test -cpu=1,2,4 -race ./..."
# go test -cpu=1,2,4 -race ./...
cd "$dir"
echo "${dir} go test -cover ./..."
go test -cover ./...
# echo "${d} go test show output"
# go test -cover -v ./... -showoutput
done

# for dir in $(find "$SRC_DIR" -mindepth 1 -maxdepth 1 -type d); do
# echo " - Process $dir"
# bname=$(basename "$dir")
# echo $bname
# done
5 changes: 5 additions & 0 deletions hack/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GH_OWNER='enr'
GH_REPO='zipp'
DIST_DIR='dist'

APP_VERSION='0.2'
65 changes: 65 additions & 0 deletions hack/gh-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

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 )"

source "${HACK_DIR}/config"

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

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

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

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

if [ -z "$APP_VERSION" ]; then
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=''
else
PRERELEASE='--prerelease'
fi

echo "Release $PRJ_HOME version $RELEASE_VERSION $PRERELEASE"

"${HACK_DIR}/build-dist"

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

#ghr -t "$GH_TOKEN" -u "$GH_OWNER" -r "$GH_REPO" "$PRERELEASE" "$RELEASE_VERSION" "$DIST_DIR"
GHR_COMMAND="ghr -t ${GH_TOKEN} -u ${GH_OWNER} -r ${GH_REPO} ${PRERELEASE} ${RELEASE_VERSION} ${DIST_DIR}"
echo "$GHR_COMMAND"
sh -c "$GHR_COMMAND"
14 changes: 14 additions & 0 deletions hack/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

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 )"

cd "$PRJ_HOME"

go get -u github.com/constabulary/gb/...

gb vendor update -all
Loading

0 comments on commit 56dfc24

Please sign in to comment.