diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59413aa..0652fb6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -110,275 +110,5 @@ jobs: 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_lookup=$(curl -sS --connect-timeout 15 --max-time 30 \ - -w '\n%{http_code}' \ - -H "Authorization: token ${GITEA_TOKEN}" \ - "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}") - release_status=$(printf '%s\n' "$release_lookup" | tail -n 1) - release_body=$(printf '%s\n' "$release_lookup" | sed '$d') - case "$release_status" in - 200) - RELEASE_ID=$(echo "$release_body" | jq -r '.id // empty') - ;; - 404) - RELEASE_ID="" - ;; - *) - echo "::error::Failed to query the Gitea release (HTTP ${release_status})." - echo "$release_body" | sed -n '1,20p' - exit 1 - ;; - esac - - 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 + # Gitea asset promotion and Homebrew tap updates are owned by the WSL + # seal-use-release-sync.timer after this GitHub Release is published. diff --git a/ops/README.md b/ops/README.md new file mode 100644 index 0000000..edad558 --- /dev/null +++ b/ops/README.md @@ -0,0 +1,41 @@ +# Seal Use Infrastructure Operations + +## Release promotion + +GitHub Actions is responsible only for building and publishing the GitHub +Release. On WSL, `seal-use-release-sync.timer` polls the latest release every +15 minutes and promotes it in this order: + +1. `seal-use-darwin-arm64.tar.gz` +2. `checksums.txt` +3. the remaining archives +4. raw platform binaries + +The Homebrew tap is updated immediately after the first two assets are present +in Gitea and the macOS arm64 checksum is available. The remaining assets are +idempotent retries and do not make a valid Homebrew installation unavailable. + +The worker uses mac13's `http://192.168.3.62:7897` proxy only for GitHub. Local +Gitea traffic stays direct through `127.0.0.1:3001`. + +Useful WSL commands: + +```sh +systemctl status seal-use-release-sync.timer +systemctl start seal-use-release-sync.service +journalctl -u seal-use-release-sync.service -n 100 --no-pager +``` + +Credentials are stored as `0600` files under +`~/.config/seal-use/`; they must never be committed or printed. + +## Cross-host health check + +From mac15, run: + +```sh +./ops/infra-healthcheck.sh +``` + +It emits JSON checks for mac15, WSL, Windows, mac13, and Aliyun. The script is +read-only; a failed check does not restart or mutate any service. diff --git a/ops/infra-healthcheck.sh b/ops/infra-healthcheck.sh new file mode 100755 index 0000000..ea0fa65 --- /dev/null +++ b/ops/infra-healthcheck.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -uo pipefail + +# Run from mac15. This is read-only and emits one JSON report. +SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=8) + +json_result() { + local name="$1" status="$2" detail="$3" + jq -n --arg name "$name" --arg status "$status" --arg detail "$detail" \ + '{name:$name,status:$status,detail:$detail}' +} + +run_ssh() { + local host="$1" command="$2" output + if output=$(ssh "${SSH_OPTS[@]}" "$host" "$command" 2>&1); then + printf 'ok\t%s' "$(tr '\n' ' ' <<< "$output")" + else + printf 'fail\t%s' "$(tr '\n' ' ' <<< "$output")" + fi +} + +check_ssh() { + local name="$1" host="$2" command="$3" result status detail + result=$(run_ssh "$host" "$command") + status=${result%%$'\t'*} + detail=${result#*$'\t'} + json_result "$name" "$status" "$detail" +} + +check_local_proxy() { + local code + code=$(curl -sS -o /dev/null --proxy http://127.0.0.1:7897 \ + --connect-timeout 5 --max-time 15 -w '%{http_code}' https://github.com 2>/dev/null || true) + [ "$code" = "200" ] && json_result mac15_proxy ok "github_http=$code" || json_result mac15_proxy fail "github_http=$code" +} + +results=( + "$(check_local_proxy)" + "$(check_ssh wsl_tailscale wsl-dev 'tailscale ip -4')" + "$(check_ssh wsl_frp wsl-dev 'docker inspect -f "{{.State.Status}}" frpc-wsl-gateway')" + "$(check_ssh wsl_gitea wsl-dev 'curl -sS -o /dev/null -w "gitea_http=%{http_code}" http://127.0.0.1:3001/api/v1/version')" + "$(check_ssh wsl_github_proxy wsl-dev 'HTTPS_PROXY=http://192.168.3.62:7897 HTTP_PROXY=http://192.168.3.62:7897 NO_PROXY=127.0.0.1,localhost curl -sS -o /dev/null --connect-timeout 8 --max-time 15 -w "github_http=%{http_code}" https://github.com')" + "$(check_ssh windows_tailscale windows '"C:\Program Files\Tailscale\tailscale.exe" ip -4')" + "$(check_ssh windows_wifi windows 'netsh wlan show interfaces | findstr /C:"SSID"')" + "$(check_ssh mac13_proxy mac13 'curl -sS -o /dev/null --proxy http://127.0.0.1:7897 --connect-timeout 5 --max-time 15 -w "github_http=%{http_code}" https://github.com')" + "$(check_ssh aliyun_frps aliyun 'docker inspect -f "{{.State.Status}}" frps')" + "$(check_ssh aliyun_gitea aliyun 'curl -sS -o /dev/null -w "gitea_public_http=%{http_code}" https://git.ying-qing.cn/api/v1/version')" +) + +printf '%s\n' "${results[@]}" | jq -s --arg generatedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + '{generatedAt:$generatedAt,checks:.}' diff --git a/ops/release-sync.sh b/ops/release-sync.sh new file mode 100755 index 0000000..c60950a --- /dev/null +++ b/ops/release-sync.sh @@ -0,0 +1,214 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# GitHub is the release source of truth. This worker promotes a published +# release to the local Gitea mirror, then updates Homebrew after the macOS +# arm64 archive and checksums are present in Gitea. + +umask 077 +STATE_DIR="${SEAL_USE_SYNC_STATE_DIR:-$HOME/.local/state/seal-use-release-sync}" +WORK_DIR="${SEAL_USE_SYNC_WORK_DIR:-$STATE_DIR/work}" +GITHUB_REPO="${SEAL_USE_GITHUB_REPO:-yunyingk/seal-use}" +HOMEBREW_REPO="${SEAL_USE_HOMEBREW_REPO:-yunyingk/homebrew-tap}" +GITEA_BASE="${SEAL_USE_GITEA_BASE:-http://127.0.0.1:3001}" +GITEA_REPO="${SEAL_USE_GITEA_REPO:-gitea/seal-use}" +PROXY_URL="${SEAL_USE_PROXY_URL:-http://192.168.3.62:7897}" +NO_PROXY_LIST="${NO_PROXY:-127.0.0.1,localhost,100.82.151.105,git.ying-qing.cn}" +GITHUB_TOKEN_FILE="${SEAL_USE_GITHUB_TOKEN_FILE:-$HOME/.config/seal-use/github-token}" +GITEA_TOKEN_FILE="${SEAL_USE_GITEA_TOKEN_FILE:-$HOME/.config/seal-use/gitea-token}" +LOCK_FILE="${SEAL_USE_SYNC_LOCK_FILE:-$STATE_DIR/sync.lock}" + +mkdir -p "$STATE_DIR" "$WORK_DIR" +exec 9>"$LOCK_FILE" +if ! flock -n 9; then + echo "release sync is already running; exiting" >&2 + exit 0 +fi + +log() { printf '[release-sync] %s\n' "$*" >&2; } +die() { log "ERROR: $*"; exit 1; } +require_file() { [ -r "$1" ] || die "missing credential file: $1"; } + +require_file "$GITHUB_TOKEN_FILE" +require_file "$GITEA_TOKEN_FILE" +GITHUB_TOKEN=$(tr -d '\r\n' < "$GITHUB_TOKEN_FILE") +GITEA_TOKEN=$(tr -d '\r\n' < "$GITEA_TOKEN_FILE") +[ -n "$GITHUB_TOKEN" ] || die "GitHub token is empty" +[ -n "$GITEA_TOKEN" ] || die "Gitea token is empty" + +github_curl() { + local config_file rc + config_file=$(mktemp "$STATE_DIR/github-curl.XXXXXX") + chmod 600 "$config_file" + printf 'header = "Authorization: Bearer %s"\n' "$GITHUB_TOKEN" > "$config_file" + if env HTTP_PROXY="$PROXY_URL" HTTPS_PROXY="$PROXY_URL" ALL_PROXY= NO_PROXY="$NO_PROXY_LIST" \ + curl --fail-with-body --connect-timeout 15 --max-time 120 \ + --config "$config_file" "$@"; then + rc=0 + else + rc=$? + fi + rm -f "$config_file" + return "$rc" +} + +gitea_curl() { + local config_file rc + config_file=$(mktemp "$STATE_DIR/gitea-curl.XXXXXX") + chmod 600 "$config_file" + printf 'header = "Authorization: token %s"\n' "$GITEA_TOKEN" > "$config_file" + if env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY NO_PROXY="$NO_PROXY_LIST" \ + curl --fail-with-body --connect-timeout 15 --max-time 120 \ + --config "$config_file" "$@"; then + rc=0 + else + rc=$? + fi + rm -f "$config_file" + return "$rc" +} + +release_json=$(github_curl -H 'Accept: application/vnd.github+json' \ + "https://api.github.com/repos/$GITHUB_REPO/releases/latest") || die "cannot read latest GitHub release" +tag=$(jq -r '.tag_name // empty' <<< "$release_json") +[ -n "$tag" ] || die "latest GitHub release has no tag" +log "latest GitHub release: $tag" + +release_dir="$WORK_DIR/$tag" +mkdir -p "$release_dir" + +github_asset() { + local name="$1" + jq -c --arg name "$name" '.assets[] | select(.name == $name)' <<< "$release_json" | head -n 1 +} + +gitea_release_response() { + local response status body + response=$(gitea_curl -sS -w '\n%{http_code}' \ + "$GITEA_BASE/api/v1/repos/$GITEA_REPO/releases/tags/$tag" 2>&1) || true + status=$(tail -n 1 <<< "$response") + body=$(sed '$d' <<< "$response") + printf '%s\n%s\n' "$status" "$body" +} + +readarray -t gitea_lookup < <(gitea_release_response) +gitea_status="${gitea_lookup[0]:-}" +gitea_body="${gitea_lookup[1]:-}" + +if [ "$gitea_status" = "404" ]; then + log "creating Gitea release $tag" + notes=$(jq -r '.body // ""' <<< "$release_json") + payload=$(jq -n --arg tag "$tag" --arg body "$notes" \ + '{tag_name:$tag,name:$tag,body:$body,draft:false,prerelease:false}') + gitea_body=$(gitea_curl -sS -X POST -H 'Content-Type: application/json' \ + -d "$payload" "$GITEA_BASE/api/v1/repos/$GITEA_REPO/releases") || die "cannot create Gitea release $tag" +elif [ "$gitea_status" != "200" ]; then + die "cannot read Gitea release $tag (HTTP $gitea_status)" +fi + +release_id=$(jq -r '.id // empty' <<< "$gitea_body") +[ -n "$release_id" ] || die "Gitea release $tag has no id" + +gitea_assets() { gitea_curl -sS "$GITEA_BASE/api/v1/repos/$GITEA_REPO/releases/$release_id"; } + +asset_matches() { + local assets="$1" name="$2" size="$3" + [ "$(jq -r --arg name "$name" --argjson size "$size" \ + '[.assets[] | select(.name == $name and .size == $size)] | length' <<< "$assets")" = "1" ] +} + +delete_named_assets() { + local assets="$1" name="$2" asset_id + while IFS= read -r asset_id; do + [ -n "$asset_id" ] || continue + log "removing stale Gitea asset $name ($asset_id)" + gitea_curl -sS -X DELETE \ + "$GITEA_BASE/api/v1/repos/$GITEA_REPO/releases/$release_id/assets/$asset_id" >/dev/null + done < <(jq -r --arg name "$name" '.assets[] | select(.name == $name) | .id' <<< "$assets") +} + +sync_asset() { + local name="$1" asset size url sha file actual assets encoded + asset=$(github_asset "$name") + [ -n "$asset" ] || die "GitHub release $tag is missing $name" + size=$(jq -r '.size' <<< "$asset") + # Download through the authenticated GitHub asset API. The public browser + # URL can return a proxy-generated 404 from WSL even when the asset exists. + url=$(jq -r '.url' <<< "$asset") + assets=$(gitea_assets) + if asset_matches "$assets" "$name" "$size"; then + log "keep $name ($size bytes)" + return 0 + fi + + file="$release_dir/$name" + log "download $name ($size bytes) through mac13 proxy" + github_curl -L -H 'Accept: application/octet-stream' "$url" -o "$file" + [ "$(wc -c < "$file" | tr -d ' ')" = "$size" ] || die "size mismatch for $name" + + if [ "$name" != "checksums.txt" ]; then + sha=$(awk -v name="$name" '$2 == name { print $1 }' "$release_dir/checksums.txt" 2>/dev/null || true) + if [ -n "$sha" ]; then + actual=$(sha256sum "$file" | awk '{print $1}') + [ "$actual" = "$sha" ] || die "sha256 mismatch for $name" + fi + fi + + delete_named_assets "$assets" "$name" + encoded=$(jq -rn --arg name "$name" '$name|@uri') + log "upload $name to Gitea" + gitea_curl -sS -X POST --max-time 1800 -H 'Expect:' -F "attachment=@$file" \ + "$GITEA_BASE/api/v1/repos/$GITEA_REPO/releases/$release_id/assets?name=$encoded" >/dev/null +} + +# Gate A: macOS Apple Silicon and checksums are promoted first. +sync_asset "seal-use-darwin-arm64.tar.gz" +sync_asset "checksums.txt" + +checksums_file="$release_dir/checksums.txt" +if [ ! -s "$checksums_file" ] || ! grep -q 'seal-use-darwin-arm64.tar.gz' "$checksums_file"; then + rm -f "$checksums_file" + asset=$(github_asset "checksums.txt") + github_curl -L -H 'Accept: application/octet-stream' \ + "$(jq -r '.url' <<< "$asset")" -o "$checksums_file" +fi +arm_sha=$(awk '$2 == "seal-use-darwin-arm64.tar.gz" { print $1 }' "$checksums_file") +[ -n "$arm_sha" ] || die "checksums.txt has no macOS arm64 checksum" + +formula_response=$(github_curl -sS -H 'Accept: application/vnd.github+json' \ + "https://api.github.com/repos/$HOMEBREW_REPO/contents/Formula/seal-use.rb?ref=main") +formula_sha=$(jq -r '.sha // empty' <<< "$formula_response") +formula_file="$release_dir/seal-use.rb" +jq -r '.content' <<< "$formula_response" | tr -d '\r\n' | base64 -d > "$formula_file" + +if ! grep -q "version \"${tag#v}\"" "$formula_file" || ! grep -q "sha256 \"$arm_sha\"" "$formula_file"; then + sed -i -E "s/version \"[^\"]+\"/version \"${tag#v}\"/" "$formula_file" + sed -i -E "s/sha256 \"[^\"]+\"/sha256 \"$arm_sha\"/" "$formula_file" + formula_content=$(base64 -w0 "$formula_file") + formula_payload=$(jq -n --arg message "chore(release): bump seal-use to ${tag#v}" \ + --arg content "$formula_content" --arg sha "$formula_sha" \ + '{message:$message,content:$content,sha:$sha,branch:"main"}') + log "update Homebrew tap to ${tag#v} after ARM gate" + github_curl -sS -X PUT -H 'Content-Type: application/json' -d "$formula_payload" \ + "https://api.github.com/repos/$HOMEBREW_REPO/contents/Formula/seal-use.rb" >/dev/null +else + log "Homebrew tap already points to ${tag#v}" +fi + +# Remaining archives and raw binaries are retried by the next timer run if +# one upload fails. The Homebrew ARM path is already valid at this point. +mirror_failed=0 +for name in \ + seal-use-darwin-x64.tar.gz seal-use-linux-arm64.tar.gz seal-use-linux-x64.tar.gz seal-use-windows-x64.zip \ + seal-use-darwin-arm64 seal-use-darwin-x64 seal-use-linux-arm64 seal-use-linux-x64 seal-use-windows-x64.exe; do + if ! sync_asset "$name"; then + log "deferred asset failed: $name" + mirror_failed=1 + fi +done + +if [ "$mirror_failed" -ne 0 ]; then + log "ARM/Homebrew gate succeeded; some secondary assets will retry" + exit 2 +fi +log "release $tag fully synchronized to Gitea and Homebrew" diff --git a/ops/systemd/seal-use-release-sync.service b/ops/systemd/seal-use-release-sync.service new file mode 100644 index 0000000..9febbbc --- /dev/null +++ b/ops/systemd/seal-use-release-sync.service @@ -0,0 +1,14 @@ +[Unit] +Description=Promote GitHub releases to Gitea and Homebrew +After=network-online.target docker.service +Wants=network-online.target + +[Service] +Type=oneshot +User=dev +WorkingDirectory=/home/dev/apps/seal-use-release-sync +Environment=HOME=/home/dev +Environment=HTTP_PROXY=http://192.168.3.62:7897 +Environment=HTTPS_PROXY=http://192.168.3.62:7897 +Environment=NO_PROXY=127.0.0.1,localhost,100.82.151.105,git.ying-qing.cn +ExecStart=/home/dev/apps/seal-use-release-sync/release-sync.sh diff --git a/ops/systemd/seal-use-release-sync.timer b/ops/systemd/seal-use-release-sync.timer new file mode 100644 index 0000000..9e2d643 --- /dev/null +++ b/ops/systemd/seal-use-release-sync.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Periodic Seal Use release promotion + +[Timer] +OnBootSec=2min +OnUnitActiveSec=15min +Persistent=true +Unit=seal-use-release-sync.service + +[Install] +WantedBy=timers.target