Merge pull request #170782 from superherointj/package-fluxcd-update-script-improved-v1

This commit is contained in:
Sandro 2022-04-30 18:39:51 +02:00 committed by GitHub
commit ea6915669f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,36 +3,43 @@
set -x -eu -o pipefail
cd $(dirname "${BASH_SOURCE[0]}")
NIXPKGS_PATH="$(git rev-parse --show-toplevel)"
FLUXCD_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/fluxcd/flux2/releases/latest | jq -r '.tag_name')
OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_PATH {}; fluxcd.version or (builtins.parseDrvName fluxcd.name).version" | tr -d '"')"
LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/fluxcd/flux2/releases/latest | jq -r '.tag_name')
LATEST_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//')
VERSION=$(echo ${TAG} | sed 's/^v//')
if [ ! "$OLD_VERSION" = "$LATEST_VERSION" ]; then
SHA256=$(nix-prefetch-url --quiet --unpack https://github.com/fluxcd/flux2/archive/refs/tags/${LATEST_TAG}.tar.gz)
SPEC_SHA256=$(nix-prefetch-url --quiet --unpack https://github.com/fluxcd/flux2/releases/download/${LATEST_TAG}/manifests.tar.gz)
SHA256=$(nix-prefetch-url --quiet --unpack https://github.com/fluxcd/flux2/archive/refs/tags/${TAG}.tar.gz)
setKV () {
sed -i "s|$1 = \".*\"|$1 = \"${2:-}\"|" "${FLUXCD_PATH}/default.nix"
}
SPEC_SHA256=$(nix-prefetch-url --quiet --unpack https://github.com/fluxcd/flux2/releases/download/${TAG}/manifests.tar.gz)
setKV version ${LATEST_VERSION}
setKV sha256 ${SHA256}
setKV manifestsSha256 ${SPEC_SHA256}
setKV vendorSha256 "0000000000000000000000000000000000000000000000000000" # The same as lib.fakeSha256
setKV () {
sed -i "s|$1 = \".*\"|$1 = \"${2:-}\"|" ./default.nix
}
set +e
VENDOR_SHA256=$(nix-build --no-out-link -A fluxcd $NIXPKGS_PATH 2>&1 >/dev/null | grep "got:" | cut -d':' -f2 | sed 's| ||g')
set -e
setKV version ${VERSION}
setKV sha256 ${SHA256}
setKV manifestsSha256 ${SPEC_SHA256}
setKV vendorSha256 "0000000000000000000000000000000000000000000000000000" # The same as lib.fakeSha256
if [ -n "${VENDOR_SHA256:-}" ]; then
setKV vendorSha256 ${VENDOR_SHA256}
else
echo "Update failed. VENDOR_SHA256 is empty."
exit 1
fi
cd ../../../../../
set +e
VENDOR_SHA256=$(nix-build --no-out-link -A fluxcd 2>&1 >/dev/null | grep "got:" | cut -d':' -f2 | sed 's| ||g')
set -e
cd - > /dev/null
if [ -n "${VENDOR_SHA256:-}" ]; then
setKV vendorSha256 ${VENDOR_SHA256}
# `git` flag here is to be used by local maintainers to speed up the bump process
if [ "$1" = "git" ]; then
git switch -c "package-fluxcd-${LATEST_VERSION}"
git add "$FLUXCD_PATH"/default.nix
git commit -m "fluxcd: ${OLD_VERSION} -> ${LATEST_VERSION}"
fi
else
echo "Update failed. VENDOR_SHA256 is empty."
exit 1
echo "fluxcd is already up-to-date at $OLD_VERSION"
fi