Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/subtree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,40 @@ jobs:
with:
ref: main
fetch-depth: 0
- name: subtree merge
- name: subtree merge and create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euxo pipefail
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"

Comment on lines +25 to +28
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"

BEFORE_COMMIT=$(git rev-parse HEAD)

git subtree pull --prefix vendor/github.com/performancecopilot/ansible-pcp https://github.com/performancecopilot/ansible-pcp.git HEAD --squash
git push

if git diff --quiet "$BEFORE_COMMIT" HEAD; then
echo "No changes detected, skipping PR creation"
git checkout main
git branch -D "$BRANCH_NAME"
exit 0
fi

git push origin "$BRANCH_NAME"

PR_URL=$(gh pr create \
--title "Sync ansible-pcp git subtree" \
--body "Automated sync of ansible-pcp git subtree from upstream repository. This PR contains the latest changes from https://github.com/performancecopilot/ansible-pcp.git" \
--base main \
--head "$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.


gh pr merge "$PR_URL" --squash --delete-branch
echo "PR merged and branch deleted"
Loading