369 lines
15 KiB
YAML
369 lines
15 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-github:
|
|
name: 🚀 Build & Publish GitHub Release
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# The tag is the publish trigger, but on its own it says nothing about review: `contents:
|
|
# write` plus any pushed tag would ship binaries built from an unreviewed commit, and the
|
|
# manual dispatch input can name a tag that was never merged. Require the tagged commit to
|
|
# be an ancestor of origin/main, i.e. to have gone through the protected branch.
|
|
- name: Verify the release tag is on main
|
|
env:
|
|
TAG_NAME: ${{ github.event.inputs.tag || github.ref_name }}
|
|
run: |
|
|
if [ -z "${TAG_NAME}" ]; then
|
|
echo "::error::Could not resolve a release tag from this event."
|
|
exit 1
|
|
fi
|
|
|
|
git fetch --no-tags origin main
|
|
if ! git rev-parse --verify --quiet "refs/tags/${TAG_NAME}" >/dev/null; then
|
|
if ! git fetch --no-tags origin "refs/tags/${TAG_NAME}:refs/tags/${TAG_NAME}"; then
|
|
echo "::error::'${TAG_NAME}' is not a tag in this repository. Pass the release tag as the workflow input."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
TAG_COMMIT=$(git rev-list -n 1 "refs/tags/${TAG_NAME}")
|
|
if ! git merge-base --is-ancestor "${TAG_COMMIT}" origin/main; then
|
|
echo "::error::Tag ${TAG_NAME} (${TAG_COMMIT}) is not an ancestor of origin/main. Merge it through a PR first, then re-tag."
|
|
exit 1
|
|
fi
|
|
echo "✓ ${TAG_NAME} -> ${TAG_COMMIT} is on main"
|
|
|
|
- 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: 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-use-linux-x64.tar.gz seal-use-linux-x64
|
|
tar -czf seal-use-linux-arm64.tar.gz seal-use-linux-arm64
|
|
tar -czf seal-use-darwin-x64.tar.gz seal-use-darwin-x64
|
|
tar -czf seal-use-darwin-arm64.tar.gz seal-use-darwin-arm64
|
|
zip -q seal-use-windows-x64.zip seal-use-windows-x64.exe
|
|
sha256sum seal-use-* > 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-use-* dist/bin/checksums.txt --repo "${GITHUB_REPOSITORY}" --clobber
|
|
|
|
- name: Upload binaries artifact
|
|
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
continue-on-error: true
|
|
with:
|
|
name: release-binaries
|
|
path: dist/bin/
|
|
retention-days: 1
|
|
|
|
publish-gitea:
|
|
name: 📦 Sync Gitea Mirror
|
|
needs: build-and-publish-github
|
|
# Mirror only a release that was actually published. `always()` also ran this after the
|
|
# tag-on-main guard refused to publish, so the mirror chased assets that were never built.
|
|
if: ${{ !cancelled() && needs.build-and-publish-github.result == 'success' }}
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# The GitHub artifact service can be unavailable or quota-limited even
|
|
# after the release upload succeeds. Download from the release itself so
|
|
# Gitea mirroring remains independent of ephemeral workflow artifacts.
|
|
- name: Download release assets from GitHub Release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
TAG_NAME="${{ github.event.inputs.tag || github.ref_name }}"
|
|
mkdir -p dist/bin
|
|
gh release download "${TAG_NAME}" \
|
|
--repo "${GITHUB_REPOSITORY}" \
|
|
--pattern 'seal-use-*' \
|
|
--pattern 'checksums.txt' \
|
|
--dir dist/bin \
|
|
--clobber
|
|
|
|
- name: Sync to Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_HOST: "https://git.ying-qing.cn"
|
|
GITEA_REPO: "gitea/seal-use"
|
|
run: |
|
|
if [ -z "$GITEA_TOKEN" ]; then
|
|
echo "::error::GITEA_TOKEN secret is not configured; refusing to report a partial release."
|
|
exit 1
|
|
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 -fsS --connect-timeout 15 --max-time 30 \
|
|
-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 -fsS --connect-timeout 15 --max-time 30 -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 "::warning::Failed to create or find the Gitea release. Skipping Gitea publishing."
|
|
exit 0
|
|
fi
|
|
|
|
# Tier 1: Supreme Priority (Mac Apple Silicon compressed archive & checksums, ~26MB)
|
|
supreme_files=(
|
|
"dist/bin/seal-use-darwin-arm64.tar.gz"
|
|
"dist/bin/checksums.txt"
|
|
)
|
|
|
|
# Tier 2: Secondary Priority (Other platforms compressed archives, ~110MB)
|
|
secondary_archive_files=(
|
|
"dist/bin/seal-use-darwin-x64.tar.gz"
|
|
"dist/bin/seal-use-linux-arm64.tar.gz"
|
|
"dist/bin/seal-use-linux-x64.tar.gz"
|
|
"dist/bin/seal-use-windows-x64.zip"
|
|
)
|
|
|
|
# Tier 3: Tertiary Priority (Raw uncompressed executables, ~360MB)
|
|
raw_binary_files=(
|
|
"dist/bin/seal-use-darwin-arm64"
|
|
"dist/bin/seal-use-darwin-x64"
|
|
"dist/bin/seal-use-linux-arm64"
|
|
"dist/bin/seal-use-linux-x64"
|
|
"dist/bin/seal-use-windows-x64.exe"
|
|
)
|
|
|
|
release_json() {
|
|
curl -fsS --connect-timeout 15 --max-time 30 \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}"
|
|
}
|
|
|
|
delete_asset() {
|
|
local asset_id="$1"
|
|
curl -fsS --connect-timeout 15 --max-time 30 -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 (${file_size} bytes)"
|
|
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 0
|
|
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 15 \
|
|
--max-time 180 \
|
|
--speed-time 30 \
|
|
--speed-limit 1024 \
|
|
--retry 1 \
|
|
--retry-delay 5 \
|
|
--retry-max-time 240 \
|
|
-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}" \
|
|
-H "Expect:" \
|
|
--http1.1 \
|
|
-F "attachment=@${file}"); then
|
|
echo "::warning::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 "::warning::Unexpected Gitea upload status for ${filename}: HTTP ${http_code}"
|
|
return 1
|
|
fi
|
|
echo " [done] ${filename} -> HTTP ${http_code}"
|
|
return 0
|
|
}
|
|
|
|
mirror_failed=0
|
|
echo "==> Tier 1: Uploading Supreme Priority assets (Mac Apple Silicon archive & checksums)..."
|
|
for file in "${supreme_files[@]}"; do
|
|
if [ -f "$file" ]; then
|
|
upload_asset "$file" || mirror_failed=1
|
|
fi
|
|
done
|
|
|
|
echo "==> Tier 2: Uploading Secondary Priority archives (Linux, Windows, Intel Mac)..."
|
|
for file in "${secondary_archive_files[@]}"; do
|
|
if [ -f "$file" ]; then
|
|
upload_asset "$file" || mirror_failed=1
|
|
fi
|
|
done
|
|
|
|
echo "==> Tier 3: Uploading Tertiary Priority uncompressed raw binaries..."
|
|
for file in "${raw_binary_files[@]}"; do
|
|
if [ -f "$file" ]; then
|
|
upload_asset "$file" || mirror_failed=1
|
|
fi
|
|
done
|
|
|
|
echo "==> Verifying Gitea release asset manifest..."
|
|
final_release=$(release_json)
|
|
required_files=("${supreme_files[@]}" "${secondary_archive_files[@]}" "${raw_binary_files[@]}")
|
|
for file in "${required_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')
|
|
if [ "$matching_count" = "1" ]; then
|
|
echo " ✓ ${filename} ready"
|
|
else
|
|
echo " ⚠️ ${filename} not yet synchronized"
|
|
mirror_failed=1
|
|
fi
|
|
done
|
|
if [ "$mirror_failed" -ne 0 ]; then
|
|
echo "::error::Gitea mirror is incomplete; failing the job so downstream publishing does not run."
|
|
exit 1
|
|
fi
|
|
echo "✓ Gitea publishing step completed!"
|
|
|
|
update-brew-tap:
|
|
name: 🍺 Update Homebrew Tap
|
|
needs: [build-and-publish-github, publish-gitea]
|
|
if: ${{ !cancelled() && needs.build-and-publish-github.result == 'success' && needs.publish-gitea.result == 'success' }}
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout Homebrew Tap
|
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
repository: yunyingk/homebrew-tap
|
|
token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
path: tap
|
|
|
|
- name: Download checksums from GitHub Release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
TAG_NAME="${{ github.event.inputs.tag || github.ref_name }}"
|
|
gh release download "${TAG_NAME}" \
|
|
--repo "${GITHUB_REPOSITORY}" \
|
|
--pattern 'checksums.txt' \
|
|
--dir . \
|
|
--clobber
|
|
|
|
- name: Update Formula
|
|
run: |
|
|
RAW_TAG="${{ github.event.inputs.tag || github.ref_name }}"
|
|
VERSION="${RAW_TAG#v}"
|
|
ARM64_SHA=$(grep 'seal-use-darwin-arm64.tar.gz' checksums.txt | awk '{print $1}')
|
|
|
|
if [ -z "$ARM64_SHA" ]; then
|
|
echo "::error::Could not find sha256 for seal-use-darwin-arm64.tar.gz"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Updating Formula to version ${VERSION} with sha256 ${ARM64_SHA}"
|
|
|
|
FORMULA_FILE="tap/Formula/seal-use.rb"
|
|
sed -i -E "s/version \"[^\"]+\"/version \"${VERSION}\"/" "$FORMULA_FILE"
|
|
sed -i -E "s/sha256 \"[^\"]+\"/sha256 \"${ARM64_SHA}\"/" "$FORMULA_FILE"
|
|
|
|
cd tap
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
if git diff --quiet; then
|
|
echo "No changes to Formula, skipping commit."
|
|
else
|
|
git add Formula/seal-use.rb
|
|
git commit -m "chore(release): bump seal-use to ${VERSION}"
|
|
git push origin main
|
|
echo "✓ Homebrew Tap formula updated successfully!"
|
|
fi
|