237 lines
9.3 KiB
YAML
237 lines
9.3 KiB
YAML
name: 🚀 Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: "Release tag (e.g. v0.9.5, defaults to current ref)"
|
|
required: false
|
|
type: string
|
|
|
|
concurrency:
|
|
group: release-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
name: 🚀 Build & Publish Multi-Platform Binaries
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@v2
|
|
with:
|
|
bun-version: latest
|
|
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
|
|
- 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 & checksums
|
|
run: |
|
|
sudo apt-get update && sudo apt-get install -y zip
|
|
cd dist/bin
|
|
tar -czf seal-home-linux-x64.tar.gz seal-home-linux-x64
|
|
tar -czf seal-home-linux-arm64.tar.gz seal-home-linux-arm64
|
|
tar -czf seal-home-darwin-x64.tar.gz seal-home-darwin-x64
|
|
tar -czf seal-home-darwin-arm64.tar.gz seal-home-darwin-arm64
|
|
zip -q seal-home-windows-x64.zip seal-home-windows-x64.exe
|
|
sha256sum seal-home-* > checksums.txt
|
|
echo "Generated checksums:"
|
|
cat checksums.txt
|
|
|
|
- name: Publish GitHub Release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
TAG_NAME="${{ github.event.inputs.tag || github.ref_name }}"
|
|
TAG_MSG=$(git tag -l --format='%(contents)' "${TAG_NAME}" | sed '/^$/d')
|
|
if [ -n "$TAG_MSG" ]; then
|
|
gh release view "${TAG_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${TAG_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${TAG_NAME}" --notes "$TAG_MSG" --generate-notes
|
|
else
|
|
gh release view "${TAG_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${TAG_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${TAG_NAME}" --generate-notes
|
|
fi
|
|
gh release upload "${TAG_NAME}" dist/bin/seal-home-* dist/bin/checksums.txt --repo "${GITHUB_REPOSITORY}" --clobber
|
|
|
|
- name: Publish Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_HOST: "https://git.ying-qing.cn"
|
|
GITEA_REPO: "gitea/seal-home"
|
|
run: |
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "::notice::GITEA_TOKEN secret not configured, skipping Gitea upload."
|
|
exit 0
|
|
fi
|
|
|
|
TAG_NAME="${{ github.event.inputs.tag || github.ref_name }}"
|
|
TAG_MSG=$(git tag -l --format='%(contents)' "${TAG_NAME}" | sed '/^$/d')
|
|
NOTES="${TAG_MSG:-Automated release for ${TAG_NAME}}"
|
|
|
|
echo "==> Creating or finding release on Gitea for ${TAG_NAME}..."
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
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')
|
|
fi
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "::error::Failed to create or find the Gitea release."
|
|
exit 1
|
|
fi
|
|
|
|
priority_files=(
|
|
"dist/bin/seal-home-darwin-arm64.tar.gz"
|
|
"dist/bin/seal-home-darwin-arm64"
|
|
"dist/bin/seal-home-darwin-x64.tar.gz"
|
|
"dist/bin/seal-home-darwin-x64"
|
|
)
|
|
remaining_files=(
|
|
"dist/bin/seal-home-linux-arm64.tar.gz"
|
|
"dist/bin/seal-home-linux-arm64"
|
|
"dist/bin/seal-home-linux-x64.tar.gz"
|
|
"dist/bin/seal-home-linux-x64"
|
|
"dist/bin/seal-home-windows-x64.zip"
|
|
"dist/bin/seal-home-windows-x64.exe"
|
|
"dist/bin/checksums.txt"
|
|
)
|
|
expected_files=("${priority_files[@]}" "${remaining_files[@]}")
|
|
|
|
for file in "${expected_files[@]}"; do
|
|
if [ ! -f "$file" ]; then
|
|
echo "::error::Expected release asset is missing locally: ${file}"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
release_json() {
|
|
curl -fsS \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}"
|
|
}
|
|
|
|
delete_asset() {
|
|
local asset_id="$1"
|
|
curl -fsS -X DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets/${asset_id}" \
|
|
>/dev/null
|
|
}
|
|
|
|
upload_asset() {
|
|
local file="$1"
|
|
local filename file_size assets matching_id asset_id response_file http_code
|
|
filename=$(basename "$file")
|
|
file_size=$(wc -c < "$file" | tr -d ' ')
|
|
assets=$(release_json)
|
|
|
|
matching_id=$(echo "$assets" | jq -r --arg name "$filename" --argjson size "$file_size" \
|
|
'[.assets[] | select(.name == $name and .size == $size) | .id][0] // empty')
|
|
|
|
if [ -n "$matching_id" ]; then
|
|
echo " [keep] ${filename} already exists with the expected size"
|
|
while IFS= read -r asset_id; do
|
|
[ -n "$asset_id" ] || continue
|
|
if [ "$asset_id" != "$matching_id" ]; then
|
|
echo " [dedupe] removing duplicate ${filename} asset ${asset_id}"
|
|
delete_asset "$asset_id"
|
|
fi
|
|
done < <(echo "$assets" | jq -r --arg name "$filename" '.assets[] | select(.name == $name) | .id')
|
|
return
|
|
fi
|
|
|
|
while IFS= read -r asset_id; do
|
|
[ -n "$asset_id" ] || continue
|
|
echo " [replace] removing stale ${filename} asset ${asset_id}"
|
|
delete_asset "$asset_id"
|
|
done < <(echo "$assets" | jq -r --arg name "$filename" '.assets[] | select(.name == $name) | .id')
|
|
|
|
response_file=$(mktemp)
|
|
echo " [start] uploading ${filename} (${file_size} bytes)"
|
|
if ! http_code=$(curl -sS --fail-with-body \
|
|
--connect-timeout 10 \
|
|
--max-time 900 \
|
|
--retry 3 \
|
|
--retry-delay 5 \
|
|
--retry-all-errors \
|
|
--retry-max-time 2700 \
|
|
-o "$response_file" \
|
|
-w '%{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 "::error::Failed to upload ${filename} to Gitea."
|
|
sed -n '1,20p' "$response_file"
|
|
rm -f "$response_file"
|
|
return 1
|
|
fi
|
|
rm -f "$response_file"
|
|
|
|
if [ "$http_code" != "201" ]; then
|
|
echo "::error::Unexpected Gitea upload status for ${filename}: HTTP ${http_code}"
|
|
return 1
|
|
fi
|
|
echo " [done] ${filename} -> HTTP ${http_code}"
|
|
}
|
|
|
|
echo "==> Uploading macOS assets first (Apple Silicon archive has highest priority)..."
|
|
for file in "${priority_files[@]}"; do
|
|
upload_asset "$file"
|
|
done
|
|
|
|
echo "==> Uploading remaining assets with at most 2 concurrent transfers..."
|
|
for ((index=0; index<${#remaining_files[@]}; index+=2)); do
|
|
pids=()
|
|
for ((offset=0; offset<2 && index+offset<${#remaining_files[@]}; offset++)); do
|
|
upload_asset "${remaining_files[index+offset]}" &
|
|
pids+=("$!")
|
|
done
|
|
for pid in "${pids[@]}"; do
|
|
wait "$pid"
|
|
done
|
|
done
|
|
|
|
echo "==> Verifying the Gitea release asset manifest..."
|
|
final_release=$(release_json)
|
|
verification_failed=false
|
|
for file in "${expected_files[@]}"; do
|
|
filename=$(basename "$file")
|
|
file_size=$(wc -c < "$file" | tr -d ' ')
|
|
matching_count=$(echo "$final_release" | jq -r --arg name "$filename" --argjson size "$file_size" \
|
|
'[.assets[] | select(.name == $name and .size == $size)] | length')
|
|
total_count=$(echo "$final_release" | jq -r --arg name "$filename" \
|
|
'[.assets[] | select(.name == $name)] | length')
|
|
if [ "$matching_count" != "1" ] || [ "$total_count" != "1" ]; then
|
|
echo "::error::Gitea asset verification failed for ${filename}: matching=${matching_count}, total=${total_count}"
|
|
verification_failed=true
|
|
fi
|
|
done
|
|
if [ "$verification_failed" = "true" ]; then
|
|
exit 1
|
|
fi
|
|
echo "✓ Successfully published and verified all Gitea release assets!"
|