Skip to content

Commit 5a5641d

Browse files
sfeiferrichm
authored andcommitted
Update the subtree.yml workflow file to create a PR and merge
1 parent c5a412d commit 5a5641d

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

.github/workflows/subtree.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,40 @@ jobs:
1515
with:
1616
ref: main
1717
fetch-depth: 0
18-
- name: subtree merge
18+
- name: subtree merge and create PR
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1921
run: |
2022
set -euxo pipefail
2123
git config --global user.name "github-actions[bot]"
2224
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
25+
26+
BRANCH_NAME="sync-ansible-pcp-subtree-$(date +%Y%m%d-%H%M%S)"
27+
git checkout -b "$BRANCH_NAME"
28+
29+
BEFORE_COMMIT=$(git rev-parse HEAD)
30+
2331
git subtree pull --prefix vendor/github.com/performancecopilot/ansible-pcp https://github.com/performancecopilot/ansible-pcp.git HEAD --squash
24-
git push
32+
33+
if git diff --quiet "$BEFORE_COMMIT" HEAD; then
34+
echo "No changes detected, skipping PR creation"
35+
git checkout main
36+
git branch -D "$BRANCH_NAME"
37+
exit 0
38+
fi
39+
40+
git push origin "$BRANCH_NAME"
41+
42+
PR_URL=$(gh pr create \
43+
--title "Sync ansible-pcp git subtree" \
44+
--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" \
45+
--base main \
46+
--head "$BRANCH_NAME")
47+
48+
echo "Created PR: $PR_URL"
49+
50+
# Wait for PR to be fully created
51+
sleep 10
52+
53+
gh pr merge "$PR_URL" --squash --delete-branch
54+
echo "PR merged and branch deleted"

0 commit comments

Comments
 (0)