nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p jq nix
3
4set -euo pipefail
5echoerr() { echo "$@" 1>&2; }
6
7fetchgithub() {
8 set +eo pipefail
9 nix-build -A "$1" 2>&1 >/dev/null | grep "got:" | cut -d':' -f2 | sed 's| ||g'
10 set -eo pipefail
11}
12
13fname="$1"
14echoerr "Working on $fname"
15shift
16
17# Fetch latest tags from the repo, leave only stable and lts, use version sort in reverse order.
18all_tags=$(curl -L -s ${GITHUB_TOKEN:+-u ":${GITHUB_TOKEN}"} https://api.github.com/repos/ClickHouse/ClickHouse/tags \
19 | jq -r '.[].name | select(test("-(stable|lts)$"))' \
20 | sort -Vr)
21
22# Fail if no tags found
23if [[ -z "$all_tags" ]]; then
24 echoerr "Error: no suitable tag found in ClickHouse repo"
25 exit 1
26fi
27
28pname="clickhouse"
29if [[ "$fname" == *lts.nix ]]; then
30 all_tags=$(echo "$all_tags" | grep -- "-lts$")
31 pname="clickhouse-lts"
32fi
33
34latest_tag=$(echo "$all_tags" | head -n1)
35version=${latest_tag##v}
36
37# Do nothing if latest version is already there.
38if grep -q "version = \"$version\"" "$fname"; then
39 echoerr "Version $version is already the latest in $fname"
40 exit 0
41fi
42
43echoerr "Latest tag for $fname: $latest_tag (version $version)"
44
45# Get the annotated tag commit SHA.
46rev=$(curl -L -s ${GITHUB_TOKEN:+-u ":${GITHUB_TOKEN}"} "https://api.github.com/repos/clickhouse/clickhouse/git/ref/tags/$latest_tag" \
47 | jq -r '.object.sha')
48rev=$(curl -L -s ${GITHUB_TOKEN:+-u ":${GITHUB_TOKEN}"} "https://api.github.com/repos/clickhouse/clickhouse/git/tags/$rev" \
49 | jq -r '.object.sha')
50echoerr "Resolved commit hash for tag $latest_tag: $rev"
51
52# Update version.
53sed -i -E "s@(version = \").*(\";)@\1$version\2@" "$fname"
54grep -q "$version" "$fname"
55
56# Update Git hash.
57sed -i -E "s@(rev = \").*(\";)@\1$rev\2@" "$fname"
58grep -q "$rev" "$fname"
59
60# Update source hash.
61# First, put lib.fakeHash value.
62tmp_src_hash="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
63sed -i -E "s@(hash = \").*(\";)@\1$tmp_src_hash\2@" "$fname"
64grep -q "$tmp_src_hash" "$fname"
65
66# Next, we need to run actual build due to presence of postFetch script.
67echoerr "Running fetchFromGitHub on $pname to get new sources hash"
68
69src_hash=$(fetchgithub "$pname.src")
70if [[ -z "$src_hash" ]]; then
71 echoerr "Error: failed to get source hash from nix-build"
72 exit 1
73fi
74
75# Finally, update the source hash.
76echoerr "New src hash: $src_hash"
77sed -i -E "s@(hash = \").*(\";)@\1$src_hash\2@" "$fname"
78grep -q "$src_hash" "$fname"