1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gnugrep gnused jq nix-prefetch
6 ETCD_PATH
="$(dirname "$0")"
7 ETCD_VERSION_MAJOR_MINOR
="$(basename $ETCD_PATH)"
8 ETCD_PKG_NAME
=etcd_$
(echo $ETCD_VERSION_MAJOR_MINOR |
sed 's/[.]/_/g')
9 NIXPKGS_PATH
="$(git rev-parse --show-toplevel)"
11 OLD_VERSION
="$(nix-instantiate --eval -E "with import
$NIXPKGS_PATH {}; \
12 $ETCD_PKG_NAME.version or
(builtins.parseDrvName
$ETCD_PKG_NAME.name
).version
" | tr -d '"')"
14 LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/etcd-io/etcd/releases \
15 | jq -r 'map
(.tag_name
)' | grep $ETCD_VERSION_MAJOR_MINOR | sed 's|
[", ]||g' | sort -rV | head -n1)
17 LATEST_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//')
19 if [ ! "$OLD_VERSION" = "$LATEST_VERSION" ]; then
20 echo "Attempting to update etcd from
$OLD_VERSION to
$LATEST_VERSION"
21 ETCD_SRC_HASH=$(nix-prefetch-url --quiet --unpack https://github.com/etcd-io/etcd/archive/refs/tags/${LATEST_TAG}.tar.gz)
22 ETCD_SRC_HASH=$(nix hash to-sri --type sha256 $ETCD_SRC_HASH)
25 sed -i "s|
$1 = \".
*\"|
$1 = \"${2:-}\"|
" "$ETCD_PATH/default.nix
"
28 setKV version $LATEST_VERSION
29 setKV etcdSrcHash $ETCD_SRC_HASH
31 getAndSetVendorHash () {
32 local EMPTY_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
=" # Hash from lib.fakeHash
33 local VENDOR_HASH=$EMPTY_HASH
37 setKV $PKG_KEY $EMPTY_HASH
40 VENDOR_HASH=$(nix-prefetch -I nixpkgs=$NIXPKGS_PATH "{ sha256
}: \
41 (import
$NIXPKGS_PATH/.
{}).
$ETCD_PKG_NAME.passthru.
$INNER_PKG.goModules.overrideAttrs
(_
: { vendorHash
= sha256
; })")
44 if [ -n "${VENDOR_HASH:-}" ]; then
45 setKV $PKG_KEY $VENDOR_HASH
47 echo "Update failed.
$PKG_KEY is empty.
"
52 getAndSetVendorHash etcdServerVendorHash etcdserver
53 getAndSetVendorHash etcdUtlVendorHash etcdutl
54 getAndSetVendorHash etcdCtlVendorHash etcdctl
56 # `git` flag here is to be used by local maintainers to speed up the bump process
57 if [ $# -eq 1 ] && [ "$1" = "git
" ]; then
58 git switch -c "package-
$ETCD_PKG_NAME-$LATEST_VERSION"
59 git add "$ETCD_PATH"/default.nix
60 git commit -m "$ETCD_PKG_NAME: $OLD_VERSION -> $LATEST_VERSION
62 Release
: https
://github.com
/etcd-io
/etcd
/releases
/tag
/v
$LATEST_VERSION"
66 echo "etcd is already up-to-date
at $OLD_VERSION"