Use container host network option #109
Workflow file for this run
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
| name: Branch sync | |
| on: | |
| pull_request_target: | |
| branches: | |
| - main | |
| - ootb | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| mirror-changes: | |
| runs-on: ubuntu-latest | |
| if: github.actor != 'dependabot[bot]' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Get target branch | |
| id: target-branch | |
| run: | | |
| if [ "${{ github.base_ref }}" == "main" ]; then | |
| echo "branch=ootb" >> $GITHUB_OUTPUT | |
| else | |
| echo "branch=main" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Target branch for sync: $(cat $GITHUB_OUTPUT | grep branch | cut -d= -f2)" | |
| - name: Cherry-pick commits to target branch | |
| id: cherry-pick | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name syncbot | |
| git config user.email github-actions@github.com | |
| # Fetch all branches and the PR head (which may be from a fork) | |
| git fetch origin | |
| git fetch origin pull/${{ github.event.pull_request.number }}/head | |
| # Get the source branch name and target branch | |
| SOURCE_BRANCH="${{ github.head_ref }}" | |
| TARGET_BRANCH="${{ steps.target-branch.outputs.branch }}" | |
| SYNC_BRANCH="sync-${SOURCE_BRANCH}-to-${TARGET_BRANCH}" | |
| echo "Source branch: $SOURCE_BRANCH" | |
| echo "Target branch: $TARGET_BRANCH" | |
| echo "Sync branch: $SYNC_BRANCH" | |
| # Store branch names for next step | |
| echo "source_branch=$SOURCE_BRANCH" >> $GITHUB_OUTPUT | |
| echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT | |
| echo "sync_branch=$SYNC_BRANCH" >> $GITHUB_OUTPUT | |
| # Delete local sync branch if it exists | |
| git branch -D $SYNC_BRANCH 2>/dev/null || true | |
| # Create sync branch from target branch (will reset if remote exists) | |
| git checkout -b $SYNC_BRANCH origin/$TARGET_BRANCH | |
| # Get only the commits that are part of the PR | |
| COMMITS=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits --jq '.[].sha') | |
| # Cherry-pick each commit | |
| echo "Cherry-picking commits..." | |
| SKIPPED_COMMITS="" | |
| for commit in $COMMITS; do | |
| echo "Cherry-picking $commit" | |
| git cherry-pick $commit || { | |
| # If the cherry-pick is empty (change already exists on target), skip it | |
| if git diff --cached --quiet; then | |
| echo "Cherry-pick of $commit is empty (already applied), skipping" | |
| git cherry-pick --skip | |
| else | |
| echo "Cherry-pick of $commit conflicted, skipping" | |
| git cherry-pick --abort | |
| SKIPPED_COMMITS="$SKIPPED_COMMITS $commit" | |
| fi | |
| } | |
| done | |
| if [ -n "$SKIPPED_COMMITS" ]; then | |
| echo "skipped_commits=$SKIPPED_COMMITS" >> $GITHUB_OUTPUT | |
| echo "Some commits were skipped due to conflicts:$SKIPPED_COMMITS" | |
| fi | |
| echo "Cherry-pick complete" | |
| - name: Push sync branch and create PR | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| SOURCE_BRANCH="${{ steps.cherry-pick.outputs.source_branch }}" | |
| TARGET_BRANCH="${{ steps.cherry-pick.outputs.target_branch }}" | |
| SYNC_BRANCH="${{ steps.cherry-pick.outputs.sync_branch }}" | |
| SKIPPED="${{ steps.cherry-pick.outputs.skipped_commits }}" | |
| # Push the sync branch | |
| git push origin $SYNC_BRANCH --force | |
| echo "Successfully pushed sync branch" | |
| # Create PR using GitHub CLI | |
| PR_TITLE="[Sync -> ${TARGET_BRANCH}] $(gh pr view ${{ github.event.pull_request.number }} --json title --jq .title)" | |
| PR_BODY="Automated sync of PR #${{ github.event.pull_request.number }} from \`$SOURCE_BRANCH\` to \`$TARGET_BRANCH\` | |
| Syncbot will not be offended if the sync isn't appropriate and you close this PR. | |
| Original PR: #${{ github.event.pull_request.number }}" | |
| if [ -n "$SKIPPED" ]; then | |
| PR_BODY="$PR_BODY | |
| **Note:** The following commits were skipped due to conflicts and may need manual syncing: | |
| $(for sha in $SKIPPED; do echo "- \`$sha\`"; done)" | |
| fi | |
| # Check if PR already exists | |
| EXISTING_PR=$(gh pr list --head $SYNC_BRANCH --base $TARGET_BRANCH --json number --jq '.[0].number' || echo "") | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR already exists: #$EXISTING_PR" | |
| gh pr edit $EXISTING_PR --body "$PR_BODY" | |
| else | |
| NEW_PR=$(gh pr create --base $TARGET_BRANCH --head $SYNC_BRANCH --title "$PR_TITLE" --body "$PR_BODY" --label "sync") | |
| echo "Created new PR: $NEW_PR" | |
| fi | |
| - name: Update PR comment on success | |
| if: steps.cherry-pick.outputs.skipped_commits == '' | |
| uses: quarkusio/action-helpers@main | |
| with: | |
| action: maintain-one-comment | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| 🤖 This PR has been synchronized to the `${{ steps.cherry-pick.outputs.target_branch }}` branch. 🔄 | |
| pr-number: ${{ github.event.pull_request.number }} | |
| - name: Update PR comment on partial sync | |
| if: steps.cherry-pick.outputs.skipped_commits != '' | |
| uses: quarkusio/action-helpers@main | |
| with: | |
| action: maintain-one-comment | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| 🤖 This PR has been partially synchronized to the `${{ steps.cherry-pick.outputs.target_branch }}` branch. Some commits were skipped due to conflicts and may need manual syncing. 🔄 | |
| pr-number: ${{ github.event.pull_request.number }} |