Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Syncs packages/scramjet/ in this monorepo (source of truth) to the
# standalone public repo MercuryWorkshop/scramjet, on pushes to main.
#
# How it works:
# - Pushes to main migrate the subdir state to main in
# MercuryWorkshop/scramjet via the `browserjs_to_scramjet` workflow in
# copy.bara.sky. Pushes that don't touch packages/scramjet/ are cheap no-ops.
# - Loop prevention: commits that already carry a `Scramjet-RevId:` trailer
# arrived via the reverse sync (public -> monorepo) and are skipped.
#
# Required setup (once, in BOTH HeyPuter/browser.js and
# MercuryWorkshop/scramjet): create a fine-grained PAT (or classic PAT with
# `repo` + `workflow` scopes) owned by an account with push access to both
# repos, and store it as the Actions secret COPYBARA_SYNC_TOKEN.

name: Sync to public scramjet

on:
push:
branches:
- main
workflow_dispatch:

concurrency:
group: copybara-forward
cancel-in-progress: false

permissions:
contents: write

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout monorepo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.COPYBARA_SYNC_TOKEN }}

- name: Sync main to MercuryWorkshop/scramjet
env:
SYNC_TOKEN: ${{ secrets.COPYBARA_SYNC_TOKEN }}
run: |
set -euo pipefail
echo "::add-mask::$SYNC_TOKEN"

# Loop guard: skip commits that came from the reverse sync.
MSG="$(git log -1 --format=%B origin/main)"
if grep -q 'Scramjet-RevId:' <<<"$MSG"; then
echo "Skipping: tip already carries Scramjet-RevId (reverse-synced)."
exit 0
fi
if grep -q '\[skip copybara\]' <<<"$MSG"; then
echo "Skipping: tip carries [skip copybara]."
exit 0
fi

set +e
docker run --rm \
-v "$GITHUB_WORKSPACE:/workspace" -w /workspace \
gcr.io/copybara/copybara:latest \
migrate copy.bara.sky browserjs_to_scramjet \
--git-origin-url "https://x-access-token:${SYNC_TOKEN}@github.com/HeyPuter/browser.js.git" \
--git-destination-url "https://x-access-token:${SYNC_TOKEN}@github.com/MercuryWorkshop/scramjet.git"
CODE=$?
set -e
if [ "$CODE" -eq 4 ]; then
echo "Already in sync."
exit 0
fi
exit "$CODE"
27 changes: 27 additions & 0 deletions copy.bara.sky
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Usage (manual):
# copybara migrate copy.bara.sky browserjs_to_scramjet \
# --git-origin-ref my-branch --git-destination-fetch my-branch \
# --git-destination-push my-branch
SUBDIR = "packages/scramjet"

core.workflow(
name = "browserjs_to_scramjet",
origin = git.origin(
url = "https://github.com/HeyPuter/browser.js",
ref = "main",
),
destination = git.destination(
url = "https://github.com/MercuryWorkshop/scramjet",
fetch = "main",
push = "main",
),
origin_files = glob([SUBDIR + "/**"]),
destination_files = glob(["**"]),
transformations = [
core.move(SUBDIR, ""),
],
authoring = authoring.pass_thru("copybara-puter <copybara@puter.com>"),
mode = "ITERATIVE",
reversible_check = True,
custom_rev_id = "Browserjs-RevId",
)
81 changes: 81 additions & 0 deletions packages/scramjet/.github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Syncs the standalone public repo MercuryWorkshop/scramjet back into the
# monorepo (HeyPuter/browser.js, under packages/scramjet/), on pushes to main.
#
# NOTE on location: this file lives at
# packages/scramjet/.github/workflows/sync.yml
# in the monorepo, which Copybara maps to
# .github/workflows/sync.yml
# in MercuryWorkshop/scramjet. It is guarded to run ONLY in
# MercuryWorkshop/scramjet (the synced copy sitting in the monorepo never runs).
#
# How it works:
# - Pushes to main migrate the repo state to main in HeyPuter/browser.js via
# the `scramjet_to_browserjs` workflow in copy.bara.sky (nested under
# packages/scramjet/).
# - Loop prevention: commits that already carry a `Browserjs-RevId:` trailer
# arrived via the forward sync (monorepo -> public) and are skipped.
#
# Required setup (once, in BOTH HeyPuter/browser.js and
# MercuryWorkshop/scramjet): create a fine-grained PAT (or classic PAT with
# `repo` + `workflow` scopes) owned by an account with push access to both
# repos, and store it as the Actions secret COPYBARA_SYNC_TOKEN.

name: Sync to monorepo

on:
push:
branches:
- main
workflow_dispatch:

concurrency:
group: copybara-reverse
cancel-in-progress: false

permissions:
contents: write

jobs:
sync:
# Only run in the public repo; the copy synced into the monorepo stays idle.
if: github.repository == 'MercuryWorkshop/scramjet'
runs-on: ubuntu-latest
steps:
- name: Checkout public repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.COPYBARA_SYNC_TOKEN }}

- name: Sync main to HeyPuter/browser.js
env:
SYNC_TOKEN: ${{ secrets.COPYBARA_SYNC_TOKEN }}
run: |
set -euo pipefail
echo "::add-mask::$SYNC_TOKEN"

# Loop guard: skip commits that came from the forward sync.
MSG="$(git log -1 --format=%B origin/main)"
if grep -q 'Browserjs-RevId:' <<<"$MSG"; then
echo "Skipping: tip already carries Browserjs-RevId (forward-synced)."
exit 0
fi
if grep -q '\[skip copybara\]' <<<"$MSG"; then
echo "Skipping: tip carries [skip copybara]."
exit 0
fi

set +e
docker run --rm \
-v "$GITHUB_WORKSPACE:/workspace" -w /workspace \
gcr.io/copybara/copybara:latest \
migrate copy.bara.sky scramjet_to_browserjs \
--git-origin-url "https://x-access-token:${SYNC_TOKEN}@github.com/MercuryWorkshop/scramjet.git" \
--git-destination-url "https://x-access-token:${SYNC_TOKEN}@github.com/HeyPuter/browser.js.git"
CODE=$?
set -e
if [ "$CODE" -eq 4 ]; then
echo "Already in sync."
exit 0
fi
exit "$CODE"
26 changes: 26 additions & 0 deletions packages/scramjet/copy.bara.sky
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Usage (manual, from the public repo root):
# copybara migrate copy.bara.sky scramjet_to_browserjs \
# --git-origin-ref my-branch --git-destination-fetch my-branch \
# --git-destination-push my-branch
SUBDIR = "packages/scramjet"

core.workflow(
name = "scramjet_to_browserjs",
origin = git.origin(
url = "https://github.com/MercuryWorkshop/scramjet",
ref = "main",
),
destination = git.destination(
url = "https://github.com/HeyPuter/browser.js",
fetch = "main",
push = "main",
),
destination_files = glob([SUBDIR + "/**"]),
transformations = [
core.move("", SUBDIR),
],
authoring = authoring.pass_thru("copybara-mw <copybara@mercurywork.shop>"),
mode = "ITERATIVE",
reversible_check = True,
custom_rev_id = "Scramjet-RevId",
)