1+ name : Sync Merged Changes to Public Repo
2+
3+ # Trigger this workflow whenever a Pull Request is merged into the internal repo.
4+ # A merge closes the PR and updates the base branch, so we can sync that branch to the public repository
5+ on :
6+ pull_request :
7+ types : [closed]
8+
9+ env :
10+ SDK_NAME : sinch-sdk-python # Adjust dynamically if needed
11+ PUBLIC_REPO_OWNER : sinch
12+
13+ # Ensure we don't have multiple syncs trying to push at the exact same time
14+ concurrency :
15+ group : sync-to-public-${{ github.repository }}-${{ github.event.pull_request.base.ref }}
16+ cancel-in-progress : true
17+
18+ jobs :
19+ sync-to-public :
20+ # Only sync when a PR is merged in the internal repo; skip merges performed by the sync app
21+ if : |
22+ github.event.pull_request.merged == true &&
23+ github.actor != 'sinch-internal-repo-sync-app[bot]' &&
24+ endsWith(github.event.repository.name, 'internal')
25+ runs-on : ubuntu-latest
26+ steps :
27+ # 1. Resolve the target branch name
28+ - name : Resolve Target Branch
29+ run : echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> "$GITHUB_ENV"
30+
31+ # 2. Checkout the internal repository (the source of truth)
32+ - name : Checkout Internal Repository
33+ uses : actions/checkout@v4
34+ with :
35+ ref : ${{ env.TARGET_BRANCH }}
36+ fetch-depth : 0 # We need full history to push correctly
37+ persist-credentials : false # We'll use the App token for pushing, not the default GITHUB
38+
39+ # 3. Generate a temporary token scoped to the PUBLIC repository
40+ - name : Generate GitHub App Token for Public Repo
41+ uses : actions/create-github-app-token@v3
42+ id : app-token
43+ with :
44+ client-id : ${{ vars.SINCH_INTERNAL_REPO_SYNC_APP_CLIENT_ID }}
45+ private-key : ${{ secrets.SINCH_INTERNAL_REPO_SYNC_APP_PRIVATE_KEY }}
46+ owner : ${{ env.PUBLIC_REPO_OWNER }}
47+ repositories : ${{ env.SDK_NAME }}
48+
49+ # 4. Push the updated branch to the public repository
50+ - name : Push to Public Repository
51+ env :
52+ SYNC_TOKEN : ${{ steps.app-token.outputs.token }}
53+ run : |
54+ echo "Syncing branch $TARGET_BRANCH to public repository..."
55+
56+ # Add the public repository as a remote using the App token
57+ git remote add public "https://x-access-token:${SYNC_TOKEN}@github.com/${PUBLIC_REPO_OWNER}/${SDK_NAME}.git"
58+
59+ # Push the specific branch that was just updated
60+ # We do NOT force push (-f) by default to prevent accidentally wiping out public history if things get out of sync.
61+ git push public HEAD:refs/heads/$TARGET_BRANCH
0 commit comments