native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Harden fork release script with origin repo detection and fallback

onevcat 058177e5 022bb87e

+58 -5
+3
doc-onevcat/fork-sync-and-release.md
··· 72 72 73 73 - Sync helper: `doc-onevcat/scripts/sync-upstream-main.sh` 74 74 - Release helper: `doc-onevcat/scripts/release-to-fork.sh` 75 + - Default target repo: auto-detected from `origin` 76 + - Override target repo: `GH_REPO=owner/repo` 77 + - Release create fallback: if `gh release create` fails (for example token scope mismatch), script falls back to `gh api` and then uploads assets 75 78 76 79 ### Example 77 80
+55 -5
doc-onevcat/scripts/release-to-fork.sh
··· 11 11 exit 1 12 12 fi 13 13 14 - REPO="$(gh repo view --json nameWithOwner -q .nameWithOwner)" 14 + origin_repo_from_remote() { 15 + local remote_url 16 + remote_url="$(git remote get-url origin 2>/dev/null || true)" 17 + if [[ -z "${remote_url}" ]]; then 18 + return 1 19 + fi 20 + 21 + # Supports: 22 + # - git@github.com:owner/repo.git 23 + # - ssh://git@github.com/owner/repo.git 24 + # - https://github.com/owner/repo.git 25 + local repo 26 + repo="$(echo "${remote_url}" | sed -E 's#^(git@github.com:|ssh://git@github.com/|https://github.com/)##; s#\.git$##')" 27 + if [[ "${repo}" == */* ]]; then 28 + echo "${repo}" 29 + return 0 30 + fi 31 + return 1 32 + } 33 + 34 + REPO="${GH_REPO:-$(origin_repo_from_remote || true)}" 35 + if [[ -z "${REPO}" ]]; then 36 + REPO="$(gh repo view --json nameWithOwner -q .nameWithOwner)" 37 + fi 38 + 15 39 SHORT_SHA="$(git rev-parse --short HEAD)" 16 40 DEFAULT_TAG="onevcat-v$(date +%Y.%m.%d)-${SHORT_SHA}" 17 41 TAG="${1:-$DEFAULT_TAG}" ··· 60 84 git push origin "${TAG}" 61 85 62 86 echo "[release] create GitHub Release and upload asset" 63 - gh release create "${TAG}" "${ZIP_PATH}" \ 64 - --repo "${REPO}" \ 65 - --title "Personal build ${TAG}" \ 66 - --notes-file "${NOTES_PATH}" 87 + if gh release view "${TAG}" --repo "${REPO}" >/dev/null 2>&1; then 88 + echo "[release] release already exists, upload asset with --clobber" 89 + gh release upload "${TAG}" "${ZIP_PATH}" --clobber --repo "${REPO}" 90 + else 91 + CREATE_ERR="$(mktemp)" 92 + if gh release create "${TAG}" "${ZIP_PATH}" \ 93 + --repo "${REPO}" \ 94 + --title "Personal build ${TAG}" \ 95 + --notes-file "${NOTES_PATH}" \ 96 + 2>"${CREATE_ERR}" 97 + then 98 + rm -f "${CREATE_ERR}" 99 + else 100 + echo "[release] gh release create failed, fallback to gh api + upload" 101 + cat "${CREATE_ERR}" 102 + rm -f "${CREATE_ERR}" 103 + 104 + if ! gh release view "${TAG}" --repo "${REPO}" >/dev/null 2>&1; then 105 + RELEASE_NOTES="$(cat "${NOTES_PATH}")" 106 + PAYLOAD="$(jq -n \ 107 + --arg tag "${TAG}" \ 108 + --arg name "Personal build ${TAG}" \ 109 + --arg body "${RELEASE_NOTES}" \ 110 + '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" 111 + gh api -X POST "repos/${REPO}/releases" --input - <<<"${PAYLOAD}" >/dev/null 112 + fi 113 + 114 + gh release upload "${TAG}" "${ZIP_PATH}" --clobber --repo "${REPO}" 115 + fi 116 + fi 67 117 68 118 echo 69 119 echo "[done] release created: https://github.com/${REPO}/releases/tag/${TAG}"