forked from asciimoo/hister
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-nix-vendor-hash.sh
More file actions
executable file
·55 lines (41 loc) · 1.46 KB
/
Copy pathupdate-nix-vendor-hash.sh
File metadata and controls
executable file
·55 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -euo pipefail
PACKAGE_FILE="nix/package.nix"
update_hash() {
local output="$1"
local attempt="$2"
if echo "$output" | grep -q "hash mismatch in fixed-output derivation"; then
EXPECTED_HASH=$(echo "$output" | grep "specified:" | sed 's/.*specified: *//')
GOT_HASH=$(echo "$output" | grep "got:" | sed 's/.*got: *//')
echo "::notice::Attempt $attempt - Expected: $EXPECTED_HASH"
echo "::notice::Attempt $attempt - Got: $GOT_HASH"
if echo "$output" | grep -q "go-modules.drv"; then
echo "::notice::Updating vendorHash"
else
echo "::warning::Unknown hash mismatch, updating anyway"
fi
sed -i.bak "s|$EXPECTED_HASH|$GOT_HASH|g" "$PACKAGE_FILE"
rm -f "$PACKAGE_FILE.bak"
echo "updated"
fi
}
echo "::notice::Running nix build to check for hash mismatches..."
# Attempt 1: typically catches npmDepsHash or vendorHash mismatch
echo "::group::Build attempt 1"
OUTPUT=$(nix build .#hister 2>&1 || true)
echo "$OUTPUT"
echo "::endgroup::"
RESULT1=$(update_hash "$OUTPUT" "1")
# Attempt 2: catches the remaining hash if both changed
echo "::group::Build attempt 2"
OUTPUT=$(nix build .#hister 2>&1 || true)
echo "$OUTPUT"
echo "::endgroup::"
RESULT2=$(update_hash "$OUTPUT" "2")
if [ -n "$RESULT1" ] || [ -n "$RESULT2" ]; then
echo "::notice::Updated vendorHash"
fi
echo "::group::Verifying final build"
nix build .#hister 2>&1 | tail -5
echo "::endgroup::"
echo "::notice::Build successful!"