Skip to content

Update the subtree.yml workflow file to create a PR and merge#248

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
sfeifer:fix-pcp-subtree-action
Aug 8, 2025
Merged

Update the subtree.yml workflow file to create a PR and merge#248
richm merged 1 commit intolinux-system-roles:mainfrom
sfeifer:fix-pcp-subtree-action

Conversation

@sfeifer
Copy link
Copy Markdown
Collaborator

@sfeifer sfeifer commented Aug 5, 2025

The "Sync ansible-pcp git subtree" github action no longer works as intended due to permission changes preventing directly pushing to main. This PR introduces changes to the subtree.yml workflow file to create and merge a PR, which is the accepted way of introducing changes.

Summary by Sourcery

Switch the ansible-pcp subtree sync workflow from direct pushes to a PR-based process using the GitHub CLI to comply with updated permissions.

Enhancements:

  • Replace direct subtree push with a PR-based merge process for ansible-pcp sync

CI:

  • Generate a timestamped branch for each sync and skip PR creation when there are no changes
  • Automate PR creation, squash merging, and branch cleanup via gh cli

@sfeifer sfeifer requested review from natoscott and richm as code owners August 5, 2025 19:00
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Aug 5, 2025

Reviewer's Guide

This PR converts the subtree sync workflow to a pull-request-based flow by creating a timestamped branch, detecting changes, creating and auto-merging a PR with the GitHub CLI, replacing the direct push to main.

Sequence diagram for the new subtree sync workflow via PR

sequenceDiagram
    participant Workflow as GitHub Actions Workflow
    participant Git as git
    participant GHCLI as GitHub CLI (gh)
    participant GitHub as GitHub

    Workflow->>Git: Checkout main
    Workflow->>Git: Create new branch (sync-ansible-pcp-subtree-<timestamp>)
    Workflow->>Git: Pull subtree from upstream
    Workflow->>Git: Check for changes
    alt Changes detected
        Workflow->>Git: Push branch to origin
        Workflow->>GHCLI: Create PR to main
        GHCLI->>GitHub: Create PR
        Workflow->>GHCLI: Merge PR (squash, delete branch)
        GHCLI->>GitHub: Merge PR and delete branch
    else No changes
        Workflow->>Git: Delete branch
    end
Loading

File-Level Changes

Change Details Files
Replace direct push with PR-based merge flow
  • Renamed the subtree step to reflect PR creation and added GH_TOKEN environment variable
  • Removed the direct git push to main
.github/workflows/subtree.yml
Introduce dynamic branch creation and change detection
  • Generate a timestamped BRANCH_NAME and switch to it
  • Capture BEFORE_COMMIT and compare it to HEAD to skip PR creation when no changes occur
  • Clean up the branch and exit early if no subtree changes are detected
.github/workflows/subtree.yml
Automate PR creation and squash-merge via GitHub CLI
  • Push the new branch to origin, open a PR with a standardized title and body
  • Pause briefly for PR availability, then squash-merge and delete the branch automatically
.github/workflows/subtree.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @sfeifer - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `.github/workflows/subtree.yml:26` </location>
<code_context>
           git config --global user.name "github-actions[bot]"
           git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
+          
+          BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)"
+          git checkout -b "$BRANCH_NAME"
+
</code_context>

<issue_to_address>
Branch naming may lead to collisions if jobs run within the same second.

Appending a random suffix or the GitHub run ID to the branch name will help prevent collisions from simultaneous runs.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH

          BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)"
          git checkout -b "$BRANCH_NAME"

=======

          BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)-${GITHUB_RUN_ID:-$RANDOM}"
          git checkout -b "$BRANCH_NAME"

>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `.github/workflows/subtree.yml:51` </location>
<code_context>
+          echo "Created PR: $PR_URL"
+          
+          # Wait for PR to be fully created
+          sleep 10
+
+          gh pr merge "$PR_URL" --squash --delete-branch
</code_context>

<issue_to_address>
Using a fixed sleep for PR creation is brittle.

Consider replacing the fixed sleep with polling or another method to reliably detect when the PR is ready before merging.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +25 to +28

BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Branch naming may lead to collisions if jobs run within the same second.

Appending a random suffix or the GitHub run ID to the branch name will help prevent collisions from simultaneous runs.

Suggested change
BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)-${GITHUB_RUN_ID:-$RANDOM}"
git checkout -b "$BRANCH_NAME"

echo "Created PR: $PR_URL"

# Wait for PR to be fully created
sleep 10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Using a fixed sleep for PR creation is brittle.

Consider replacing the fixed sleep with polling or another method to reliably detect when the PR is ready before merging.

@richm richm requested a review from spetrosi August 5, 2025 19:38
@richm richm merged commit 5a5641d into linux-system-roles:main Aug 8, 2025
13 of 20 checks passed
@sfeifer sfeifer deleted the fix-pcp-subtree-action branch August 11, 2025 13:57
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