Skip to content

Commit 0c98e8d

Browse files
chore: add mirror-back workflow (#752)
Mirrors non-sync-app public commits back to the private repo. Pushed manually because GitHub App tokens cannot create workflow files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ca5cdac commit 0c98e8d

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/mirror-back.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Mirror Public Commits Back to Private
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
inputs:
8+
dry_run:
9+
description: 'Print the proposed private PR body without creating branches or PRs.'
10+
required: false
11+
type: boolean
12+
default: true
13+
public_sha:
14+
description: 'Specific public commit SHA to replay or preview. Defaults to the workflow SHA.'
15+
required: false
16+
type: string
17+
default: ''
18+
private_repo:
19+
description: 'Private repository that receives replay PRs.'
20+
required: false
21+
type: string
22+
default: 'microsoft-foundry/foundry-samples-pr'
23+
24+
permissions:
25+
contents: read
26+
27+
concurrency:
28+
group: mirror-back-${{ github.ref }}
29+
cancel-in-progress: false
30+
31+
jobs:
32+
mirror:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Resolve repositories
36+
id: repos
37+
env:
38+
PRIVATE_REPO_INPUT: ${{ github.event.inputs.private_repo || 'microsoft-foundry/foundry-samples-pr' }}
39+
run: |
40+
set -euo pipefail
41+
private_owner="${PRIVATE_REPO_INPUT%%/*}"
42+
private_name="${PRIVATE_REPO_INPUT#*/}"
43+
if [[ -z "$private_owner" || -z "$private_name" || "$private_owner" == "$private_name" ]]; then
44+
echo "::error::private_repo must be owner/name; got '$PRIVATE_REPO_INPUT'"
45+
exit 1
46+
fi
47+
echo "private_repo=$PRIVATE_REPO_INPUT" >> "$GITHUB_OUTPUT"
48+
echo "private_owner=$private_owner" >> "$GITHUB_OUTPUT"
49+
echo "private_name=$private_name" >> "$GITHUB_OUTPUT"
50+
51+
- name: Validate App secrets
52+
env:
53+
SYNC_APP_ID: ${{ secrets.SYNC_APP_ID }}
54+
SYNC_APP_PRIVATE_KEY: ${{ secrets.SYNC_APP_PRIVATE_KEY }}
55+
run: |
56+
set -euo pipefail
57+
if [[ -z "$SYNC_APP_ID" || -z "$SYNC_APP_PRIVATE_KEY" ]]; then
58+
echo "::error::SYNC_APP_ID and SYNC_APP_PRIVATE_KEY must be configured on the public repository before mirror-back can mint a private-repo App token."
59+
exit 1
60+
fi
61+
62+
- name: Generate private repo App token
63+
id: app-token
64+
uses: actions/create-github-app-token@v1
65+
with:
66+
app-id: ${{ secrets.SYNC_APP_ID }}
67+
private-key: ${{ secrets.SYNC_APP_PRIVATE_KEY }}
68+
owner: ${{ steps.repos.outputs.private_owner }}
69+
repositories: ${{ steps.repos.outputs.private_name }}
70+
71+
- name: Checkout public repo
72+
uses: actions/checkout@v4
73+
with:
74+
path: public-repo
75+
fetch-depth: 0
76+
77+
- name: Checkout private repo
78+
uses: actions/checkout@v4
79+
with:
80+
repository: ${{ steps.repos.outputs.private_repo }}
81+
token: ${{ steps.app-token.outputs.token }}
82+
path: private-repo
83+
fetch-depth: 0
84+
ref: main
85+
86+
- name: Mirror non-sync-App public commits
87+
env:
88+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
89+
PUBLIC_REPO_PATH: ${{ github.workspace }}/public-repo
90+
PRIVATE_REPO_PATH: ${{ github.workspace }}/private-repo
91+
PUBLIC_REPO: ${{ github.repository }}
92+
PRIVATE_REPO: ${{ steps.repos.outputs.private_repo }}
93+
BEFORE_SHA: ${{ github.event.before || '' }}
94+
AFTER_SHA: ${{ github.sha }}
95+
PUBLIC_SHA: ${{ github.event.inputs.public_sha || '' }}
96+
DRY_RUN: ${{ github.event.inputs.dry_run == 'true' && '1' || '0' }}
97+
run: bash public-repo/.github/scripts/mirror-back.sh

0 commit comments

Comments
 (0)