Merge pull request #10 from yunyingk/codex/harden-release-process
🧪 CI / 🧪 Test, Type-Check & Build Validation (push) Has been cancelled
🧪 CI / 🧪 Test, Type-Check & Build Validation (push) Has been cancelled
Harden release publishing workflow
This commit is contained in:
2 files changed
+162
-28
No files matched your search
+142
-21
@@ -100,32 +100,153 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "::warning::Failed to create or find Gitea release ID. Proceeding anyway."
|
||||
exit 0
|
||||
echo "::error::Failed to create or find the Gitea release."
|
||||
exit 1
|
||||
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}" \
|
||||
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}" \
|
||||
-F "attachment=@${file}")
|
||||
STATUS=$(echo "$RESP" | tail -n 1)
|
||||
echo " [done] ${filename} -> ${STATUS}"
|
||||
"${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}"
|
||||
}
|
||||
|
||||
pids=()
|
||||
for file in dist/bin/seal-home-* dist/bin/checksums.txt; do
|
||||
[ -f "$file" ] || continue
|
||||
upload_asset "$file" &
|
||||
pids+=($!)
|
||||
delete_asset() {
|
||||
local asset_id="$1"
|
||||
curl -fsS -X DELETE \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/assets/${asset_id}" \
|
||||
>/dev/null
|
||||
}
|
||||
|
||||
upload_asset() {
|
||||
local file="$1"
|
||||
local filename file_size local_hash assets matching_id asset_id asset_url comparison_file remote_hash response_file http_code
|
||||
filename=$(basename "$file")
|
||||
file_size=$(wc -c < "$file" | tr -d ' ')
|
||||
local_hash=$(sha256sum "$file" | awk '{print $1}')
|
||||
assets=$(release_json)
|
||||
|
||||
matching_id=""
|
||||
while IFS=$'\t' read -r asset_id asset_url; do
|
||||
[ -n "$asset_id" ] || continue
|
||||
comparison_file=$(mktemp)
|
||||
if curl -fsSL --connect-timeout 10 --max-time 900 --retry 2 \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"$asset_url" -o "$comparison_file"; then
|
||||
remote_hash=$(sha256sum "$comparison_file" | awk '{print $1}')
|
||||
if [ "$remote_hash" = "$local_hash" ]; then
|
||||
matching_id="$asset_id"
|
||||
rm -f "$comparison_file"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
rm -f "$comparison_file"
|
||||
done < <(echo "$assets" | jq -r --arg name "$filename" \
|
||||
'.assets[] | select(.name == $name) | [.id, .browser_download_url] | @tsv')
|
||||
|
||||
if [ -n "$matching_id" ]; then
|
||||
echo " [keep] ${filename} already exists with the expected SHA-256"
|
||||
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
|
||||
|
||||
# Wait for all parallel uploads to complete
|
||||
for pid in "${pids[@]}"; do
|
||||
wait "$pid" || true
|
||||
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 "✓ Successfully published release assets to Gitea!"
|
||||
|
||||
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!"
|
||||
@@ -42,14 +42,28 @@ Recent commits use concise imperative subjects, often `Add ...` or `Refine ...`,
|
||||
- Run `bun run bump <new-version | patch | minor>` (automatically updates `package.json`, `.zcode-plugin/plugin.json`, `skills/seal-home/SKILL.md`, `openapi/openapi.yaml`, and bundles `dist/`).
|
||||
- Update `CHANGELOG.md` with new features and fixes.
|
||||
- Run `bun test && bun run check`.
|
||||
2. **Tag & Release**:
|
||||
- Create an annotated Git tag with a descriptive release summary:
|
||||
2. **Protected-Branch Release**:
|
||||
- Do not tag or push `master` directly. Create a release branch, commit the version bump, push it, open a PR to `master`, wait for the required CI check, and merge the PR first.
|
||||
- After the PR is merged, fast-forward the local `master`, then synchronize `home/master` before creating the tag:
|
||||
```bash
|
||||
git commit -am "Release vX.Y.Z: ..."
|
||||
git tag -a vX.Y.Z -m "🚀 Release summary text describing key changes"
|
||||
git push origin master --tags && git push home master --tags
|
||||
git switch -c codex/release-vX.Y.Z
|
||||
git add <release-files>
|
||||
git commit -m "Release vX.Y.Z: ..."
|
||||
git push origin HEAD:refs/heads/codex/release-vX.Y.Z
|
||||
gh pr create --base master --head codex/release-vX.Y.Z --title "Release vX.Y.Z: ..." --body "..."
|
||||
gh pr checks <pr-number> --watch
|
||||
gh pr merge <pr-number> --merge
|
||||
git switch master
|
||||
git pull --ff-only origin master
|
||||
git push home master
|
||||
```
|
||||
- GitHub Actions will automatically extract the tag message, append commit notes via `--generate-notes`, cross-compile all 5 target binaries in ~50s, and publish the GitHub Release.
|
||||
- Only after both `origin/master` and `home/master` contain the merged release should you create the annotated tag. Push the tag to `home` first, then to `origin`; pushing the GitHub tag last triggers the Release workflow after the Gitea tag and branch are ready:
|
||||
```bash
|
||||
git tag -a vX.Y.Z -m "🚀 Release summary text describing key changes"
|
||||
git push home refs/tags/vX.Y.Z
|
||||
git push origin refs/tags/vX.Y.Z
|
||||
```
|
||||
- GitHub Actions will automatically extract the tag message, append commit notes via `--generate-notes`, cross-compile all 5 target binaries, and publish GitHub and Gitea releases. Wait for the workflow, then verify that both releases point to the intended tag commit and contain every expected asset exactly once.
|
||||
|
||||
## Security & Configuration Tips
|
||||
|
||||
@@ -58,4 +72,3 @@ Never commit real enterprise credentials, Seal tokens, service logs, or local ge
|
||||
## Agent-Specific Instructions
|
||||
|
||||
Do not create `.codex/skills`; Codex is compatible with `.agents/skills`, and this project treats `.agents/` as authoritative. At project scope, prefer `AGENT.md` instructions when present.
|
||||
|
||||
Reference in new issue
Block a user