2020-03-25 00:09:34 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
REPO=fort-nix/nix-bitcoin
|
|
|
|
BRANCH=master
|
2022-05-06 17:45:00 +03:00
|
|
|
GIT_REMOTE=origin
|
2021-09-08 18:01:16 +03:00
|
|
|
OAUTH_TOKEN=
|
2020-07-08 13:14:38 +03:00
|
|
|
DRY_RUN=
|
2023-07-08 16:33:05 +03:00
|
|
|
releaseVersion=
|
2020-03-25 00:09:34 +03:00
|
|
|
|
2022-05-17 14:18:37 +03:00
|
|
|
trap 'echo "Error at ${BASH_SOURCE[0]}:$LINENO"' ERR
|
|
|
|
|
2023-07-08 16:33:07 +03:00
|
|
|
cd "${BASH_SOURCE[0]%/*}"
|
|
|
|
|
2020-07-08 13:14:38 +03:00
|
|
|
for arg in "$@"; do
|
|
|
|
case $arg in
|
|
|
|
--dry-run|-n)
|
|
|
|
DRY_RUN=1
|
|
|
|
;;
|
|
|
|
*)
|
2023-07-08 16:33:05 +03:00
|
|
|
releaseVersion="$arg"
|
2020-07-08 13:14:38 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-07-08 16:33:07 +03:00
|
|
|
latestVersion=$(curl -fsS https://api.github.com/repos/$REPO/releases/latest | jq -r '.tag_name' | tail -c +2)
|
|
|
|
|
2023-07-08 16:33:05 +03:00
|
|
|
if [[ ! $releaseVersion ]]; then
|
2023-07-08 16:33:07 +03:00
|
|
|
# Increment the lowest/last part of `latestVersion`
|
|
|
|
releaseVersion=$(echo "$latestVersion" | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.)
|
2020-03-25 00:09:34 +03:00
|
|
|
fi
|
2023-07-08 16:33:07 +03:00
|
|
|
|
2021-09-08 18:01:16 +03:00
|
|
|
if [[ $DRY_RUN ]]; then
|
|
|
|
echo "Dry run"
|
|
|
|
else
|
|
|
|
OAUTH_TOKEN=$(pass show nix-bitcoin/github/oauth-token)
|
|
|
|
if [[ ! $OAUTH_TOKEN ]]; then
|
2023-07-08 16:33:08 +03:00
|
|
|
echo "Error fetching OAUTH_TOKEN"
|
|
|
|
exit 1
|
2021-09-08 18:01:16 +03:00
|
|
|
fi
|
|
|
|
fi
|
2020-03-25 00:09:34 +03:00
|
|
|
|
2023-07-08 16:33:07 +03:00
|
|
|
echo "Latest release: $latestVersion"
|
2021-09-08 18:01:16 +03:00
|
|
|
|
|
|
|
if [[ ! $DRY_RUN ]]; then
|
|
|
|
while true; do
|
2023-07-08 16:33:05 +03:00
|
|
|
read -rp "Create release ${releaseVersion}? [yn] " yn
|
2021-09-08 18:01:16 +03:00
|
|
|
case $yn in
|
|
|
|
[Yy]* ) break;;
|
|
|
|
[Nn]* ) exit;;
|
|
|
|
* ) echo "Please answer y or n.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
2020-03-25 00:09:34 +03:00
|
|
|
|
2023-07-08 16:33:09 +03:00
|
|
|
nixosVersion=$(sed -nE 's|.*system.stateVersion = "(.*?)".*|\1|p' ../examples/configuration.nix)
|
|
|
|
if [[ ! $nixosVersion ]]; then
|
|
|
|
echo "Error fetching NixOS version"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
nixosVersionBranch=nixos-$nixosVersion
|
|
|
|
|
2020-03-25 00:09:34 +03:00
|
|
|
TMPDIR=$(mktemp -d)
|
2022-08-16 22:00:00 +03:00
|
|
|
if [[ ! $DRY_RUN ]]; then trap 'rm -rf $TMPDIR' EXIT; fi
|
2023-07-08 16:33:05 +03:00
|
|
|
ARCHIVE_NAME=nix-bitcoin-$releaseVersion.tar.gz
|
2020-03-25 00:09:34 +03:00
|
|
|
ARCHIVE=$TMPDIR/$ARCHIVE_NAME
|
|
|
|
|
2022-05-17 14:18:37 +03:00
|
|
|
# Need to be in the repo root directory for archiving
|
2022-08-16 22:00:00 +03:00
|
|
|
(cd "$(git rev-parse --show-toplevel)"; git archive --format=tar.gz -o "$ARCHIVE" "$BRANCH")
|
2020-03-25 00:09:34 +03:00
|
|
|
|
|
|
|
SHA256SUMS=$TMPDIR/SHA256SUMS.txt
|
2022-05-17 14:18:37 +03:00
|
|
|
# Use relative path with sha256sums because it'll output the first
|
2020-03-25 00:09:34 +03:00
|
|
|
# argument
|
2022-08-16 22:00:00 +03:00
|
|
|
(cd "$TMPDIR"; sha256sum "$ARCHIVE_NAME" > "$SHA256SUMS")
|
|
|
|
gpg -o "$SHA256SUMS.asc" -a --detach-sig "$SHA256SUMS"
|
2020-03-25 00:09:34 +03:00
|
|
|
|
2022-08-16 22:00:00 +03:00
|
|
|
pushd "$TMPDIR" >/dev/null
|
2022-05-17 14:18:37 +03:00
|
|
|
|
2022-08-16 22:00:00 +03:00
|
|
|
nix hash to-sri --type sha256 "$(nix-prefetch-url --unpack "file://$ARCHIVE" 2> /dev/null)" > nar-hash.txt
|
2021-09-08 18:01:17 +03:00
|
|
|
gpg -o nar-hash.txt.asc -a --detach-sig nar-hash.txt
|
|
|
|
|
2020-07-08 13:14:38 +03:00
|
|
|
if [[ $DRY_RUN ]]; then
|
2023-07-08 16:33:05 +03:00
|
|
|
echo "Created v$releaseVersion in $TMPDIR"
|
2023-07-08 16:33:09 +03:00
|
|
|
echo "NixOS version branch: $nixosVersionBranch"
|
2020-07-08 13:14:38 +03:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-07-08 16:33:09 +03:00
|
|
|
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
|
|
|
|
# Create release
|
|
|
|
|
2023-07-08 16:33:05 +03:00
|
|
|
POST_DATA="{ \"tag_name\": \"v$releaseVersion\", \"name\": \"nix-bitcoin-$releaseVersion\", \"body\": \"nix-bitcoin-$releaseVersion\", \"target_comitish\": \"$BRANCH\" }"
|
2023-07-08 16:33:06 +03:00
|
|
|
RESPONSE=$(curl -fsS -H "Authorization: token $OAUTH_TOKEN" -d "$POST_DATA" https://api.github.com/repos/$REPO/releases)
|
2022-08-16 22:00:00 +03:00
|
|
|
ID=$(echo "$RESPONSE" | jq -r '.id')
|
2020-03-25 00:09:34 +03:00
|
|
|
if [[ $ID == null ]]; then
|
|
|
|
echo "Failed to create release with $POST_DATA"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
post_asset() {
|
|
|
|
GH_ASSET="https://uploads.github.com/repos/$REPO/releases/$ID/assets?name="
|
2023-07-08 16:33:06 +03:00
|
|
|
curl -fsS -H "Authorization: token $OAUTH_TOKEN" --data-binary "@$1" -H "Content-Type: application/octet-stream" \
|
|
|
|
"$GH_ASSET/$(basename "$1")"
|
2020-03-25 00:09:34 +03:00
|
|
|
}
|
2021-09-08 18:01:17 +03:00
|
|
|
post_asset nar-hash.txt
|
|
|
|
post_asset nar-hash.txt.asc
|
|
|
|
# Post additional assets for backwards compatibility.
|
|
|
|
# This allows older nix-bitcoin installations to upgrade via `fetch-release`.
|
2022-08-16 22:00:00 +03:00
|
|
|
post_asset "$ARCHIVE"
|
|
|
|
post_asset "$SHA256SUMS"
|
|
|
|
post_asset "$SHA256SUMS.asc"
|
2022-05-06 17:45:00 +03:00
|
|
|
|
2022-05-17 14:18:37 +03:00
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
if [[ ! $DRY_RUN ]]; then
|
2023-07-08 16:33:09 +03:00
|
|
|
git push "$GIT_REMOTE" "$BRANCH:release"
|
|
|
|
git push "$GIT_REMOTE" "$BRANCH:$nixosVersionBranch"
|
2022-05-17 14:18:37 +03:00
|
|
|
fi
|
2022-05-06 17:45:00 +03:00
|
|
|
|
2022-08-16 22:00:00 +03:00
|
|
|
echo "Successfully created" "$(echo "$POST_DATA" | jq -r .tag_name)"
|