From 0372698ff9bac8afbce83c322829e3f718e7113a Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 27 Aug 2026 11:33:45 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20openapi:all=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=AD=A5=E9=AA=A4=E5=B9=B6=E9=9B=86=E6=88=90?= =?UTF-8?q?=20GitHub=20=E4=B8=8E=20Gitea=20=E8=87=AA=E5=8A=A8=E5=8F=8C?= =?UTF-8?q?=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7331e7a..b438a45 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,9 +25,15 @@ jobs: - name: Install dependencies run: bun install --frozen-lockfile + - name: Generate & bundle OpenAPI + run: bun run openapi:all + - name: Type-check run: bun run check + - name: Test + run: bun test + - name: Compile multi-target binaries run: | mkdir -p dist/bin @@ -54,3 +60,58 @@ jobs: gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${GITHUB_REF_NAME}" --generate-notes fi gh release upload "${GITHUB_REF_NAME}" dist/bin/hose-use-* --repo "${GITHUB_REPOSITORY}" --clobber + + - name: Publish Gitea Release + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_HOST: "https://git.ying-qing.cn" + GITEA_REPO: "gitea/hose-use" + run: | + if [ -z "$GITEA_TOKEN" ]; then + echo "::notice::GITEA_TOKEN secret not configured, skipping Gitea upload." + exit 0 + fi + + TAG_NAME="${GITHUB_REF_NAME}" + 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" \ + -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') + fi + + if [ -z "$RELEASE_ID" ]; then + echo "::warning::Failed to create or find Gitea release ID. Response: $RELEASE_RESP" + exit 0 + fi + + echo "==> Uploading assets to Gitea release ID ${RELEASE_ID}..." + upload_asset() { + local file="$1" + local filename + filename=$(basename "$file") + echo " [start] Uploading ${filename} to Gitea..." + RESP=$(curl -s -m 120 -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}" + } + + pids=() + for file in dist/bin/hose-use-*; do + upload_asset "$file" & + pids+=($!) + done + + for pid in "${pids[@]}"; do + wait "$pid" || true + done + echo "✓ Successfully published release assets to Gitea!"