Skip to content

Commit 5c22c8a

Browse files
committed
Merge remote-tracking branch 'origin' into v2.2-next
2 parents de5a702 + d5701cd commit 5c22c8a

3 files changed

Lines changed: 142 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Notify Private Repo of Update
2+
3+
env:
4+
SDK_NAME: sinch-sdk-python
5+
6+
on:
7+
push:
8+
9+
jobs:
10+
ping-private:
11+
if: |
12+
github.actor != 'sinch-internal-repo-sync-app[bot]' && !endsWith(github.event.repository.name, 'internal')
13+
14+
runs-on: ubuntu-latest
15+
steps:
16+
# 1. Generate a temporary token from the GitHub App
17+
- name: Generate GitHub App Token
18+
uses: actions/create-github-app-token@v3
19+
id: app-token
20+
with:
21+
client-id: ${{ vars.SINCH_INTERNAL_REPO_SYNC_APP_CLIENT_ID }}
22+
private-key: ${{ secrets.SINCH_INTERNAL_REPO_SYNC_APP_PRIVATE_KEY }}
23+
# Explicitly request access to the internal repository:
24+
owner: ${{ github.repository_owner }}
25+
repositories: ${{ env.SDK_NAME }}-internal
26+
27+
# 2. Use that token to send the "ping" to the private repo
28+
- name: Send Repository Dispatch to Private Repo
29+
env:
30+
SYNC_TOKEN: ${{ steps.app-token.outputs.token }}
31+
run: |
32+
curl -X POST --fail-with-body \
33+
-H "Content-Type: application/json" \
34+
-H "Authorization: Bearer ${SYNC_TOKEN}" \
35+
-H "Accept: application/vnd.github.v3+json" \
36+
-H "X-GitHub-Api-Version: 2026-03-10" \
37+
https://api.github.com/repos/sinch/${SDK_NAME}-internal/dispatches \
38+
-d '{"event_type": "public_push_event"}'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Sync From Public
2+
3+
env:
4+
SDK_NAME: sinch-sdk-python
5+
6+
# Ensures only one sync runs at a time. Cancels any running sync when a new trigger arrives.
7+
concurrency:
8+
group: sync-repo-${{ github.repository }}
9+
cancel-in-progress: true
10+
11+
on:
12+
schedule:
13+
# Runs only once a day at midnight to catch any missed updates
14+
- cron: '0 0 * * *'
15+
repository_dispatch:
16+
types: [public_push_event] # Keeps your instant trigger active
17+
workflow_dispatch: # Allows manual run
18+
19+
jobs:
20+
sync-repo:
21+
if: endsWith(github.event.repository.name, 'internal')
22+
runs-on: ubuntu-latest
23+
steps:
24+
# 1. Generate a temporary installation token using the GitHub App
25+
- name: Generate GitHub App Token
26+
uses: actions/create-github-app-token@v3
27+
id: app-token
28+
with:
29+
client-id: ${{ vars.SINCH_INTERNAL_REPO_SYNC_APP_CLIENT_ID }}
30+
private-key: ${{ secrets.SINCH_INTERNAL_REPO_SYNC_APP_PRIVATE_KEY }}
31+
32+
# 2. Execute the sync using the short-lived token
33+
- name: Sync Public to Private
34+
env:
35+
SYNC_TOKEN: ${{ steps.app-token.outputs.token }}
36+
run: |
37+
# Clone the public repository as a bare repo (read-only, public)
38+
git clone --bare https://github.com/sinch/$SDK_NAME.git public_repo
39+
cd public_repo
40+
41+
# Push all branches and tags to the private repo using the App Token
42+
git push --all https://x-access-token:${SYNC_TOKEN}@github.com/sinch/${SDK_NAME}-internal.git
43+
git push --tags https://x-access-token:${SYNC_TOKEN}@github.com/sinch/${SDK_NAME}-internal.git
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)