Skip to content

fix(ci): remove direct push to main from release workflow#556

Merged
grunch merged 3 commits into
mainfrom
fix/release-workflow-no-push-main
Apr 1, 2026
Merged

fix(ci): remove direct push to main from release workflow#556
grunch merged 3 commits into
mainfrom
fix/release-workflow-no-push-main

Conversation

@mostronatorcoder

@mostronatorcoder mostronatorcoder Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The release workflow was failing because it tried to git push origin main directly, which is now blocked by the branch protection rule (PRs required).

remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: Changes must be made through a pull request.

Solution

Instead of pushing directly to main, the workflow now opens a PR automatically after publishing the release.

New release flow

  1. Push a tag v1.2.3 → workflow triggers
  2. Build → APKs signed → GitHub Release published
  3. Workflow creates branch chore/changelog-v1.2.3 with updated CHANGELOG.md + version bump in pubspec.yaml
  4. Workflow opens a PR automatically
  5. Merge the PR with 1 click → CHANGELOG.md and pubspec.yaml land on main

The PR can be merged hours or days after the release — it has no effect on the published release or APKs.

What changed

  • Removed the step that did git checkout main + git push origin main
  • Added a new "Open changelog PR" step that:
    • Creates branch chore/changelog-vX.Y.Z from the tag
    • Commits CHANGELOG.md update + version bump
    • Opens a PR via gh pr create
  • Added pull-requests: write permission (needed to open PRs)

The release workflow was pushing changelog + version bump directly to
main, which fails now that main has branch protection (PRs required).

Removed the 'Commit changelog and version bump to main' step entirely.
Version bumps and CHANGELOG updates should be done in the release PR
before tagging, not by the CI after the fact.

The workflow now only: builds, signs, and publishes the release.
…main

Instead of pushing changelog + version bump directly to main (which is
now blocked by branch protection), the workflow:

1. Builds and publishes the release as before
2. Creates a branch chore/changelog-vX.Y.Z from the tag
3. Commits the CHANGELOG.md update + version bump there
4. Opens a PR automatically via gh pr create

The PR can be merged with one click — no manual changelog work needed.
@grunch

grunch commented Apr 1, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 07a8dc4e-b744-4530-94d5-98227ca27415

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The release workflow is modified to replace direct commits to main with a pull request-based approach. The workflow now creates a dedicated branch, bumps version and regenerates changelog, then opens a PR against main instead of pushing directly.

Changes

Cohort / File(s) Summary
Release Workflow Configuration
.github/workflows/release.yml
Modified workflow permission to allow PR creation. Replaced direct push-to-main step with branch creation (chore/changelog-${TAG}), version bump, changelog regeneration, and automated PR opening via gh pr create. Removed direct tag checkout step.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A branch for each change, a PR to review,
No more sneaky pushes—transparency's true!
Hoppy releases with care and with grace,
The changelog dances in its rightful place.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the primary change: removing direct push to main from the release workflow. This directly addresses the core problem of the protected branch protection failure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/release-workflow-no-push-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/release.yml:
- Around line 348-355: The multiline string passed to gh pr create via the
--body flag is mis-indented inside the YAML run: | block and breaks parsing; fix
by constructing the PR body without relying on inline indentation — e.g., write
the body to a file and call gh pr create --body-file pointing to that file (or
use a properly indented here-doc) so the content for --body (which includes TAG,
VERSION, BUILD, CHANGELOG.md, pubspec.yaml) is preserved exactly and the YAML
block indentation is not violated.
- Around line 284-285: The changelog PR step uses a deterministic
BRANCH="chore/changelog-${TAG}" and always runs git push and gh pr create, which
fails on reruns; make this step idempotent by first checking whether the branch
already exists or whether there are any file changes to commit (e.g., run git
fetch && git ls-remote or git rev-parse for BRANCH and/or git diff --exit-code)
and exit successfully if no changes, and if the branch exists, detect an open PR
for that branch via the GitHub CLI (gh pr list/gh api) and skip creating a new
PR; update the workflow to short-circuit before running git push and gh pr
create when either no-op or existing PR is detected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fd736f88-be3d-4bd1-acb5-845d9f35ad52

📥 Commits

Reviewing files that changed from the base of the PR and between 2518c37 and 9b71706.

📒 Files selected for processing (1)
  • .github/workflows/release.yml

Comment on lines +284 to +285
BRANCH="chore/changelog-${TAG}"
DATESTAMP=$(date -u +"%Y-%m-%d")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '280,290p'

Repository: MostroP2P/mobile

Length of output: 518


🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '340,365p'

Repository: MostroP2P/mobile

Length of output: 1225


🏁 Script executed:

wc -l .github/workflows/release.yml

Repository: MostroP2P/mobile

Length of output: 93


🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '275,285p'

Repository: MostroP2P/mobile

Length of output: 533


🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '355,375p'

Repository: MostroP2P/mobile

Length of output: 672


🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '270,295p'

Repository: MostroP2P/mobile

Length of output: 1333


🏁 Script executed:

cat -n .github/workflows/release.yml | sed -n '343,358p'

Repository: MostroP2P/mobile

Length of output: 849


Make the changelog PR step idempotent.

Line 284 makes the branch name deterministic, but the step at lines 277–359 never short-circuits on an existing PR or a no-op changelog/version update. On rerun for the same tag, git push and gh pr create will fail, causing the step to fail and blocking the "Trigger desktop builds" step at line 361. Since the GitHub release is published before this step (line 275), a rerun failure can suppress the desktop dispatch after the release is already public.

♻️ Minimal guard rails
           BRANCH="chore/changelog-${TAG}"
+          EXISTING_PR=$(gh pr list --state open --head "$BRANCH" --json url --jq '.[0].url // empty')
+          if [ -n "$EXISTING_PR" ]; then
+            echo "Changelog PR already exists: $EXISTING_PR"
+            exit 0
+          fi
           DATESTAMP=$(date -u +"%Y-%m-%d")
…
           git add pubspec.yaml CHANGELOG.md
-          git diff --cached --quiet || git commit -m "chore: update changelog and version for ${TAG}"
+          if git diff --cached --quiet; then
+            echo "No changelog/version changes to propose."
+            exit 0
+          fi
+          git commit -m "chore: update changelog and version for ${TAG}"
           git push origin "$BRANCH"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/release.yml around lines 284 - 285, The changelog PR step
uses a deterministic BRANCH="chore/changelog-${TAG}" and always runs git push
and gh pr create, which fails on reruns; make this step idempotent by first
checking whether the branch already exists or whether there are any file changes
to commit (e.g., run git fetch && git ls-remote or git rev-parse for BRANCH
and/or git diff --exit-code) and exit successfully if no changes, and if the
branch exists, detect an open PR for that branch via the GitHub CLI (gh pr
list/gh api) and skip creating a new PR; update the workflow to short-circuit
before running git push and gh pr create when either no-op or existing PR is
detected.

Comment thread .github/workflows/release.yml Outdated
Comment on lines +348 to +355
gh pr create \
--title "chore: update changelog and version for ${TAG}" \
--body "Automated changelog and version bump generated by the release workflow for \`${TAG}\`.

- Updates \`CHANGELOG.md\` with commits since the previous tag
- Bumps \`version:\` in \`pubspec.yaml\` to \`${VERSION}+${BUILD}\`

**Merge this after the release is published.**" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's locate and read the release.yml file
find . -path "*/.github/workflows/release.yml" -type f

Repository: MostroP2P/mobile

Length of output: 91


🏁 Script executed:

# Read the file around lines 348-355 with context
sed -n '340,365p' ./.github/workflows/release.yml | cat -n

Repository: MostroP2P/mobile

Length of output: 1225


🏁 Script executed:

# Need to see more context - find where this `run: |` block starts
sed -n '320,365p' ./.github/workflows/release.yml | cat -n

Repository: MostroP2P/mobile

Length of output: 1882


🏁 Script executed:

# Let me find the run: | statement that contains this code
sed -n '290,365p' ./.github/workflows/release.yml | cat -n

Repository: MostroP2P/mobile

Length of output: 3335


🏁 Script executed:

# Need to find the run: | statement - let me look further back
sed -n '270,365p' ./.github/workflows/release.yml | cat -n

Repository: MostroP2P/mobile

Length of output: 4283


🏁 Script executed:

# Let me examine the exact indentation by looking at the raw bytes
sed -n '278,290p' ./.github/workflows/release.yml | od -c | head -50

Repository: MostroP2P/mobile

Length of output: 100


🏁 Script executed:

# Use cat -A to show whitespace characters
sed -n '278,365p' ./.github/workflows/release.yml | cat -A

Repository: MostroP2P/mobile

Length of output: 3367


🏁 Script executed:

# Let me verify the indentation pattern more carefully
# Count spaces for key lines
python3 << 'EOF'
import re

lines = [
    ("          git config user.name", "baseline"),
    ("            --body \"Automated changelog", "first body line"),
    ("  - Updates", "reduced indent content"),
    ("  - Bumps", "reduced indent content"),
    ("  **Merge", "reduced indent content"),
    ("            --base main", "continuation line"),
]

for line, desc in lines:
    match = re.match(r'^( *)', line)
    if match:
        spaces = len(match.group(1))
        print(f"{spaces:2d} spaces: {desc:25s} | {line}")
EOF

Repository: MostroP2P/mobile

Length of output: 420


Fix multiline string indentation in the PR body; the current indentation breaks the workflow file.

The --body text inside the gh pr create command drops from 12 spaces to 2 spaces starting at line 81 (the - Updates line). In YAML's run: | literal block scalar, all content must maintain at least the baseline indentation (10 spaces). Lines with only 2 spaces are parsed as YAML root-level keys rather than shell content, causing a parse error when GitHub Actions loads the workflow.

🛠️ Safer body construction using file
          # Open PR via GitHub CLI
-          gh pr create \
-            --title "chore: update changelog and version for ${TAG}" \
-            --body "Automated changelog and version bump generated by the release workflow for \`${TAG}\`.
-
-  - Updates \`CHANGELOG.md\` with commits since the previous tag
-  - Bumps \`version:\` in \`pubspec.yaml\` to \`${VERSION}+${BUILD}\`
-
-  **Merge this after the release is published.**" \
-            --base main \
-            --head "$BRANCH"
+          cat > PR_BODY.md <<EOF
+          Automated changelog and version bump generated by the release workflow for \`${TAG}\`.
+
+          - Updates \`CHANGELOG.md\` with commits since the previous tag
+          - Bumps \`version:\` in \`pubspec.yaml\` to \`${VERSION}+${BUILD}\`
+
+          **Merge this after the release is published.**
+          EOF
+
+          gh pr create \
+            --title "chore: update changelog and version for ${TAG}" \
+            --body-file PR_BODY.md \
+            --base main \
+            --head "$BRANCH"
🧰 Tools
🪛 YAMLlint (1.38.0)

[error] 352-352: syntax error: expected , but found '-'

(syntax)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/release.yml around lines 348 - 355, The multiline string
passed to gh pr create via the --body flag is mis-indented inside the YAML run:
| block and breaks parsing; fix by constructing the PR body without relying on
inline indentation — e.g., write the body to a file and call gh pr create
--body-file pointing to that file (or use a properly indented here-doc) so the
content for --body (which includes TAG, VERSION, BUILD, CHANGELOG.md,
pubspec.yaml) is preserved exactly and the YAML block indentation is not
violated.

- Check remote branch existence before pushing (idempotent rerun)
- Detect existing open PR and skip silently
- Use --body-file instead of inline --body to avoid YAML indent issues
- Skip PR creation if no staged changes
@grunch grunch merged commit b0445a4 into main Apr 1, 2026
2 checks passed
@grunch grunch deleted the fix/release-workflow-no-push-main branch April 1, 2026 19:29
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.

1 participant