232 lines
9.8 KiB
YAML
232 lines
9.8 KiB
YAML
name: 🚀 Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
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 }}
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
name: 🚀 Build & Publish Multi-Platform Binaries
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
permissions:
|
|
contents: write
|
|
env:
|
|
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
|
|
MIRROR_ONLY: ${{ inputs.mirror_only || false }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
with:
|
|
ref: ${{ inputs.tag || github.ref }}
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
|
|
with:
|
|
bun-version: 1.3.14
|
|
|
|
# A tag alone does not prove review. Also verify the commit actually being
|
|
# compiled, so manual dispatch cannot validate one tag and ship another ref.
|
|
- name: Verify release commit and version
|
|
run: |
|
|
git fetch --no-tags origin main:refs/remotes/origin/main
|
|
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() {
|
|
local binary="$1"
|
|
local archive="$2"
|
|
local stage
|
|
stage=$(mktemp -d)
|
|
cp "dist/bin/${binary}" "${stage}/${binary}"
|
|
ln -s "${binary}" "${stage}/hose-aipro"
|
|
tar -czf "dist/bin/${archive}" -C "${stage}" "${binary}" hose-aipro
|
|
rm -rf "${stage}"
|
|
}
|
|
|
|
package_unix hose-use-linux-x64 hose-use-linux-x64.tar.gz
|
|
package_unix hose-use-linux-arm64 hose-use-linux-arm64.tar.gz
|
|
package_unix hose-use-darwin-x64 hose-use-darwin-x64.tar.gz
|
|
package_unix hose-use-darwin-arm64 hose-use-darwin-arm64.tar.gz
|
|
|
|
stage=$(mktemp -d)
|
|
cp dist/bin/hose-use-windows-x64.exe "${stage}/hose-use-windows-x64.exe"
|
|
printf '@echo off\r\n"%%~dp0hose-use-windows-x64.exe" %%*\r\n' > "${stage}/hose-aipro.cmd"
|
|
(cd "${stage}" && zip -q "${GITHUB_WORKSPACE}/dist/bin/hose-use-windows-x64.zip" hose-use-windows-x64.exe hose-aipro.cmd)
|
|
rm -rf "${stage}"
|
|
|
|
(cd dist/bin && sha256sum hose-use-* > checksums.txt)
|
|
|
|
- name: Publish GitHub Release
|
|
if: ${{ !inputs.mirror_only }}
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
TAG_MSG=$(git tag -l --format='%(contents)' "${RELEASE_TAG}" | sed '/^$/d')
|
|
if [ -n "$TAG_MSG" ]; then
|
|
gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --title "${RELEASE_TAG}" --notes "$TAG_MSG" --generate-notes
|
|
else
|
|
gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --title "${RELEASE_TAG}" --generate-notes
|
|
fi
|
|
gh release upload "${RELEASE_TAG}" dist/bin/hose-use-* dist/bin/checksums.txt --repo "${GITHUB_REPOSITORY}" --clobber
|
|
|
|
- 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 -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 -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
|
|
echo "::error::Failed to create or find Gitea release ID. Response: $RELEASE_RESP"
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Uploading assets to Gitea release ID ${RELEASE_ID}..."
|
|
upload_asset() {
|
|
local file="$1" filename expected_hash attempt info existing remote_hash asset_id response delete_failed
|
|
filename=$(basename "$file")
|
|
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
|
|
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
|
|
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
|
|
fi
|
|
echo "✓ Successfully published release assets to Gitea!"
|