upload-release-assets.sh
.github/scripts/upload-release-assets.sh
1#!/usr/bin/env bash2set -euo pipefail3: "${RELEASE_TAG:?Missing release tag}"4: "${GH_REPO:?Missing GitHub repository}"5[[ $# -gt 0 ]] || { echo 'No release assets provided.' >&2; exit 2; }6assets=$(gh release view "$RELEASE_TAG" --repo "$GH_REPO" --json assets --jq '.assets[].name')7for file in "$@"; do8 [[ -s "$file" ]] || { echo "Release asset missing or empty: $file" >&2; exit 2; }9 name=$(basename "$file")10 args=(--repo "$GH_REPO")11 if [[ "${REBUILD_EXISTING:-false}" == true ]]; then12 args+=(--clobber)13 elif printf '%s\n' "$assets" | grep -Fxq "$name"; then14 echo "Already published: $name"15 continue16 fi17 gh release upload "$RELEASE_TAG" "$file" "${args[@]}"18done19