Improve package structure (#207)

* Improve package structure

* Set up travis
This commit is contained in:
Sung Won Cho 2019-06-25 19:20:19 +10:00 committed by GitHub
commit 23a511dbe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
171 changed files with 4750 additions and 4531 deletions

106
pkg/cli/scripts/build.sh Executable file
View file

@ -0,0 +1,106 @@
#!/bin/bash
#
# build.sh compiles dnote binary for target platforms
# it is resonsible for creating distributable files that can
# be released by a human or a script
# use: ./scripts/build.sh 0.4.8
set -eu
version="$1"
projectDir="$GOPATH/src/github.com/dnote/dnote"
basedir="$GOPATH/src/github.com/dnote/dnote/pkg/cli"
TMP="$basedir/build"
command_exists () {
command -v "$1" >/dev/null 2>&1;
}
if ! command_exists shasum; then
echo "please install shasum"
exit 1
fi
if [ $# -eq 0 ]; then
echo "no version specified."
exit 1
fi
if [[ $1 == v* ]]; then
echo "do not prefix version with v"
exit 1
fi
build() {
# init build dir
rm -rf "$TMP"
mkdir "$TMP"
# fetch tool
go get -u github.com/karalabe/xgo
pushd "$basedir"
# build linux
xgo --targets="linux/amd64"\
--tags "linux fts5"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/linux"
mv cli-linux-amd64 "$TMP/linux/dnote"
# build darwin
xgo --targets="darwin/amd64"\
--tags "darwin fts5"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/darwin"
mv cli-darwin-10.6-amd64 "$TMP/darwin/dnote"
# build windows
xgo --targets="windows/amd64"\
--tags "fts5"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/windows"
mv cli-windows-4.0-amd64.exe "$TMP/windows/dnote.exe"
popd
}
get_buildname() {
os=$1
echo "dnote_${version}_${os}_amd64"
}
calc_checksum() {
os=$1
pushd "$TMP/$os"
buildname=$(get_buildname "$os")
mv dnote "$buildname"
shasum -a 256 "$buildname" >> "$TMP/dnote_${version}_checksums.txt"
mv "$buildname" dnote
popd
}
build_tarball() {
os=$1
buildname=$(get_buildname "$os")
pushd "$TMP/$os"
cp "$projectDir/licenses/GPLv3.txt" .
cp "$basedir/README.md" .
tar -zcvf "../${buildname}.tar.gz" ./*
popd
}
build
calc_checksum darwin
calc_checksum linux
build_tarball windows
build_tarball darwin
build_tarball linux

11
pkg/cli/scripts/dev.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
set -eux
# dev.sh builds a new binary and replaces the old one in the PATH with it
sudo rm -rf "$(which dnote)" "$GOPATH/bin/cli"
# change tags to darwin if on macos
go install -ldflags "-X main.apiEndpoint=http://127.0.0.1:5000" --tags "linux fts5" "$GOPATH/src/github.com/dnote/dnote/pkg/cli/."
sudo ln -s "$GOPATH/bin/cli" /usr/local/bin/dnote

5
pkg/cli/scripts/dump_schema.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# dump_schema.sh dumps the current system's dnote schema to testutils package
# to be used while setting up tests
sqlite3 ~/.dnote/dnote.db .schema > ./testutils/fixtures/schema.sql

58
pkg/cli/scripts/release.sh Executable file
View file

@ -0,0 +1,58 @@
#!/bin/bash
#
# release.sh releases the tarballs and checksum in the build directory
# to GitHub and brew. It is important to build those files using build.sh
# use: ./scripts/release.sh v0.4.8
set -eu
homebrewRepoDir="$GOPATH"/src/github.com/dnote/homebrew-dnote
command_exists () {
command -v "$1" >/dev/null 2>&1;
}
if [ $# -eq 0 ]; then
echo "no version specified."
exit 1
fi
if [[ $1 == v* ]]; then
echo "do not prefix version with v"
exit 1
fi
if ! command_exists hub; then
echo "please install hub"
exit 1
fi
if [ ! -d "$homebrewRepoDir" ]; then
echo "homebrew-dnote not found locally. did you clone it?"
exit 1
fi
# 1. push tag
version=$1
version_tag="cli-v$version"
echo "* tagging and pushing the tag"
git tag -a "$version_tag" -m "Release $version_tag"
git push --tags
# 2. release on GitHub
files=(./build/*.tar.gz ./build/*.txt)
file_args=()
for file in "${files[@]}"; do
file_args+=("--attach=$file")
done
echo "* creating release"
set -x
hub release create \
"${file_args[@]}" \
--message="$version_tag"\
"$version_tag"
# 3. Release on Homebrew
homebrew_sha256=$(shasum -a 256 "./build/dnote_${version}_darwin_amd64.tar.gz" | cut -d ' ' -f 1)
(cd "$homebrewRepoDir" && ./release.sh "$version" "$homebrew_sha256")

19
pkg/cli/scripts/test.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# run_server_test.sh runs server test files sequentially
# https://stackoverflow.com/questions/23715302/go-how-to-run-tests-for-multiple-packages
set -eux
basePath="$GOPATH/src/github.com/dnote/dnote/pkg/cli"
# clear tmp dir in case not properly torn down
rm -rf "$basePath/tmp"
# run test
pushd "$basePath"
go test -a ./... \
-p 1\
--tags "fts5"
popd