Fix: Skip main branch deletion in release pipeline #27

Merged
Copilot merged 2 commits from copilot/fix-main-branch-deletion-error into main 2026-01-03 23:36:28 +00:00
Copilot commented 2026-01-03 23:27:13 +00:00 (Migrated from github.com)

Pull Request

Purpose

The release pipeline fails when promoting from main because GitHub prohibits remote deletion of the default branch. This occurs when workflow_dispatch triggers on main, which promotes to version/${VERSION} but then attempts to delete main.

Change Summary

Added conditional check in Promote and delete source step:

# Skip deletion of main branch as GitHub does not allow deleting the default branch
if [ "${SRC}" != "main" ]; then
  git push origin --delete "${SRC}"
fi

Affected workflow path: .github/workflows/release_pipeline.yml lines 318-321

Behavior:

  • SRC=main: Deletion skipped
  • SRC=dev/*, rc/*, etc.: Deletion proceeds normally

Testing Evidence

  • YAML syntax validated
  • CodeQL security scan: 0 alerts
  • Hardcoded "main" consistent with existing workflow pattern (used at lines 104, 991, 1011, 1024)

Risk and Rollback

Risk: Minimal. Single conditional prevents error case; no behavior change for non-main branches.

Rollback: Revert commit removes conditional, restores original behavior.

Checklist

  • Follows Conventional Commits
  • Tests added or updated (N/A - workflow change)
  • Documentation updated if required (inline comment added)
  • License header present where applicable (N/A)
  • Linked issue(s) referenced

Reviewer Notes

The workflow already hardcodes "main" in multiple locations (guard metadata extraction, PR creation steps). Making this configurable would require broader refactoring beyond scope of this fix.

Review and Approval

Original prompt

Currently, the workflow fails during the Enforce promotion preconditions step when attempting to delete the main branch. Since GitHub does not allow the default branch (usually main) to be deleted remotely, this causes the error. This PR resolves this issue by modifying the Promote and delete source step in .github/workflows/release_pipeline.yml.

Changes Implemented

  1. Added a conditional check to skip deletion of the main branch:
    if [ "${SRC}" != "main" ]; then
      git push origin --delete "${SRC}"
    fi
    
  2. This ensures that the workflow will only delete branches other than main, resolving the conflict with GitHub's restrictions.

Testing

The updated workflow should be tested by:

  • Running the pipeline with SRC as main to ensure that the deletion is skipped.
  • Running the pipeline with SRC as a branch other than main to ensure that deletion proceeds as expected.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

# Pull Request ## Purpose The release pipeline fails when promoting from `main` because GitHub prohibits remote deletion of the default branch. This occurs when workflow_dispatch triggers on `main`, which promotes to `version/${VERSION}` but then attempts to delete `main`. ## Change Summary Added conditional check in `Promote and delete source` step: ```bash # Skip deletion of main branch as GitHub does not allow deleting the default branch if [ "${SRC}" != "main" ]; then git push origin --delete "${SRC}" fi ``` **Affected workflow path:** `.github/workflows/release_pipeline.yml` lines 318-321 **Behavior:** - `SRC=main`: Deletion skipped - `SRC=dev/*`, `rc/*`, etc.: Deletion proceeds normally ## Testing Evidence - YAML syntax validated - CodeQL security scan: 0 alerts - Hardcoded `"main"` consistent with existing workflow pattern (used at lines 104, 991, 1011, 1024) ## Risk and Rollback **Risk:** Minimal. Single conditional prevents error case; no behavior change for non-main branches. **Rollback:** Revert commit removes conditional, restores original behavior. ## Checklist - [x] Follows Conventional Commits - [x] Tests added or updated (N/A - workflow change) - [x] Documentation updated if required (inline comment added) - [x] License header present where applicable (N/A) - [x] Linked issue(s) referenced ## Reviewer Notes The workflow already hardcodes `"main"` in multiple locations (guard metadata extraction, PR creation steps). Making this configurable would require broader refactoring beyond scope of this fix. ## Review and Approval <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Currently, the workflow fails during the `Enforce promotion preconditions` step when attempting to delete the `main` branch. Since GitHub does not allow the default branch (usually `main`) to be deleted remotely, this causes the error. This PR resolves this issue by modifying the `Promote and delete source` step in `.github/workflows/release_pipeline.yml`. > > ### Changes Implemented > 1. Added a conditional check to skip deletion of the `main` branch: > ```bash > if [ "${SRC}" != "main" ]; then > git push origin --delete "${SRC}" > fi > ``` > 2. This ensures that the workflow will only delete branches other than `main`, resolving the conflict with GitHub's restrictions. > > ### Testing > The updated workflow should be tested by: > - Running the pipeline with `SRC` as `main` to ensure that the deletion is skipped. > - Running the pipeline with `SRC` as a branch other than `main` to ensure that deletion proceeds as expected. </details> <!-- START COPILOT CODING AGENT SUFFIX --> *This pull request was created from Copilot chat.* > <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
jmiller-moko (Migrated from github.com) approved these changes 2026-01-03 23:36:17 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoCassiopeia#27