11name : Buildroot release cache
22description : |
33 Restore/save buildroot.tar.zst as a GitHub Release asset on the current
4- repository. Used in place of actions/cache. Tag pattern: cache-YYYY-WW (ISO week). Releases are
4+ repository. Used in place of actions/cache when the asset is too big for
5+ the 10 GB GHA cache. Tag pattern: cache-YYYY-WW (ISO week). Releases are
56 marked prerelease so they don't appear as "Latest".
67
78inputs :
5354 curl -fsSL "https://github.com/${REPO}/releases/download/${tag}/${asset}" -o "$LOCAL_FILE" 2>/dev/null
5455 }
5556
57+ api() {
58+ curl -sSL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$@"
59+ }
60+
5661 case "$MODE" in
5762 restore)
5863 if public_dl "$EXACT_TAG" "$EXACT_ASSET"; then
@@ -68,20 +73,28 @@ runs:
6873 fi
6974 ;;
7075 save)
71- gh release view "$EXACT_TAG" --repo "$REPO" >/dev/null 2>&1 || \
72- gh release create "$EXACT_TAG" \
73- --repo "$REPO" \
74- --prerelease \
75- --title "[cache] $EXACT_TAG" \
76- --notes "Buildroot caches for ISO week ${EXACT_WEEK}." \
77- >/dev/null 2>&1 || true
76+ api -X POST "https://api.github.com/repos/${REPO}/releases" \
77+ -d "$(jq -nc --arg tag "$EXACT_TAG" --arg name "[cache] $EXACT_TAG" --arg body "Buildroot caches for ISO week ${EXACT_WEEK}." \
78+ '{tag_name:$tag, name:$name, body:$body, prerelease:true}')" \
79+ >/dev/null 2>&1 || true
80+ rel_id=$(api "https://api.github.com/repos/${REPO}/releases/tags/${EXACT_TAG}" | jq -r '.id // empty')
81+ if [ -z "$rel_id" ]; then
82+ echo "::error::could not resolve release id for ${EXACT_TAG}"
83+ exit 1
84+ fi
7885
79- staged="$(mktemp -d)/${EXACT_ASSET}"
80- ln -s "$(realpath "$LOCAL_FILE")" "$staged"
81- gh release upload "$EXACT_TAG" "$staged" \
82- --repo "$ REPO" \
83- --clobber
86+ existing=$(api "https://api.github.com/repos/${REPO}/releases/${rel_id}/assets" \
87+ | jq -r --arg n "$EXACT_ASSET" '.[] | select(.name == $n) | .id' | head -1)
88+ if [ -n "$existing" ]; then
89+ api -X DELETE "https://api.github.com/repos/${ REPO}/releases/assets/${existing}" >/dev/null
90+ fi
8491
92+ curl -fsSL -X POST \
93+ -H "Authorization: Bearer $GH_TOKEN" \
94+ -H "Content-Type: application/octet-stream" \
95+ -T "$LOCAL_FILE" \
96+ "https://uploads.github.com/repos/${REPO}/releases/${rel_id}/assets?name=${EXACT_ASSET}" \
97+ >/dev/null
8598 echo "Uploaded ${EXACT_TAG}/${EXACT_ASSET}"
8699 ;;
87100 *)
0 commit comments