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!"