-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub workflow for managing downstream WebRender
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
816766e1a236fcb7eebaa493e492b55c419ada05 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/sh | ||
# Usage: sync.sh <path/to/filtered> | ||
# | ||
# A script to sync Mozilla's git mirror of WebRender [1] to the Servo project's | ||
# downstream fork [2]. This script runs as part of a GitHub Action in this | ||
# repository triggered on regular intervals. | ||
# | ||
# The procedure for the sync is: | ||
# | ||
# 1. Clone a copy of the GitHub gecko-dev repository to the "_cache" directory. | ||
# 2. Filter that repository using `git-filter-repo` and create a new local git | ||
# repository with the filtered contents into a directory specified by the | ||
# argument passed to this script. The filtered contents are determined | ||
# by the configuration in `.github/sync/webrender.paths`. | ||
# 3. Cherry-pick the new commits into the repository in the current working | ||
# directory. The commits applied from the filtered repository are determined | ||
# by choosing every commit after the hash found in the file | ||
# `.github/sync/UPSTREAM_COMMIT` | ||
# | ||
# Note that this script relies on the idea that filtering `gecko-dev` the same | ||
# way more than once will result in the same commit hashes. | ||
# | ||
# If at some point, `webrender.paths` is modified and the commit hashes change, | ||
# then a single manual filter will have to happen in order to translate the | ||
# hash in the original filtered repository to the new one. The procedure for this | ||
# is roughly: | ||
# | ||
# 1. Run `git-filter-repo` locally and note the new hash of the latest | ||
# commit included from upstream. | ||
# 2. Replace the contents `UPSTREAM_COMMIT` with that hash and commit | ||
# it together with your changes to `webrender.paths`. | ||
# | ||
# [1]: <https://github.com/mozilla/gecko-dev/> mirrored from | ||
# <https://hg.mozilla.org/mozilla-central> | ||
# [2]: <https://github.com/mozilla/gecko-dev/> | ||
set -eux | ||
|
||
root_dir=$(pwd) | ||
cache_dir=$root_dir/_cache | ||
|
||
# Configure git because we will be making commits. | ||
git_name="Webrender Upstream Sync" | ||
git_email="[email protected]" | ||
|
||
step() { | ||
if [ "${TERM-}" != '' ]; then | ||
tput setaf 12 | ||
fi | ||
>&2 printf '* %s\n' "$*" | ||
if [ "${TERM-}" != '' ]; then | ||
tput sgr0 | ||
fi | ||
} | ||
|
||
step "Creating directory for filtered upstream repo if needed" | ||
mkdir -p "$1" | ||
cd -- "$1" | ||
filtered=$(pwd) | ||
|
||
step "Creating cache directory if needed" | ||
mkdir -p "$cache_dir" | ||
cd "$cache_dir" | ||
export PATH="$PWD:$PATH" | ||
|
||
step "Downloading git-filter-repo if needed" | ||
if ! git filter-repo --version 2> /dev/null; then | ||
curl -O https://raw.githubusercontent.com/newren/git-filter-repo/v2.38.0/git-filter-repo | ||
chmod +x git-filter-repo | ||
|
||
git filter-repo --version | ||
fi | ||
|
||
step "Cloning upstream if needed" | ||
if ! [ -e upstream ]; then | ||
git clone --bare --single-branch --progress https://github.com/mozilla/gecko-dev.git upstream | ||
fi | ||
|
||
step "Updating upstream" | ||
branch=$(git -C upstream rev-parse --abbrev-ref HEAD) | ||
git -C upstream fetch origin $branch:$branch | ||
|
||
step "Filtering upstream" | ||
# Cloning and filtering is much faster than git filter-repo --source --target. | ||
git clone upstream -- "$filtered" | ||
git -C "$filtered" filter-repo --force --paths-from-file "$root_dir/.github/sync/webrender.paths" | ||
|
||
step "Adding filtered repository as a remote" | ||
cd "$root_dir" | ||
git remote add filtered-upstream "$filtered" | ||
git fetch filtered-upstream | ||
|
||
step "Resetting `main` branch to filtered repository HEAD" | ||
git switch -c __work | ||
git reset --hard filtered-upstream/master | ||
git cherry-pick origin/test | ||
git switch -c test | ||
git reset --hard __work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Filters and renames use git-filter-repo(1) --paths-from-file: | ||
# https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#_filtering_based_on_many_paths | ||
# | ||
# WARNING: Do not modify this file without also updating UPSTREAM_COMMIT. If you | ||
# do that, it's likely that the sync will fail or add all commits again to the | ||
# repository. See the documentation in `sync.sh` for more details. | ||
|
||
gfx/wr/ | ||
regex:gfx/wr/(.+)==>\1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Sync from mozilla-central | ||
|
||
on: | ||
schedule: | ||
# Midnight on Sunday. | ||
- cron: '0 0 * * 0' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
sync: | ||
name: Sync | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
- uses: actions/cache@v4 | ||
with: | ||
path: _cache/upstream | ||
key: upstream | ||
- name: Run synchronization script | ||
run: ./.github/sync/sync.sh _filtered | ||
- name: Pushing new `main` | ||
run: git push -f origin test |