Skip to content

Commit e090775

Browse files
Use CopyBara for repo mirroring in the CLI (#282)
* move from mirror.yaml to copybara for mirroring between OSS and internal repo * Use --force for the inital instead of --init-history * Use last rev for the inital sync GitOrigin-RevId: 4fa678afe4522b80035634cdb91086a7da73698f
1 parent 8566f03 commit e090775

3 files changed

Lines changed: 137 additions & 29 deletions

File tree

.github/workflows/copybara-pr.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: copybara-pr
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
copy:
9+
if: ${{ github.repository == 'render-oss/cli' }}
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v6
14+
- uses: actions/setup-java@v5
15+
with:
16+
distribution: oracle
17+
java-version: 21
18+
- name: Generate an app token for render-oss
19+
id: generate-token-oss
20+
uses: actions/create-github-app-token@v2
21+
with:
22+
app-id: ${{ vars.APP_ID }}
23+
private-key: ${{ secrets.APP_KEY }}
24+
owner: render-oss
25+
repositories: cli
26+
- name: Generate an app token for renderinc
27+
id: generate-token-renderinc
28+
uses: actions/create-github-app-token@v2
29+
with:
30+
app-id: ${{ vars.APP_ID }}
31+
private-key: ${{ secrets.APP_KEY }}
32+
owner: renderinc
33+
repositories: cli
34+
- name: Get GitHub App User ID
35+
id: get-user-id
36+
env:
37+
GH_TOKEN: ${{ steps.generate-token-renderinc.outputs.token }}
38+
APP_SLUG: ${{ steps.generate-token-renderinc.outputs.app-slug }}
39+
run: echo "user-id=$(gh api "/users/$APP_SLUG[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
40+
- name: Set up credentials
41+
env:
42+
RENDERINC_TOKEN: ${{ steps.generate-token-renderinc.outputs.token }}
43+
RENDER_OSS_TOKEN: ${{ steps.generate-token-oss.outputs.token }}
44+
APP_SLUG: ${{ steps.generate-token-oss.outputs.app-slug }}
45+
USER_ID: ${{ steps.get-user-id.outputs.user-id }}
46+
run: |
47+
echo "https://$USER:$RENDERINC_TOKEN@api.github.com" > ~/.git-credentials
48+
echo "https://$USER:$RENDERINC_TOKEN@github.com" >> ~/.git-credentials
49+
git config --global user.name "$APP_SLUG[bot]"
50+
git config --global user.email "$USER_ID+$APP_SLUG[bot]@users.noreply.github.com"
51+
git config --global url."https://$USER:${RENDERINC_TOKEN}@github.com/renderinc".insteadOf "git@github.com:renderinc"
52+
git config --global url."https://$USER:${RENDERINC_TOKEN}@github.com/renderinc".insteadOf "https://github.com/renderinc"
53+
git config --global url."https://$USER:${RENDER_OSS_TOKEN}@github.com/render-oss".insteadOf "git@github.com:render-oss"
54+
git config --global url."https://$USER:${RENDER_OSS_TOKEN}@github.com/render-oss".insteadOf "https://github.com/render-oss"
55+
- name: Set up copybara
56+
run: |
57+
wget https://github.com/google/copybara/releases/download/v20251215/copybara_deploy.jar
58+
java -jar copybara_deploy.jar version
59+
java -jar copybara_deploy.jar validate copy.bara.sky
60+
- name: Run workflow
61+
env:
62+
RENDERINC_TOKEN: ${{ steps.generate-token-renderinc.outputs.token }}
63+
PR_NUMBER: ${{ github.event.pull_request.number }}
64+
run: |
65+
java -jar copybara_deploy.jar copy.bara.sky pr $PR_NUMBER \
66+
--git-destination-url "https://$USER:$RENDERINC_TOKEN@github.com/renderinc/cli.git"

.github/workflows/mirror.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

copy.bara.sky

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
SOT_REPO = "https://github.com/renderinc/cli.git"
2+
SOT_BRANCH = "main"
3+
DESTINATION_REPO = "https://github.com/render-oss/cli.git"
4+
DESTINATION_BRANCH = "main"
5+
6+
DESTINATION_FILES = [
7+
".github/**",
8+
"bin/**",
9+
"cmd/**",
10+
"e2e/**",
11+
"pkg/**",
12+
".gitignore",
13+
".golangci.yml",
14+
".goreleaser.yml",
15+
"AGENTS.md",
16+
"LICENSE",
17+
"README.md",
18+
"SECURITY.md",
19+
"go.mod",
20+
"go.sum",
21+
"main.go",
22+
"copy.bara.sky",
23+
"prek.toml",
24+
]
25+
26+
DESTINATION_FILES_EXCLUDE = [
27+
".github/workflows/copybara-push.yaml",
28+
]
29+
30+
DEFAULT_COMITTER = "Render Engineering <dev-public@render.com>"
31+
32+
# Push workflow
33+
core.workflow(
34+
name = "push",
35+
origin = git.github_origin(
36+
url = SOT_REPO,
37+
ref = SOT_BRANCH,
38+
),
39+
destination = git.github_destination(
40+
url = DESTINATION_REPO,
41+
push = DESTINATION_BRANCH,
42+
),
43+
origin_files = glob(DESTINATION_FILES, exclude = DESTINATION_FILES_EXCLUDE),
44+
authoring = authoring.pass_thru(default = DEFAULT_COMITTER),
45+
mode = "ITERATIVE",
46+
transformations = [
47+
metadata.restore_author("ORIGINAL_AUTHOR", search_all_changes = True),
48+
],
49+
)
50+
51+
# Pull Request workflow
52+
core.workflow(
53+
name = "pr",
54+
origin = git.github_pr_origin(
55+
url = DESTINATION_REPO,
56+
branch = DESTINATION_BRANCH,
57+
),
58+
destination = git.github_pr_destination(
59+
url = SOT_REPO,
60+
destination_ref = SOT_BRANCH,
61+
),
62+
destination_files = glob(DESTINATION_FILES, exclude = DESTINATION_FILES_EXCLUDE),
63+
origin_files = glob(["**"]),
64+
authoring = authoring.pass_thru(default = DEFAULT_COMITTER),
65+
mode = "CHANGE_REQUEST",
66+
set_rev_id = False,
67+
transformations = [
68+
metadata.save_author("ORIGINAL_AUTHOR"),
69+
metadata.expose_label("GITHUB_PR_NUMBER", new_name = "Closes", separator = DESTINATION_REPO.replace("https://github.com/", " ").replace(".git", "#")),
70+
],
71+
)

0 commit comments

Comments
 (0)