mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
parent
3d4c8ea8f4
commit
332fd8f8ca
5 changed files with 112 additions and 52 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -4,4 +4,4 @@ tmp/
|
|||
/vendor
|
||||
test-dnote
|
||||
/dist
|
||||
/release
|
||||
/build
|
||||
|
|
|
|||
|
|
@ -30,13 +30,17 @@ Run Dnote with `DNOTE_DEBUG=1` to print debugging statements.
|
|||
|
||||
## Release
|
||||
|
||||
This project uses [goreleaser](https://github.com/goreleaser/goreleaser) to automate the release process.
|
||||
|
||||
The following will tag, push the tag, create release on GitHub, build artifacts, upload them, and
|
||||
push a commit to [Dnote Homebrew tap](https://github.com/dnote/homebrew-dnote).
|
||||
* Build for all target platforms, tag, push tags
|
||||
* Release on GitHub and [Dnote Homebrew tap](https://github.com/dnote/homebrew-dnote).
|
||||
|
||||
```sh
|
||||
VERSION=v0.4.2 make
|
||||
VERSION=0.4.8 make release
|
||||
```
|
||||
|
||||
* Build, without releasing, for all target platforms
|
||||
|
||||
```sh
|
||||
VERSION=0.4.8 make
|
||||
```
|
||||
|
||||
**Note**
|
||||
|
|
|
|||
17
Makefile
17
Makefile
|
|
@ -1,14 +1,11 @@
|
|||
release:
|
||||
@echo "** Releasing version $(VERSION)..."
|
||||
@echo "** Tagging and pushing..."
|
||||
@git tag -a $(VERSION) -m "$(VERSION)"
|
||||
@git push --tags
|
||||
@API_ENDPOINT=https://api.dnote.io goreleaser --rm-dist
|
||||
.PHONY: release
|
||||
all:
|
||||
./scripts/build.sh $(VERSION)
|
||||
.PHONY: all
|
||||
|
||||
build-snapshot:
|
||||
@API_ENDPOINT=http://127.0.0.1:5000 goreleaser --snapshot --rm-dist
|
||||
.PHONY: build-snapshot
|
||||
release:
|
||||
./scripts/build.sh $(VERSION)
|
||||
./scripts/release.sh $(VERSION)
|
||||
.PHONY: release
|
||||
|
||||
clean:
|
||||
@git clean -f
|
||||
|
|
|
|||
88
scripts/build.sh
Executable file
88
scripts/build.sh
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
#!/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"
|
||||
basedir="$GOPATH/src/github.com/dnote/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"\
|
||||
-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"\
|
||||
-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"\
|
||||
-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
|
||||
}
|
||||
|
||||
calc_checksum() {
|
||||
os=$1
|
||||
|
||||
shasum -a 256 "$TMP/$os/dnote" >> "$TMP/dnote_${version}_checksums.txt"
|
||||
}
|
||||
|
||||
build_tarball() {
|
||||
os=$1
|
||||
|
||||
pushd "$TMP/$os"
|
||||
|
||||
cp "$basedir/LICENSE" .
|
||||
cp "$basedir/README.md" .
|
||||
tar -zcvf "../dnote_${version}_${os}_amd64.tar.gz" ./*
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
build
|
||||
|
||||
calc_checksum darwin
|
||||
calc_checksum linux
|
||||
|
||||
build_tarball windows
|
||||
build_tarball darwin
|
||||
build_tarball linux
|
||||
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
#!/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
|
||||
|
||||
|
|
@ -19,49 +23,17 @@ if ! command_exists hub; then
|
|||
echo "please install hub"
|
||||
exit 1
|
||||
fi
|
||||
if ! command_exists shasum; then
|
||||
echo "please install shasum"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
binary=dnote
|
||||
# 1. push tag
|
||||
version=$1
|
||||
version_tag="v$version"
|
||||
goos=("linux" "openbsd" "freebsd" "darwin" "windows")
|
||||
goarch=("386" "amd64")
|
||||
|
||||
rm -rf ./release
|
||||
mkdir ./release
|
||||
cp LICENSE ./release/LICENSE
|
||||
cp README.md ./release/README.md
|
||||
|
||||
echo "* release $version"
|
||||
|
||||
# 1. build
|
||||
for os in "${goos[@]}"; do
|
||||
for arch in "${goarch[@]}"; do
|
||||
filename="${binary}_${version}_${os}_${arch}"
|
||||
echo "* building $filename"
|
||||
|
||||
GOOS="$os" GOARCH="$arch" go build \
|
||||
-o "./release/$filename" \
|
||||
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version"
|
||||
|
||||
pushd ./release > /dev/null
|
||||
cp "$filename" dnote
|
||||
tar -czvf "$filename.tar.gz" dnote LICENSE README.md
|
||||
shasum -a 256 "$filename" >> "dnote_${version}_checksums.txt"
|
||||
popd > /dev/null
|
||||
done
|
||||
done
|
||||
|
||||
# 2. push tag
|
||||
echo "* tagging and pushing the tag"
|
||||
git tag -a "$version_tag" -m "Release $version_tag"
|
||||
git push --tags
|
||||
|
||||
# 3. create release
|
||||
files=(./release/*.tar.gz ./release/*.txt)
|
||||
# 2. release on GitHub
|
||||
files=(./build/*.tar.gz ./build/*.txt)
|
||||
file_args=()
|
||||
for file in "${files[@]}"; do
|
||||
file_args+=("--attach=$file")
|
||||
|
|
@ -74,7 +46,6 @@ hub release create \
|
|||
--message="$version_tag"\
|
||||
"$version_tag"
|
||||
|
||||
# 4. release on brew
|
||||
|
||||
homebrew_sha256=$(shasum -a 256 "./release/${binary}_${version}_darwin_amd64.tar.gz" | cut -d ' ' -f 1)
|
||||
# 3. Release on Homebrew
|
||||
homebrew_sha256=$(shasum -a 256 "./build/dnote_${version}_darwin_amd64.tar.gz" | cut -d ' ' -f 1)
|
||||
(cd "$GOPATH"/src/github.com/dnote/homebrew-dnote && ./release.sh "$version" "$homebrew_sha256")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue