Skip to content

Commit e0fc5a6

Browse files
committed
Add GitHub workflow for managing downstream WebRender
1 parent 5f77ac9 commit e0fc5a6

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.github/sync/UPSTREAM_COMMIT

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
816766e1a236fcb7eebaa493e492b55c419ada05

.github/sync/sync.sh

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/sh
2+
# Usage: sync.sh <path/to/filtered>
3+
#
4+
# A script to sync Mozilla's git mirror of WebRender [1] to the Servo project's
5+
# downstream fork [2]. This script runs as part of a GitHub Action in this
6+
# repository triggered on regular intervals.
7+
#
8+
# The procedure for the sync is:
9+
#
10+
# 1. Clone a copy of the GitHub gecko-dev repository to the "_cache" directory.
11+
# 2. Filter that repository using `git-filter-repo` and create a new local git
12+
# repository with the filtered contents into a directory specified by the
13+
# argument passed to this script. The filtered contents are determined
14+
# by the configuration in `.github/sync/webrender.paths`.
15+
# 3. Cherry-pick the new commits into the repository in the current working
16+
# directory. The commits applied from the filtered repository are determined
17+
# by choosing every commit after the hash found in the file
18+
# `.github/sync/UPSTREAM_COMMIT`
19+
#
20+
# Note that this script relies on the idea that filtering `gecko-dev` the same
21+
# way more than once will result in the same commit hashes.
22+
#
23+
# If at some point, `webrender.paths` is modified and the commit hashes change,
24+
# then a single manual filter will have to happen in order to translate the
25+
# hash in the original filtered repository to the new one. The procedure for this
26+
# is roughly:
27+
#
28+
# 1. Run `git-filter-repo` locally and note the new hash of the latest
29+
# commit included from upstream.
30+
# 2. Replace the contents `UPSTREAM_COMMIT` with that hash and commit
31+
# it together with your changes to `webrender.paths`.
32+
#
33+
# [1]: <https://github.com/mozilla/gecko-dev/> mirrored from
34+
# <https://hg.mozilla.org/mozilla-central>
35+
# [2]: <https://github.com/mozilla/gecko-dev/>
36+
set -eux
37+
38+
root_dir=$(pwd)
39+
cache_dir=$root_dir/_cache
40+
41+
# Configure git because we will be making commits.
42+
git_name="Webrender Upstream Sync"
43+
git_email="[email protected]"
44+
45+
step() {
46+
if [ "${TERM-}" != '' ]; then
47+
tput setaf 12
48+
fi
49+
>&2 printf '* %s\n' "$*"
50+
if [ "${TERM-}" != '' ]; then
51+
tput sgr0
52+
fi
53+
}
54+
55+
step "Creating directory for filtered upstream repo if needed"
56+
mkdir -p "$1"
57+
cd -- "$1"
58+
filtered=$(pwd)
59+
60+
step "Creating cache directory if needed"
61+
mkdir -p "$cache_dir"
62+
cd "$cache_dir"
63+
export PATH="$PWD:$PATH"
64+
65+
step "Downloading git-filter-repo if needed"
66+
if ! git filter-repo --version 2> /dev/null; then
67+
curl -O https://raw.githubusercontent.com/newren/git-filter-repo/v2.38.0/git-filter-repo
68+
chmod +x git-filter-repo
69+
70+
git filter-repo --version
71+
fi
72+
73+
step "Cloning upstream if needed"
74+
if ! [ -e upstream ]; then
75+
git clone --bare --single-branch --progress https://github.com/mozilla/gecko-dev.git upstream
76+
fi
77+
78+
step "Updating upstream"
79+
branch=$(git -C upstream rev-parse --abbrev-ref HEAD)
80+
git -C upstream fetch origin $branch:$branch
81+
82+
step "Filtering upstream"
83+
# Cloning and filtering is much faster than git filter-repo --source --target.
84+
git clone upstream -- "$filtered"
85+
git -C "$filtered" filter-repo --force --paths-from-file "$root_dir/.github/sync/webrender.paths"
86+
87+
step "Adding filtered repository as a remote"
88+
cd "$root_dir"
89+
git remote add filtered-upstream "$filtered"
90+
git fetch filtered-upstream
91+
92+
step "Resetting main branch to filtered repository HEAD"
93+
git switch -c __work
94+
git reset --hard filtered-upstream/master
95+
git show origin/test
96+
git cherry-pick origin/test
97+
git switch -c test
98+
git reset --hard __work

.github/sync/webrender.paths

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Filters and renames use git-filter-repo(1) --paths-from-file:
2+
# https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#_filtering_based_on_many_paths
3+
#
4+
# WARNING: Do not modify this file without also updating UPSTREAM_COMMIT. If you
5+
# do that, it's likely that the sync will fail or add all commits again to the
6+
# repository. See the documentation in `sync.sh` for more details.
7+
8+
gfx/wr/
9+
regex:gfx/wr/(.+)==>\1

.github/workflows/sync-upstream.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Sync from mozilla-central
2+
3+
on:
4+
schedule:
5+
# Midnight on Sunday.
6+
- cron: '0 0 * * 0'
7+
workflow_dispatch:
8+
9+
jobs:
10+
sync:
11+
name: Sync
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 1
17+
- uses: actions/cache@v4
18+
with:
19+
path: _cache/upstream
20+
key: upstream
21+
- name: Run synchronization script
22+
run: ./.github/sync/sync.sh _filtered
23+
- name: Pushing new `main`
24+
run: git push -f origin test

0 commit comments

Comments
 (0)