feat: sync updates.xml to main via PR (respects branch protection)

Creates chore/update-xml-<version> branch, updates file, creates PR,
auto-merges, cleans up branch. Replaces direct API file push.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-04-22 03:16:21 -05:00
parent d146b5d51e
commit c3e989d150
@@ -592,26 +592,68 @@ jobs:
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>" || true
git push || true
# Also update updates.xml on main via Gitea API (git push blocked by branch protection)
# Sync updates.xml to main via PR (respects branch protection)
if [ "$CURRENT_BRANCH" != "main" ]; then
GA_TOKEN="${{ secrets.GA_TOKEN }}"
API="${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}"
PR_BRANCH="chore/update-xml-${VERSION}"
FILE_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
"${API}/contents/updates.xml?ref=main" | jq -r '.sha // empty')
# Create branch from main
MAIN_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
"${API}/branches/main" | jq -r '.commit.sha // empty')
if [ -n "$FILE_SHA" ]; then
CONTENT=$(base64 -w0 updates.xml)
curl -sf -X PUT -H "Authorization: token ${GA_TOKEN}" \
if [ -n "$MAIN_SHA" ]; then
curl -sf -X POST -H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/contents/updates.xml" \
-d "$(jq -n \
--arg content "$CONTENT" \
--arg sha "$FILE_SHA" \
--arg msg "chore: update stable channel to ${VERSION} on main [skip ci]" \
--arg branch "main" \
'{content: $content, sha: $sha, message: $msg, branch: $branch}'
)" > /dev/null && echo "updates.xml synced to main via API" || echo "WARNING: failed to sync updates.xml to main"
"${API}/branches" \
-d "$(jq -n --arg name "$PR_BRANCH" --arg sha "$MAIN_SHA" \
'{new_branch_name: $name, old_branch_name: "main"}')" > /dev/null 2>&1 || true
# Update updates.xml on the PR branch
FILE_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
"${API}/contents/updates.xml?ref=${PR_BRANCH}" | jq -r '.sha // empty')
if [ -n "$FILE_SHA" ]; then
CONTENT=$(base64 -w0 updates.xml)
curl -sf -X PUT -H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/contents/updates.xml" \
-d "$(jq -n \
--arg content "$CONTENT" \
--arg sha "$FILE_SHA" \
--arg msg "chore: update stable channel to ${VERSION} [skip ci]" \
--arg branch "$PR_BRANCH" \
'{content: $content, sha: $sha, message: $msg, branch: $branch}'
)" > /dev/null 2>&1
# Create PR
PR_URL=$(curl -sf -X POST -H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/pulls" \
-d "$(jq -n \
--arg title "chore: update updates.xml for ${VERSION} [skip ci]" \
--arg head "$PR_BRANCH" \
--arg base "main" \
--arg body "Auto-generated by release workflow. Updates updates.xml with SHA-256 and download URLs for ${VERSION}." \
'{title: $title, head: $head, base: $base, body: $body}'
)" | jq -r '.number // empty')
# Auto-merge the PR
if [ -n "$PR_URL" ]; then
curl -sf -X POST -H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/pulls/${PR_URL}/merge" \
-d '{"Do":"merge","merge_message_field":"chore: update updates.xml for '"${VERSION}"' [skip ci]"}' > /dev/null 2>&1 \
&& echo "updates.xml synced to main via PR #${PR_URL}" \
|| echo "PR #${PR_URL} created but auto-merge failed — merge manually"
# Cleanup: delete PR branch
curl -sf -X DELETE -H "Authorization: token ${GA_TOKEN}" \
"${API}/branches/${PR_BRANCH}" > /dev/null 2>&1 || true
else
echo "WARNING: failed to create PR for updates.xml sync"
fi
fi
fi
fi
fi