Skip to content

Commit

Permalink
Add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed May 19, 2020
1 parent 7b13837 commit b1c9c8d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Dockerfile
stuff
scripts
.git
dist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
stuff
dist
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Unreleased

First release!
14 changes: 0 additions & 14 deletions scripts/docker-release.sh

This file was deleted.

103 changes: 103 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
set -xeo pipefail

docker_name=shesek/bwt
gh_repo=shesek/bwt

if ! git diff-index --quiet HEAD; then
echo git working directory is dirty
exit 1
fi

version=`cat Cargo.toml | egrep '^version =' | cut -d'"' -f2`

if [[ "$1" == "patch" ]]; then
# bump the patch version by one
version=`node -p 'process.argv[1].replace(/\.(\d+)$/, (_, v) => "."+(+v+1))' $version`
sed -i 's/^version =.*/version = "'$version'"/' Cargo.toml
elif [[ "$1" != "nobump" ]]; then
echo invalid argument, use "patch" or "nobump"
exit 1
fi

# Extract unreleased changelog & update version number
changelog="`sed -nr '/^## (Unreleased|'$version' )/{n;:a;n;/^## /q;p;ba}' CHANGELOG.md`"
grep '## Unreleased' CHANGELOG.md > /dev/null \
&& sed -i "s/^## Unreleased/## $version - `date +%Y-%m-%d`/" CHANGELOG.md

echo -e "Releasing bwt v$version\n================\n\n$changelog\n\n"

echo Running cargo check and fmt...
cargo fmt -- --check
./scripts/check.sh

if [ -z "$SKIP_BUILD" ]; then
echo Building executables...
build_bin() {
echo "Building $1 with: $2"
cargo build --release --no-default-features --features "$2"
mkdir -p dist/$1
mv target/release/bwt dist/$1
cp README.md LICENSE dist/$1
(cd dist && tar -czf $1.tar.gz $1)
rm -r dist/$1
}
rm -rf dist/*
build_bin "bwt-v$version-electrum_only-x86_64-linux" "electrum"
build_bin "bwt-v$version-x86_64-linux" "http electrum webhooks track-spends"

echo Making SHA256SUMS...
(cd dist && sha256sum *) | gpg --clearsign --digest-algo sha256 > SHA256SUMS.asc
fi


if [ -z "$SKIP_TAG" ]; then
echo Tagging...
git add Cargo.{toml,lock} CHANGELOG.md SHA256SUMS.asc
git commit -S -m v$version
git tag --sign -m "$changelog" v$version
git branch -f stable HEAD

echo Pushing to github...
git push gh master stable
git push gh --tags
fi

if [ -z "$SKIP_DOCKER" ]; then
echo Releasing docker images...

docker_tag=$docker_name:$version
docker build -t $docker_tag .
docker build -t $docker_tag-electrum --build-arg FEATURES=electrum .
docker tag $docker_tag $docker_name:latest
docker tag $docker_tag-electrum $docker_name:electrum
docker push $docker_name
fi

if [ -z "$SKIP_CRATE" ]; then
echo Publishing to crates.io...
cargo publish
fi


if [[ -z "$SKIP_UPLOAD" && -n "$GH_TOKEN" ]]; then
echo Uploading to github...
gh_auth="Authorization: token $GH_TOKEN"
gh_base=https://api.github.com/repos/$gh_repo
release_opt=`jq -n --arg version v$version --arg changelog "$changelog" \
'{ tag_name: $version, name: $version, body: $changelog, draft:true }'`
gh_release=`curl -sf -H "$gh_auth" $gh_base/releases/tags/v$version \
|| curl -sf -H "$gh_auth" -d "$release_opt" $gh_base/releases`
gh_upload=`echo "$gh_release" | jq -r .upload_url | sed -e 's/{?name,label}//'`

for file in SHA256SUMS.asc dist/*; do
echo ">> Uploading $file"

curl -f --progress-bar -H "$gh_auth" -H "Content-Type: application/octet-stream" \
--data-binary @"$file" "$gh_upload?name=$(basename $file)" | (grep -v browser_download_url || true)
done

# make release public once everything is ready
curl -sf -H "$gh_auth" -X PATCH $gh_base/releases/`echo "$gh_release" | jq -r .id` \
-d '{"draft":false}' > /dev/null
fi

0 comments on commit b1c9c8d

Please sign in to comment.