push-release.sh: improve --dry-run mode

- Don't require OAUTH_TOKEN
- Skip interactive query
This commit is contained in:
Erik Arvstedt 2021-09-08 17:01:16 +02:00
parent 82a2b148d8
commit 8a757e0486
No known key found for this signature in database
GPG Key ID: 33312B944DD97846

View File

@ -3,14 +3,10 @@ set -euo pipefail
REPO=fort-nix/nix-bitcoin REPO=fort-nix/nix-bitcoin
BRANCH=master BRANCH=master
OAUTH_TOKEN=$(pass show nix-bitcoin/github/oauth-token) OAUTH_TOKEN=
DRY_RUN= DRY_RUN=
TAG_NAME= TAG_NAME=
if [[ ! $OAUTH_TOKEN ]]; then
echo "Please set OAUTH_TOKEN variable"
fi
for arg in "$@"; do for arg in "$@"; do
case $arg in case $arg in
--dry-run|-n) --dry-run|-n)
@ -26,10 +22,19 @@ if [[ ! $TAG_NAME ]]; then
echo "$0 [--dry-run|-n] <tag_name>" echo "$0 [--dry-run|-n] <tag_name>"
exit exit
fi fi
if [[ $DRY_RUN ]]; then echo "Dry run"; fi if [[ $DRY_RUN ]]; then
echo "Dry run"
else
OAUTH_TOKEN=$(pass show nix-bitcoin/github/oauth-token)
if [[ ! $OAUTH_TOKEN ]]; then
echo "Please set OAUTH_TOKEN variable"
fi
fi
RESPONSE=$(curl https://api.github.com/repos/$REPO/releases/latest 2> /dev/null) 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) echo "Latest release" $(echo $RESPONSE | jq -r '.tag_name' | tail -c +2)
if [[ ! $DRY_RUN ]]; then
while true; do while true; do
read -p "Create release $TAG_NAME? [yn] " yn read -p "Create release $TAG_NAME? [yn] " yn
case $yn in case $yn in
@ -38,6 +43,7 @@ while true; do
* ) echo "Please answer y or n.";; * ) echo "Please answer y or n.";;
esac esac
done done
fi
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
if [[ ! $DRY_RUN ]]; then trap "rm -rf $TMPDIR" EXIT; fi if [[ ! $DRY_RUN ]]; then trap "rm -rf $TMPDIR" EXIT; fi