Skip to content

Commit ee1776b

Browse files
Merge pull request #3387 from puppetlabs/OSPTE-283-Forward_prs_workflow
(OSPTE-283) Adding PR forwarding workflow
2 parents b47e205 + c73d8cd commit ee1776b

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

.github/workflows/sync_private

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Forward PR to bolt-private
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [closed]
7+
branches: [main]
8+
9+
jobs:
10+
forward:
11+
if: github.event.pull_request.merged == true
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout bolt
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up variables
21+
id: vars
22+
run: |
23+
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
24+
echo "pr_title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT
25+
echo "pr_branch=forward-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
26+
27+
- name: Download PR patch
28+
run: |
29+
PATCH_URL="https://github.com/${{ github.repository }}/pull/${{ steps.vars.outputs.pr_number }}.patch"
30+
echo "Downloading patch from $PATCH_URL"
31+
status=$(curl -sSL -w "%{http_code}" -o pr.patch "$PATCH_URL")
32+
if [ "$status" -ne 200 ]; then
33+
echo "❌ Failed to download patch. HTTP status code: $status"
34+
exit 1
35+
fi
36+
37+
- name: Show patch summary
38+
run: |
39+
echo "---- PATCH START ----"
40+
cat pr.patch
41+
echo "\n---- PATCH END ----"
42+
43+
- name: Clone bolt-private
44+
run: |
45+
git clone https://x-access-token:${{ secrets.PRIVATE_REPO_PAT }}@github.com/puppetlabs/bolt-private.git ../bolt-private
46+
47+
- name: Configure Git identity
48+
run: |
49+
git config --global user.name "GitHub Actions"
50+
git config --global user.email "[email protected]"
51+
52+
- name: Apply patch to private repo (force even with conflicts)
53+
run: |
54+
cd ../bolt-private
55+
git checkout -b ${{ steps.vars.outputs.pr_branch }}
56+
57+
echo "🔁 Trying to apply patch using git am..."
58+
if git am ../bolt/pr.patch; then
59+
echo "✅ Patch applied cleanly using git am"
60+
else
61+
echo "⚠️ git am failed — falling back to manual apply"
62+
63+
patch_files=$(grep '^diff --git' ../bolt/pr.patch | awk '{print $3}' | cut -c3-)
64+
for file in $patch_files; do
65+
if [ ! -f "$file" ]; then
66+
echo "📄 Creating placeholder for missing file: $file"
67+
mkdir -p "$(dirname "$file")"
68+
touch "$file"
69+
fi
70+
done
71+
72+
echo "📌 Applying patch with git apply --reject..."
73+
git apply --reject --whitespace=fix ../bolt/pr.patch || echo "⚠️ Patch had partial conflicts"
74+
75+
echo "⚠️ This PR was generated automatically by forwarding PR #${{ steps.vars.outputs.pr_number }} from the public repository." > CONFLICT_NOTE.md
76+
echo "" >> CONFLICT_NOTE.md
77+
echo "One or more conflicts occurred when applying the patch. The patch has been added, but could not be cleanly applied." >> CONFLICT_NOTE.md
78+
echo "" >> CONFLICT_NOTE.md
79+
echo "Please manually review and implement the changes described in the patch." >> CONFLICT_NOTE.md
80+
echo "" >> CONFLICT_NOTE.md
81+
echo "⚠️ **Do NOT merge this PR as-is.** Once the patch is implemented manually, you may remove this notice." >> CONFLICT_NOTE.md
82+
83+
git add -A
84+
85+
if git diff --cached --quiet; then
86+
echo "⚠️ Patch applied nothing — creating dummy commit to allow PR"
87+
git commit --allow-empty -m "Forwarded PR #${{ steps.vars.outputs.pr_number }} (empty or conflict)"
88+
else
89+
git commit -m "Forwarded PR #${{ steps.vars.outputs.pr_number }} with manual conflict resolution required"
90+
fi
91+
fi
92+
93+
- name: Push and create PR
94+
run: |
95+
cd ../bolt-private
96+
git push origin ${{ steps.vars.outputs.pr_branch }}
97+
gh pr create \
98+
--title "[Forwarded] ${{ steps.vars.outputs.pr_title }}" \
99+
--body "This PR is an automated forward of https://github.com/${{ github.repository }}/pull/${{ steps.vars.outputs.pr_number }}.
100+
101+
If there were conflicts applying the patch, the patch has been partially or entirely rejected. A file named \`CONFLICT_NOTE.md\` has been added to this PR to guide you on resolving the issues.
102+
103+
⚠️ **Do NOT merge this PR as-is if there are conflicts**. Instead, review and manually implement the patch changes, then remove the note when done." \
104+
--head ${{ steps.vars.outputs.pr_branch }} \
105+
--base main
106+
env:
107+
GH_TOKEN: ${{ secrets.PRIVATE_REPO_PAT }}

0 commit comments

Comments
 (0)