forked from ajaxbits/nixos-caddy-patched
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.sh
executable file
·94 lines (72 loc) · 2.52 KB
/
update.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env -S nix develop .#update -c bash
COMMIT="$1"
ROOT_DIR="$(pwd)"
git_push() {
if [[ "$COMMIT" == "--commit" ]]; then
(
cd "$ROOT_DIR" || return
git config --global user.name 'Updater'
git config --global user.email '[email protected]'
git remote update
alejandra .
git add .
git commit -m "$1"
git push
)
else
echo "$1"
fi
}
sanitizeCfVer() {
IFS='-' read -r -a split_version <<< "$1"
echo "${split_version[0]}+${split_version[2]}"
}
updateInfo() {
version=$(sed -n 's#.*github.com/caddyserver/caddy/v2 \(.*\)#\1#p' "$ROOT_DIR/src/go.mod")
sane_version="${version:1}"
cf_version=$(sed -n 's#.*github.com/caddy-dns/cloudflare \(.*\)#\1#p' "$ROOT_DIR/src/go.mod")
sane_cf_version=$(sanitizeCfVer "${cf_version:1}")
dist_hash=$(nix-prefetch-github caddyserver dist --rev "$version" | jq -r .hash)
{
echo '# This file was autogenerated. DO NOT EDIT!'
echo '{'
echo " version = \"$sane_version\";"
echo " cfVersion = \"$sane_cf_version\";"
echo " vendorHash = \"$1\";"
echo " dist = {"
echo " owner = \"caddyserver\";"
echo " repo = \"dist\";"
echo " rev = \"$version\";"
echo " hash = \"$dist_hash\";"
echo " };"
echo '}'
} >"$ROOT_DIR/pkgs/info.nix"
}
updateGoSources() {
current_version=$(nix eval --json --file "$ROOT_DIR/pkgs/info.nix" | jq -r .version)
current_cf=$(nix eval --json --file "$ROOT_DIR/pkgs/info.nix" | jq -r .cfVersion)
cd ./src || return
old_hash="$(sha256sum ./go.sum)"
rm go*
go mod init caddy
go mod tidy
new_hash="$(sha256sum ./go.sum)"
if [ "$old_hash" != "$new_hash" ]; then
nix flake update
updateInfo ""
new_vendor_hash="$(nix build "$ROOT_DIR"/.# |& sed -n 's/.*got: *//p')"
updateInfo "$new_vendor_hash"
new_version=$(nix eval --json --file "$ROOT_DIR/pkgs/info.nix" | jq -r .version)
new_cf=$(nix eval --json --file "$ROOT_DIR/pkgs/info.nix" | jq -r .cfVersion)
commit_msg="ci: "
if [[ "$current_version" != "$new_version" ]]; then
commit_msg+="caddy $current_version -> $new_version"
elif [[ "$current_cf" != "$new_cf" ]]; then
commit_msg+="cloudflare-plugin $current_cf -> $new_cf"
else
commit_msg+="bump deps"
fi
git_push "$commit_msg"
fi
}
updateGoSources