Skip to content

Commit f2dd103

Browse files
authored
Refactor release asset handling with GitHub CLI
Removed unused API function and replaced asset management with GitHub CLI commands for release creation and asset upload.
1 parent 64fed67 commit f2dd103

1 file changed

Lines changed: 13 additions & 29 deletions

File tree

.github/actions/buildroot-cache/action.yml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Buildroot release cache
22
description: |
33
Restore/save buildroot.tar.zst as a GitHub Release asset on the current
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
4+
repository. Used in place of actions/cache. Tag pattern: cache-YYYY-WW (ISO week). Releases are
65
marked prerelease so they don't appear as "Latest".
76
87
inputs:
@@ -54,10 +53,6 @@ runs:
5453
curl -fsSL "https://github.com/${REPO}/releases/download/${tag}/${asset}" -o "$LOCAL_FILE" 2>/dev/null
5554
}
5655
57-
api() {
58-
curl -sSL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$@"
59-
}
60-
6156
case "$MODE" in
6257
restore)
6358
if public_dl "$EXACT_TAG" "$EXACT_ASSET"; then
@@ -73,31 +68,20 @@ runs:
7368
fi
7469
;;
7570
save)
76-
# Ensure release exists; ignore 422-already-exists from concurrent siblings.
77-
api -X POST "https://api.github.com/repos/${REPO}/releases" \
78-
-d "$(jq -nc --arg tag "$EXACT_TAG" --arg name "[cache] $EXACT_TAG" --arg body "Buildroot caches for ISO week ${EXACT_WEEK}." \
79-
'{tag_name:$tag, name:$name, body:$body, prerelease:true}')" \
80-
>/dev/null 2>&1 || true
81-
rel_id=$(api "https://api.github.com/repos/${REPO}/releases/tags/${EXACT_TAG}" | jq -r '.id // empty')
82-
if [ -z "$rel_id" ]; then
83-
echo "::error::could not resolve release id for ${EXACT_TAG}"
84-
exit 1
85-
fi
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
8678
87-
# Clobber: delete existing asset of the same name.
88-
existing=$(api "https://api.github.com/repos/${REPO}/releases/${rel_id}/assets" \
89-
| jq -r --arg n "$EXACT_ASSET" '.[] | select(.name == $n) | .id' | head -1)
90-
if [ -n "$existing" ]; then
91-
api -X DELETE "https://api.github.com/repos/${REPO}/releases/assets/${existing}" >/dev/null
92-
fi
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
9384
94-
# Upload.
95-
curl -fsSL -X POST \
96-
-H "Authorization: Bearer $GH_TOKEN" \
97-
-H "Content-Type: application/octet-stream" \
98-
--data-binary "@${LOCAL_FILE}" \
99-
"https://uploads.github.com/repos/${REPO}/releases/${rel_id}/assets?name=${EXACT_ASSET}" \
100-
>/dev/null
10185
echo "Uploaded ${EXACT_TAG}/${EXACT_ASSET}"
10286
;;
10387
*)

0 commit comments

Comments
 (0)