1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gnused jq nix-prefetch
6 # provide a github token so you don't get rate limited
7 # if you use gh cli you can use:
8 # `export GITHUB_TOKEN="$(cat ~/.config/gh/config.yml | yq '.hosts."github.com".oauth_token' -r)"`
9 # or just set your token by hand:
10 # `read -s -p "Enter your token: " GITHUB_TOKEN; export GITHUB_TOKEN`
11 # (we use read so it doesn't show in our shell history and in secret mode so the token you paste isn't visible)
12 if [ -z "${GITHUB_TOKEN:-}" ]; then
13 echo "no GITHUB_TOKEN provided - you could meet API request limiting" >&2
16 ROOT
="$(dirname "$
(readlink
-f "$0")")"
17 NIXPKGS_ROOT
="$ROOT/../../../.."
19 COMMON_FILE
="$ROOT/common.nix"
22 nix-instantiate
-A "$1" --eval --strict | cut
-d\" -f2
28 "Accept: application/vnd.github.v3+json" \
29 ${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \
30 https
://api.github.com
/repos
/semgrep
/semgrep
/releases
/latest \
34 NEW_VERSION
="${NEW_VERSION:1}"
35 OLD_VERSION
="$(instantiateClean semgrep.passthru.common.version)"
37 if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then
38 echo "Already up to date"
43 sed -i "s@$1@$2@g" "$3"
48 nix-build
-A "$1" 2>&1 >/dev
/null |
grep "got:" | cut
-d':' -f2 |
sed 's| ||g'
55 nix-prefetch
"{ fetchPypi }:
58 version = \"$VERSION\";
61 python = \"cp38.cp39.cp310.cp311.py37.py38.py39.py310.py311\";
62 platform = \"$PLATFORM\";
67 replace
"$OLD_VERSION" "$NEW_VERSION" "$COMMON_FILE"
71 OLD_HASH
="$(instantiateClean semgrep.passthru.common.srcHash)"
72 echo "Old hash $OLD_HASH"
73 TMP_HASH
="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
74 replace
"$OLD_HASH" "$TMP_HASH" "$COMMON_FILE"
75 NEW_HASH
="$(fetchgithub semgrep.src)"
76 echo "New hash $NEW_HASH"
77 replace
"$TMP_HASH" "$NEW_HASH" "$COMMON_FILE"
82 update_core_platform
() {
84 echo "Updating core src $SYSTEM"
86 PLATFORM
="$(instantiateClean "semgrep.passthru.common.core.
$SYSTEM.platform
")"
88 OLD_HASH
="$(instantiateClean "semgrep.passthru.common.core.
$SYSTEM.
hash")"
89 echo "Old core hash $OLD_HASH"
90 NEW_HASH
="$(fetch_arch "$NEW_VERSION" "$PLATFORM")"
91 echo "New core hash $NEW_HASH"
92 replace
"$OLD_HASH" "$NEW_HASH" "$COMMON_FILE"
94 echo "Updated core src $SYSTEM"
97 update_core_platform
"x86_64-linux"
98 update_core_platform
"aarch64-linux"
99 update_core_platform
"x86_64-darwin"
100 update_core_platform
"aarch64-darwin"
103 TMPDIR
="$(mktemp -d)"
104 # shallow clone to check submodule commits, don't actually need the submodules
105 git clone https
://github.com
/semgrep
/semgrep
"$TMPDIR/semgrep" --depth 1 --branch "v$NEW_VERSION"
107 get_submodule_commit
() {
111 git ls-tree
--object-only HEAD
"$1"
116 # loop through submodules
117 nix-instantiate
-E "with import $NIXPKGS_ROOT {}; builtins.attrNames semgrep.passthru.common.submodules" --eval --strict --json \
119 |
while read -r SUBMODULE
; do
120 echo "Updating $SUBMODULE"
121 OLD_REV
=$
(instantiateClean semgrep.passthru.common.submodules.
"$SUBMODULE".
rev)
122 echo "Old commit $OLD_REV"
123 OLD_HASH
=$
(instantiateClean semgrep.passthru.common.submodules.
"$SUBMODULE".
hash)
124 echo "Old hash $OLD_HASH"
126 NEW_REV
=$
(get_submodule_commit
"$SUBMODULE")
127 echo "New commit $NEW_REV"
129 if [[ "$OLD_REV" == "$NEW_REV" ]]; then
130 echo "$SUBMODULE already up to date"
134 TMP_HASH
="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
135 replace
"$OLD_REV" "$NEW_REV" "$COMMON_FILE"
136 replace
"$OLD_HASH" "$TMP_HASH" "$COMMON_FILE"
137 NEW_HASH
="$(fetchgithub semgrep.passthru.submodulesSubset."$SUBMODULE")"
138 echo "New hash $NEW_HASH"
139 replace
"$TMP_HASH" "$NEW_HASH" "$COMMON_FILE"
141 echo "Updated $SUBMODULE"