@@ -4,36 +4,32 @@ set -euo pipefail
44DB=" ${1:? Usage: $0 <db-file>} "
55REPO=" idank/explainshell"
66RELEASE=" db-latest"
7- ASSET= " explainshell.db.zst "
8- CDN_URL= " https://github.com/ $REPO /releases/download/ $RELEASE / $ASSET "
7+ DATE= $( date -u +%Y-%m-%d-%H%M%S )
8+ ASSET= " explainshell- ${DATE} .db.zst "
99
1010test -f " $DB " || { echo " $DB not found" ; exit 1; }
1111
12- # --- Compress and check if upload is needed ---
12+ # --- Compress ---
1313zstd -1 -f " $DB " -o " $ASSET "
14- local_sha=$( sha256sum " $ASSET " | awk ' {print $1}' )
15- remote_sha=$( gh api " repos/$REPO /releases/tags/$RELEASE " \
16- --jq " .assets[] | select(.name == \" $ASSET \" ) | .digest" 2> /dev/null \
17- | sed ' s/^sha256://' )
18-
19- if [ " $local_sha " = " $remote_sha " ]; then
20- echo " Local DB digest ($local_sha ) matches release. Nothing to upload."
21- rm -f " $ASSET "
22- exit 0
23- fi
2414
25- echo " Local digest: $local_sha "
26- echo " Release digest: ${remote_sha:- <none>} "
27-
28- # --- Archive existing asset ---
29- asset_id=$( gh api " repos/$REPO /releases/tags/$RELEASE " --jq " .assets[] | select(.name == \" $ASSET \" ) | .id" )
30- if [ -n " $asset_id " ]; then
31- upload_date=$( gh api " repos/$REPO /releases/tags/$RELEASE " \
32- --jq " .assets[] | select(.name == \" $ASSET \" ) | .updated_at" \
33- | tr -d ' Z' | tr ' T:' ' -' )
34- archive_name=" explainshell-${upload_date} .db.zst"
35- echo " Renaming existing asset to $archive_name ..."
36- gh api " repos/$REPO /releases/assets/$asset_id " -X PATCH -f name=" $archive_name " --silent
15+ # --- Check if upload is needed by comparing to the newest existing asset ---
16+ newest_asset=$( gh api " repos/$REPO /releases/tags/$RELEASE " \
17+ --jq ' [.assets[] | select(.name | test("^explainshell-.*\\.db\\.zst$"))] | sort_by(.created_at) | last | .name' 2> /dev/null || true)
18+
19+ if [ -n " $newest_asset " ]; then
20+ remote_sha=$( gh api " repos/$REPO /releases/tags/$RELEASE " \
21+ --jq " .assets[] | select(.name == \" $newest_asset \" ) | .digest" 2> /dev/null \
22+ | sed ' s/^sha256://' )
23+ local_sha=$( sha256sum " $ASSET " | awk ' {print $1}' )
24+
25+ if [ " $local_sha " = " $remote_sha " ]; then
26+ echo " Local DB digest ($local_sha ) matches latest release asset ($newest_asset ). Nothing to upload."
27+ rm -f " $ASSET "
28+ exit 0
29+ fi
30+
31+ echo " Local digest: $local_sha "
32+ echo " Latest asset: $newest_asset (digest: ${remote_sha:- <none>} )"
3733fi
3834
3935# --- Upload ---
@@ -47,17 +43,5 @@ curl --progress-bar \
4743 --data-binary @" $ASSET " \
4844 " ${upload_url} ?name=$ASSET " | cat
4945
50- # --- Wait for CDN ---
51- expected_size=$( wc -c < " $ASSET " )
5246rm -f " $ASSET "
53-
54- echo " Waiting for CDN to serve the new file ($expected_size bytes)..."
55- while true ; do
56- cdn_size=$( curl -sI -L " $CDN_URL " | grep -i content-length | tail -1 | tr -d ' [:space:]' | cut -d: -f2)
57- if [ " $cdn_size " = " $expected_size " ]; then
58- echo " CDN updated."
59- break
60- fi
61- echo " CDN still serving $cdn_size bytes, expected $expected_size . Retrying in 10s..."
62- sleep 10
63- done
47+ echo " Uploaded $ASSET to release $RELEASE ."
0 commit comments