fix(release): retry bounded Gitea uploads and support mirror recovery
This commit is contained in:
1 parent
07031f58a0
commit
9a9e857606
3 files changed
+154
-20
No files matched your search
@@ -10,6 +10,11 @@ on:
|
||||
description: Release tag already merged into main (e.g. v0.8.14)
|
||||
required: true
|
||||
type: string
|
||||
mirror_only:
|
||||
description: Reuse the existing GitHub assets and repair only the Gitea mirror
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
concurrency:
|
||||
group: release-${{ inputs.tag || github.ref_name }}
|
||||
@@ -27,6 +32,7 @@ jobs:
|
||||
contents: write
|
||||
env:
|
||||
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
|
||||
MIRROR_ONLY: ${{ inputs.mirror_only || false }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
@@ -47,34 +53,43 @@ jobs:
|
||||
bun run scripts/verify-release.ts "$RELEASE_TAG"
|
||||
|
||||
- name: Install dependencies
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Check committed version consistency
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun run check:version
|
||||
|
||||
- name: Generate & bundle OpenAPI
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun run openapi:all
|
||||
|
||||
- name: Type-check
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun run check
|
||||
|
||||
- name: Test
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun test
|
||||
|
||||
- name: Compile multi-target binaries
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: |
|
||||
mkdir -p dist/bin
|
||||
node scripts/build-binary.mjs --all --release
|
||||
|
||||
- name: Verify packaged MCP entrypoint
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: bun run scripts/verify-binary.ts dist/bin/hose-use-linux-x64
|
||||
|
||||
- name: Verify plugin bundle runtime
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: |
|
||||
bun run build:plugin
|
||||
bun run scripts/verify-binary.ts dist/mcp/server.js --plugin
|
||||
|
||||
- name: Package release archives
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y zip
|
||||
package_unix() {
|
||||
@@ -102,6 +117,7 @@ jobs:
|
||||
(cd dist/bin && sha256sum hose-use-* > checksums.txt)
|
||||
|
||||
- name: Publish GitHub Release
|
||||
if: ${{ !inputs.mirror_only }}
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
@@ -115,28 +131,40 @@ jobs:
|
||||
|
||||
- name: Publish Gitea Release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_HOST: "https://git.ying-qing.cn"
|
||||
GITEA_REPO: "gitea/hose-use"
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
if [ "${MIRROR_ONLY:-false}" = "true" ]; then
|
||||
echo "::error::GITEA_TOKEN is required to repair the mirror."
|
||||
exit 1
|
||||
fi
|
||||
echo "::notice::GITEA_TOKEN secret not configured, skipping Gitea upload."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TAG_NAME="${RELEASE_TAG}"
|
||||
if [ "${MIRROR_ONLY:-false}" = "true" ]; then
|
||||
# Preserve the published bytes and checksums; never rebuild or replace GitHub assets.
|
||||
mkdir -p dist/bin
|
||||
gh release download "$TAG_NAME" --repo "$GITHUB_REPOSITORY" --dir dist/bin --pattern 'hose-use-*' --pattern checksums.txt
|
||||
(cd dist/bin && sha256sum --strict -c checksums.txt)
|
||||
fi
|
||||
TAG_MSG=$(git tag -l --format='%(contents)' "${TAG_NAME}" | sed '/^$/d')
|
||||
NOTES="${TAG_MSG:-Automated release for ${TAG_NAME}}"
|
||||
|
||||
echo "==> Creating release on Gitea for ${TAG_NAME}..."
|
||||
RELEASE_RESP=$(curl -s -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases" \
|
||||
RELEASE_RESP=$(curl -sS --connect-timeout 15 --max-time 60 -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"body\":$(echo "$NOTES" | jq -Rsa .),\"draft\":false,\"prerelease\":false}")
|
||||
|
||||
RELEASE_ID=$(echo "$RELEASE_RESP" | jq -r '.id // empty')
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
|
||||
RELEASE_ID=$(curl -fsS --connect-timeout 15 --max-time 60 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
@@ -146,32 +174,56 @@ jobs:
|
||||
|
||||
echo "==> Uploading assets to Gitea release ID ${RELEASE_ID}..."
|
||||
upload_asset() {
|
||||
local file="$1"
|
||||
local filename
|
||||
local file="$1" filename expected_hash attempt info existing remote_hash asset_id response delete_failed
|
||||
filename=$(basename "$file")
|
||||
echo " [start] Uploading ${filename} to Gitea..."
|
||||
# Match GitHub --clobber when retrying the same verified release.
|
||||
existing=$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}" | jq -r --arg name "$filename" '.assets[]? | select(.name == $name) | .id')
|
||||
for asset_id in $existing; do
|
||||
curl -fsS -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets/${asset_id}"
|
||||
expected_hash=$(sha256sum "$file" | awk '{ print $1 }')
|
||||
for attempt in 1 2 3; do
|
||||
if [ "$attempt" -gt 1 ]; then sleep "${GITEA_RETRY_DELAY:-3}"; fi
|
||||
echo " [start] Uploading ${filename} to Gitea (attempt ${attempt}/3)..."
|
||||
if ! info=$(curl -fsS --connect-timeout 15 --max-time 60 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}"); then
|
||||
continue
|
||||
fi
|
||||
existing=$(printf '%s' "$info" | jq -r --arg name "$filename" '.assets[]? | select(.name == $name) | .id')
|
||||
if [ -n "$existing" ]; then
|
||||
if ! remote_hash=$(curl -fLsS --connect-timeout 15 --max-time 600 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/${GITEA_REPO}/releases/download/${TAG_NAME}/${filename}" | sha256sum | awk '{ print $1 }'); then
|
||||
continue
|
||||
fi
|
||||
if [ "$remote_hash" = "$expected_hash" ]; then
|
||||
echo " [skip] ${filename} already matches SHA-256"
|
||||
return 0
|
||||
fi
|
||||
# Match GitHub --clobber only when the existing bytes differ.
|
||||
delete_failed=0
|
||||
for asset_id in $existing; do
|
||||
curl -fsS --connect-timeout 15 --max-time 60 -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets/${asset_id}" || delete_failed=1
|
||||
done
|
||||
if [ "$delete_failed" -ne 0 ]; then continue; fi
|
||||
fi
|
||||
if response=$(curl -fsS --connect-timeout 15 --max-time 600 -w "\nHTTP_STATUS:%{http_code}" -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${filename}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-F "attachment=@${file}"); then
|
||||
echo " [done] ${filename} -> $(printf '%s' "$response" | tail -n 1)"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
RESP=$(curl -fsS -m 600 -w "\nHTTP_STATUS:%{http_code}" -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${filename}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-F "attachment=@${file}")
|
||||
STATUS=$(echo "$RESP" | tail -n 1)
|
||||
echo " [done] ${filename} -> ${STATUS}"
|
||||
echo "::error::Failed to upload ${filename} after 3 attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
# Bound outbound traffic: large raw binaries must not compete with all archives.
|
||||
pids=()
|
||||
failed=0
|
||||
for file in dist/bin/hose-use-* dist/bin/checksums.txt; do
|
||||
upload_asset "$file" &
|
||||
pids+=($!)
|
||||
if [ "${#pids[@]}" -eq 2 ]; then
|
||||
for pid in "${pids[@]}"; do wait "$pid" || failed=1; done
|
||||
pids=()
|
||||
fi
|
||||
done
|
||||
|
||||
failed=0
|
||||
for pid in "${pids[@]}"; do
|
||||
wait "$pid" || failed=1
|
||||
done
|
||||
if [ "${#pids[@]}" -gt 0 ]; then
|
||||
for pid in "${pids[@]}"; do wait "$pid" || failed=1; done
|
||||
fi
|
||||
if [ "$failed" -ne 0 ]; then
|
||||
echo "::error::One or more Gitea assets failed to upload."
|
||||
exit 1
|
||||
|
||||
Reference in new issue
Block a user