Skip to content

Push release assets to a separate branch for CORS#195

Open
puddly wants to merge 1 commit intoNabuCasa:mainfrom
puddly:puddly/sync-releases-branch
Open

Push release assets to a separate branch for CORS#195
puddly wants to merge 1 commit intoNabuCasa:mainfrom
puddly:puddly/sync-releases-branch

Conversation

@puddly
Copy link
Copy Markdown
Collaborator

@puddly puddly commented Mar 2, 2026

Due to https://github.com/orgs/community/discussions/45446, we cannot use the GitHub API from the browser context to download release assets (even though all other API requests are permitted). To work around this until a more permanent solution is found, we will upload release assets as files to a separate releases branch that can paradoxically be fetched.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a GitHub Actions job to mirror GitHub Release assets into a dedicated releases branch, enabling browser-based fetching of assets despite GitHub API CORS restrictions.

Changes:

  • Introduces a sync-releases-branch job that downloads release assets via gh release download.
  • Copies downloaded assets into a tag-named directory on the releases branch and pushes the update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +295 to +299
sync-releases-branch:
name: Sync releases branch
needs: [release-assets]
if: github.event_name == 'release'
runs-on: ubuntu-latest
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider serializing this job with a concurrency group (e.g., per releases branch) to avoid push/rebase conflicts if multiple release workflows (or reruns) run at the same time and try to update the same branch.

Copilot uses AI. Check for mistakes.
cd releases_branch
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "${{ github.event.release.tag_name }}"
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git add "${{ github.event.release.tag_name }}" can misbehave if a tag name ever begins with - (it may be parsed as an option). Use a variable and pass paths with -- (e.g., git add -- "$tag") to make option-parsing unambiguous.

Suggested change
git add "${{ github.event.release.tag_name }}"
tag="${{ github.event.release.tag_name }}"
git add -- "$tag"

Copilot uses AI. Check for mistakes.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "${{ github.event.release.tag_name }}"
git commit --allow-empty -m "Sync release assets for ${{ github.event.release.tag_name }}"
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git commit --allow-empty will create empty commits on reruns even when the downloaded assets are unchanged, which can unnecessarily bloat the releases branch history. Consider only committing/pushing when there are staged changes (skip the commit when the working tree is clean).

Suggested change
git commit --allow-empty -m "Sync release assets for ${{ github.event.release.tag_name }}"
if ! git diff --cached --quiet; then
git commit -m "Sync release assets for ${{ github.event.release.tag_name }}"
else
echo "No changes to commit for ${{ github.event.release.tag_name }}; skipping commit."
fi

Copilot uses AI. Check for mistakes.
uses: actions/checkout@v4
with:
ref: releases
path: releases_branch
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions/checkout defaults to a shallow clone. Because this job later runs git pull --rebase, a shallow history can cause rebase/pull failures when the remote branch has advanced beyond the fetched depth. Set fetch-depth: 0 (or a sufficiently large depth) on this checkout to make the subsequent rebase reliable.

Suggested change
path: releases_branch
path: releases_branch
fetch-depth: 0

Copilot uses AI. Check for mistakes.
Comment on lines +315 to +320
sleep 10
gh release download "${{ github.event.release.tag_name }}" \
--repo "${{ github.repository }}" \
--dir artifacts_release \
--clobber

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fixed sleep 10 to wait for release assets is brittle; release asset availability can take longer and cause intermittent failures. Replace the sleep with a small retry loop/backoff around gh release download (and fail with a clear message after N attempts).

Suggested change
sleep 10
gh release download "${{ github.event.release.tag_name }}" \
--repo "${{ github.repository }}" \
--dir artifacts_release \
--clobber
max_attempts=5
delay=10
attempt=1
while [ "$attempt" -le "$max_attempts" ]; do
echo "Attempt $attempt/$max_attempts: downloading release assets for tag '${{ github.event.release.tag_name }}'..."
if gh release download "${{ github.event.release.tag_name }}" \
--repo "${{ github.repository }}" \
--dir artifacts_release \
--clobber; then
echo "Successfully downloaded release assets."
break
fi
if [ "$attempt" -eq "$max_attempts" ]; then
echo "Failed to download release assets for tag '${{ github.event.release.tag_name }}' after $max_attempts attempts." >&2
exit 1
fi
echo "Download failed; retrying in ${delay}s..."
sleep "$delay"
attempt=$((attempt + 1))
delay=$((delay * 2))
done

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants