-
Notifications
You must be signed in to change notification settings - Fork 25
Update the subtree.yml workflow file to create a PR and merge #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
richm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "PR merged and branch deleted" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.