|
|
|
@@ -43,11 +43,13 @@ forgejo_release_ensure() {
|
|
|
|
|
get_code_file="/tmp/forgejo_get_code.$$"
|
|
|
|
|
get_body_file="/tmp/forgejo_get_body.$$.json"
|
|
|
|
|
|
|
|
|
|
curl "${FORGEJO_CURL_TLS[@]}" -s -o "$get_body_file" -w '%{http_code}' \
|
|
|
|
|
curl ${FORGEJO_CURL_TLS[@]+"${FORGEJO_CURL_TLS[@]}"} -s -o "$get_body_file" -w '%{http_code}' \
|
|
|
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
|
|
|
"${FORGEJO_URL}/api/v1/repos/${FORGEJO_REPO}/releases/tags/${tag}" \
|
|
|
|
|
> "$get_code_file"
|
|
|
|
|
read -r get_code < "$get_code_file"
|
|
|
|
|
# `|| true`: curl -w '%{http_code}' 写入的值无结尾换行,read 到无换行 EOF 返回 1
|
|
|
|
|
# (值已赋)→ set -e 会静默中止。容错该退出码;文件恒由上面的 curl 创建,不掩盖真错。
|
|
|
|
|
read -r get_code < "$get_code_file" || true
|
|
|
|
|
rm -f "$get_code_file"
|
|
|
|
|
|
|
|
|
|
if [ "$get_code" = "200" ]; then
|
|
|
|
@@ -81,13 +83,13 @@ json.dump(
|
|
|
|
|
)
|
|
|
|
|
' > "$create_req_file"
|
|
|
|
|
|
|
|
|
|
curl "${FORGEJO_CURL_TLS[@]}" -s -o "$create_body_file" -w '%{http_code}' \
|
|
|
|
|
curl ${FORGEJO_CURL_TLS[@]+"${FORGEJO_CURL_TLS[@]}"} -s -o "$create_body_file" -w '%{http_code}' \
|
|
|
|
|
-X POST "${FORGEJO_URL}/api/v1/repos/${FORGEJO_REPO}/releases" \
|
|
|
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
--data @"$create_req_file" \
|
|
|
|
|
> "$create_code_file"
|
|
|
|
|
read -r create_code < "$create_code_file"
|
|
|
|
|
read -r create_code < "$create_code_file" || true # 无结尾换行,见 forgejo_release_ensure 注释
|
|
|
|
|
rm -f "$create_code_file" "$create_req_file"
|
|
|
|
|
|
|
|
|
|
if [ "$create_code" -lt 200 ] || [ "$create_code" -ge 300 ]; then
|
|
|
|
@@ -108,7 +110,7 @@ _forgejo_read_release_id() {
|
|
|
|
|
id_file="/tmp/forgejo_release_id.$$"
|
|
|
|
|
python3 -c "import json,sys; print(json.load(open(sys.argv[1]))['id'])" \
|
|
|
|
|
"$json_file" > "$id_file"
|
|
|
|
|
read -r RELEASE_ID < "$id_file"
|
|
|
|
|
read -r RELEASE_ID < "$id_file" || true # python 写入可能无结尾换行,见上注释
|
|
|
|
|
rm -f "$id_file"
|
|
|
|
|
export RELEASE_ID
|
|
|
|
|
}
|
|
|
|
@@ -125,12 +127,12 @@ forgejo_upload_asset() {
|
|
|
|
|
code_file="/tmp/forgejo_upload_code.$$"
|
|
|
|
|
body_file="/tmp/forgejo_upload_body.$$.json"
|
|
|
|
|
|
|
|
|
|
curl "${FORGEJO_CURL_TLS[@]}" -s -o "$body_file" -w '%{http_code}' \
|
|
|
|
|
curl ${FORGEJO_CURL_TLS[@]+"${FORGEJO_CURL_TLS[@]}"} -s -o "$body_file" -w '%{http_code}' \
|
|
|
|
|
-X POST "${FORGEJO_URL}/api/v1/repos/${FORGEJO_REPO}/releases/${RELEASE_ID}/assets" \
|
|
|
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
|
|
|
-F "attachment=@${file}" \
|
|
|
|
|
> "$code_file"
|
|
|
|
|
read -r code < "$code_file"
|
|
|
|
|
read -r code < "$code_file" || true # curl http_code 无结尾换行,见上注释
|
|
|
|
|
rm -f "$code_file"
|
|
|
|
|
|
|
|
|
|
echo "==> forgejo: uploaded ${file} (HTTP ${code})"
|
|
|
|
|