- Pin oven-sh/setup-bun to v2.2.0 by full commit SHA instead of the mutable v2 tag, and pin bun-version to 1.3.14 instead of latest - Declare packageManager (bun@1.3.14) and engines (>=1.3.14) in package.json so local dev and CI use the same Bun toolchain
133 lines
5.0 KiB
YAML
133 lines
5.0 KiB
YAML
name: 🚀 Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
name: 🚀 Build & Publish Multi-Platform Binaries
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
|
|
with:
|
|
bun-version: 1.3.14
|
|
|
|
- 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
|
|
node scripts/build-binary.mjs --all
|
|
|
|
- name: Package release archives
|
|
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}"
|
|
|
|
- name: Publish GitHub Release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
TAG_MSG=$(git tag -l --format='%(contents)' "${GITHUB_REF_NAME}" | sed '/^$/d')
|
|
if [ -n "$TAG_MSG" ]; then
|
|
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}" --notes "$TAG_MSG" --generate-notes
|
|
else
|
|
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 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}"
|
|
}
|
|
|
|
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!"
|