|
| 1 | +name: Sync Merge of PR to Private Repo |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + merged-pr: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Check out the code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: '3.x' |
| 19 | + |
| 20 | + - name: Install PyGithub |
| 21 | + run: pip install PyGithub |
| 22 | + |
| 23 | + - name: Echo environment variables |
| 24 | + run: | |
| 25 | + echo "GITHUB_TOKEN=${{ secrets.PRIVATE_REPO_TOKEN }}" |
| 26 | + echo "PUBLIC_PR_NUMBER=${{ github.event.pull_request.number }}" |
| 27 | + echo "PRIVATE_REPO_OWNER=${{ secrets.PRIVATE_REPO_OWNER }}" |
| 28 | + echo "PRIVATE_REPO_NAME=${{ secrets.PRIVATE_REPO_NAME }}" |
| 29 | + |
| 30 | + - name: Merge PR in Private Repo |
| 31 | + if: github.event.pull_request.merged == true |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${{ secrets.PRIVATE_REPO_TOKEN }} |
| 34 | + PRIVATE_REPO_OWNER: ${{ secrets.PRIVATE_REPO_OWNER }} |
| 35 | + PRIVATE_REPO_NAME: ${{ secrets.PRIVATE_REPO_NAME }} |
| 36 | + PUBLIC_PR_NUMBER: ${{ github.event.pull_request.number }} |
| 37 | + run: | |
| 38 | + python -c " |
| 39 | + import os |
| 40 | + from github import Github |
| 41 | + |
| 42 | + # Load environment variables |
| 43 | + token = os.getenv('GITHUB_TOKEN') |
| 44 | + private_repo_owner = os.getenv('PRIVATE_REPO_OWNER') |
| 45 | + private_repo_name = os.getenv('PRIVATE_REPO_NAME') |
| 46 | + public_pr_number = os.getenv('PUBLIC_PR_NUMBER') |
| 47 | + |
| 48 | + # Initialize GitHub client |
| 49 | + g = Github(token) |
| 50 | + private_repo = g.get_repo(f'{private_repo_owner}/{private_repo_name}') |
| 51 | + |
| 52 | + # Generate branch name |
| 53 | + branch_name = f'pr-sync-{public_pr_number}' |
| 54 | + |
| 55 | + # Find the existing PR in the private repo |
| 56 | + prs = private_repo.get_pulls(state='open', head=f'{private_repo_owner}:{branch_name}') |
| 57 | + if prs.totalCount > 0: |
| 58 | + pr = prs[0] |
| 59 | + # Merge the PR if it exists |
| 60 | + pr.merge(commit_message='Auto Merging PR from docs-content to deploy') |
| 61 | + " |
0 commit comments