Skip to content

Commit

Permalink
Merge #206: Add --dry-run option to push-release script
Browse files Browse the repository at this point in the history
dd78d2b Add --dry-run option to push-release script (Jonas Nick)

Pull request description:

ACKs for top commit:
  erikarvstedt:
    ACK dd78d2b
  nixbitcoin:
    utACK dd78d2b

Tree-SHA512: 75351d8b60899912cbd7a76a5f98b5c19044c15297c268a097d44a0e6bb540aca6a737066290c66cbf82cfae200e8a4b03988d18d2d5e80d3a54284723f80871
  • Loading branch information
jonasnick committed Sep 22, 2020
2 parents de1a734 + dd78d2b commit 6554e69
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions helper/push-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ set -euo pipefail
REPO=fort-nix/nix-bitcoin
BRANCH=master
OAUTH_TOKEN=$(pass show nix-bitcoin/github/oauth-token)
DRY_RUN=
TAG_NAME=

if [[ ! $OAUTH_TOKEN ]]; then
echo "Please set OAUTH_TOKEN variable"
fi

if [[ $# < 1 ]]; then
echo "$0 <tag_name>"
for arg in "$@"; do
case $arg in
--dry-run|-n)
DRY_RUN=1
;;
*)
TAG_NAME="$arg"
;;
esac
done

if [[ ! $TAG_NAME ]]; then
echo "$0 [--dry-run|-n] <tag_name>"
exit
fi
TAG_NAME=$1
if [[ $DRY_RUN ]]; then echo "Dry run"; fi

RESPONSE=$(curl https://api.github.com/repos/$REPO/releases/latest 2> /dev/null)
echo "Latest release" $(echo $RESPONSE | jq -r '.tag_name' | tail -c +2)
while true; do
read -p "Create release $1? [yn] " yn
read -p "Create release $TAG_NAME? [yn] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
Expand All @@ -27,7 +40,7 @@ while true; do
done

TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" EXIT
if [[ ! $DRY_RUN ]]; then trap "rm -rf $TMPDIR" EXIT; fi
ARCHIVE_NAME=nix-bitcoin-$TAG_NAME.tar.gz
ARCHIVE=$TMPDIR/$ARCHIVE_NAME

Expand All @@ -40,6 +53,11 @@ SHA256SUMS=$TMPDIR/SHA256SUMS.txt
(cd $TMPDIR; sha256sum $ARCHIVE_NAME > $SHA256SUMS)
gpg -o $SHA256SUMS.asc -a --detach-sig $SHA256SUMS

if [[ $DRY_RUN ]]; then
echo "Created v$TAG_NAME in $TMPDIR"
exit 0
fi

POST_DATA="{ \"tag_name\": \"v$TAG_NAME\", \"name\": \"nix-bitcoin-$TAG_NAME\", \"body\": \"nix-bitcoin-$TAG_NAME\", \"target_comitish\": \"$BRANCH\" }"
RESPONSE=$(curl -H "Authorization: token $OAUTH_TOKEN" -d "$POST_DATA" https://api.github.com/repos/$REPO/releases 2> /dev/null)
ID=$(echo $RESPONSE | jq -r '.id')
Expand All @@ -50,8 +68,8 @@ fi

post_asset() {
GH_ASSET="https://uploads.github.com/repos/$REPO/releases/$ID/assets?name="
curl -H "Authorization: token $OAUTH_TOKEN" --data-binary "@$1" -H "Content-Type: application/octet-stream" \
$GH_ASSET/$(basename $1) &> /dev/null
curl -H "Authorization: token $OAUTH_TOKEN" --data-binary "@$TAG_NAME" -H "Content-Type: application/octet-stream" \
$GH_ASSET/$(basename $TAG_NAME) &> /dev/null
}
post_asset $ARCHIVE
post_asset $SHA256SUMS
Expand Down

0 comments on commit 6554e69

Please sign in to comment.