{"id":235,"date":"2025-02-27T20:34:23","date_gmt":"2025-02-27T12:34:23","guid":{"rendered":"https:\/\/feiyangblog.eu.org\/?p=235"},"modified":"2025-11-05T15:30:07","modified_gmt":"2025-11-05T07:30:07","slug":"%e5%ae%9d%e5%a1%94%e9%9d%a2%e6%9d%bf%e5%ae%9a%e6%97%b6%e6%8b%89%e5%8f%96github-releases%e7%89%88%e6%9c%ac%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/feiyangblog.eu.org\/?p=235","title":{"rendered":"\u5b9d\u5854\u9762\u677f\u5b9a\u65f6\u62c9\u53d6github releases\u7248\u672c\u6587\u4ef6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u4e00\u3001\u670d\u52a1\u5668\u5b89\u88c5 GH<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install gh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e8c\u3001\u811a\u672c\u6587\u4ef6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Telegram Bot \u8bbe\u7f6e\uff08\u5199\u6b7b\u5728\u4ee3\u7801\u4e2d\uff09\nTG_API_TOKEN=\"Bot API Token\"  # \u66ff\u6362\u4e3a\u4f60\u521b\u5efa\u7684 Bot API Token\nTG_USER_ID=\"Telegram \u7528\u6237 ID\"          # \u66ff\u6362\u4e3a\u4f60\u7684 Telegram \u7528\u6237 ID\n\n# GitHub Token \u8bbe\u7f6e\uff08\u5199\u6b7b\u5728\u4ee3\u7801\u4e2d\uff09\nGH_TOKEN=\"GitHub API Token\"  # \u66ff\u6362\u4e3a\u4f60\u7684 GitHub API Token\n\n# \u5c06 GitHub Token \u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u4fbf gh CLI \u4f7f\u7528\nexport GH_TOKEN\n\nREPO=\"$REPO\"\nLOCAL_DIR=\"$LOCAL_DIR\"\nTAG=\"$TAG\"\n\n# ========= \u5de5\u5177\u51fd\u6570 =========\nsend_telegram_message() {\n    local message=\"$1\"\n    curl -s -X POST \"https:\/\/api.telegram.org\/bot$TG_API_TOKEN\/sendMessage\" \\\n        -d chat_id=\"$TG_USER_ID\" \\\n        -d text=\"$message\"\n}\n\nmkdir -p \"$LOCAL_DIR\"\n\n# \u83b7\u53d6\u672c\u5730\u7248\u672c\nif &#91; -f \"$LOCAL_DIR\/version.txt\" ]; then\n    LOCAL_VERSION=$(cat \"$LOCAL_DIR\/version.txt\")\nelse\n    LOCAL_VERSION=\"v0.0.0\"\nfi\n\nSTATUS=\"\"\nUPDATED_FOLDERS=\"\"\n\n# ========= \u83b7\u53d6\u6700\u65b0\u7248\u672c =========\nif &#91; -n \"$TAG\" ]; then\n    LATEST_VERSION=\"$TAG\"\n    STATUS+=\"\u4f7f\u7528\u6307\u5b9a\u7684\u7248\u672c: $TAG%0A\"\nelse\n    LATEST_VERSION=$(gh release list --repo \"$REPO\" --json tagName,isPrerelease,isDraft,publishedAt \\\n      --jq '&#91;.&#91;] | select(.isPrerelease == false and .isDraft == false)] | sort_by(.publishedAt) | reverse | .&#91;0].tagName')\n\n    if &#91; -z \"$LATEST_VERSION\" ]; then\n        # \u82e5\u6ca1\u6709 Release\uff0c\u5c1d\u8bd5\u83b7\u53d6 tags\n        LATEST_VERSION=$(gh api -H \"Accept: application\/vnd.github+json\" \/repos\/$REPO\/tags \\\n          | jq -r '.&#91;0].name')\n        STATUS+=\"\u672a\u53d1\u73b0\u6b63\u5f0f Release\uff0c\u4f7f\u7528\u6700\u65b0 tag: $LATEST_VERSION%0A\"\n    else\n        STATUS+=\"\u4f7f\u7528\u6700\u65b0 Release: $LATEST_VERSION%0A\"\n    fi\nfi\n\n# ========= \u5224\u65ad\u7248\u672c\u662f\u5426\u9700\u66f4\u65b0 =========\nif &#91; \"$LATEST_VERSION\" != \"$LOCAL_VERSION\" ]; then\n    STATUS+=\"\u53d1\u73b0\u65b0\u7248\u672c: $LATEST_VERSION\uff08\u5f53\u524d: $LOCAL_VERSION\uff09%0A\u5f00\u59cb\u4e0b\u8f7d...\\n\"\n    rm -rf \"$LOCAL_DIR\"\/*\n    \n    # \u4e0b\u8f7d\u65b0\u7248\u672c\n    gh release download \"$LATEST_VERSION\" --repo \"$REPO\" --dir \"$LOCAL_DIR\" 2&gt;\/dev\/null || {\n        # fallback\uff1a\u5c1d\u8bd5\u76f4\u63a5\u4e0b\u8f7d tag zip \u5305\n        curl -L -o \"$LOCAL_DIR\/$LATEST_VERSION.zip\" \"https:\/\/github.com\/$REPO\/archive\/refs\/tags\/$LATEST_VERSION.zip\"\n        unzip -q \"$LOCAL_DIR\/$LATEST_VERSION.zip\" -d \"$LOCAL_DIR\"\n        rm \"$LOCAL_DIR\/$LATEST_VERSION.zip\"\n    }\n\n    # \u6e05\u7406\u65e0\u7528\u6587\u4ef6\n    find \"$LOCAL_DIR\" -type f \\( -name \"*.yml\" -o -name \"*.sha256\" -o -name \"*.json\" \\) -delete\n\n    # \u66f4\u65b0\u7248\u672c\u53f7\n    echo \"$LATEST_VERSION\" &gt; \"$LOCAL_DIR\/version.txt\"\n    STATUS+=\"\u66f4\u65b0\u5b8c\u6210: $LATEST_VERSION%0A\"\nelse\n    STATUS+=\"\u5f53\u524d\u7248\u672c $LOCAL_VERSION \u5df2\u662f\u6700\u65b0\uff0c\u65e0\u9700\u66f4\u65b0\u3002%0A\"\nfi\n\n# ========= \u83b7\u53d6\u6587\u4ef6\u5939\u7ed3\u6784 =========\nUPDATED_FOLDERS=$(find \"$LOCAL_DIR\" -type d | sed 's\/^\/\ud83d\udcc1 \/')\n\n# ========= \u6d88\u606f\u7ec4\u5408 =========\nFINAL_MESSAGE=\"$REPO \u66f4\u65b0\u72b6\u6001\uff1a%0A$STATUS\"\nif &#91; -n \"$UPDATED_FOLDERS\" ]; then\n    FINAL_MESSAGE+=\"\u6587\u4ef6\u5939\u5217\u8868\uff1a%0A$UPDATED_FOLDERS\"\nfi\n\n# ========= \u63a8\u9001 =========\nsend_telegram_message \"$FINAL_MESSAGE\"\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e09\u3001\u5b9a\u65f6\u4efb\u52a1\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8bbe\u7f6e GitHub \u4ed3\u5e93\u7684\u540d\u79f0\uff0c\u683c\u5f0f\u4e3a 'username\/repository'\uff0c\u8fd9\u91cc\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539\nexport REPO=\"MetaCubeX\/ClashMetaForAndroid\"\n# \u8bbe\u7f6e\u672c\u5730\u5b58\u50a8\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u8def\u5f84\uff0c\u7528\u4e8e\u4e0b\u8f7d\u5e76\u5b58\u50a8\u6700\u65b0\u7684 release \u6587\u4ef6\nexport LOCAL_DIR=\"\/www\/wwwroot\/\u7f51\u7ad9\u57df\u540d\/\u5b58\u653e\u6587\u4ef6\u5939\"\n# \u6267\u884c\u811a\u672c\uff0c\u4f20\u9012\u73af\u5883\u53d8\u91cf\u7ed9\u811a\u672c\u4f7f\u7528\n\/bin\/bash \u811a\u672c\u6587\u4ef6.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u670d\u52a1\u5668\u5b89\u88c5 GH \u4e8c\u3001\u811a\u672c\u6587\u4ef6 \u4e09\u3001\u5b9a\u65f6\u4efb\u52a1\u5b9e\u4f8b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_total_topic_count_hidden":0,"_bbp_total_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"wpai_generated_summary":"","wpai_meta_description":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"views":1031,"_links":{"self":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=235"}],"version-history":[{"count":4,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}