From 17e47ac520b051d7eba239550238c2b4dbe804e1 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Mon, 18 Nov 2024 13:48:53 +0100 Subject: [PATCH] Add GitHub workflow for managing downstream WebRender --- .github/sync/UPSTREAM_COMMIT | 1 + .github/sync/sync.sh | 97 +++++++++++++++++++++++++++++ .github/sync/webrender.paths | 9 +++ .github/workflows/sync-upstream.yml | 24 +++++++ 4 files changed, 131 insertions(+) create mode 100644 .github/sync/UPSTREAM_COMMIT create mode 100755 .github/sync/sync.sh create mode 100644 .github/sync/webrender.paths create mode 100644 .github/workflows/sync-upstream.yml diff --git a/.github/sync/UPSTREAM_COMMIT b/.github/sync/UPSTREAM_COMMIT new file mode 100644 index 0000000000..bdc97d5bed --- /dev/null +++ b/.github/sync/UPSTREAM_COMMIT @@ -0,0 +1 @@ +816766e1a236fcb7eebaa493e492b55c419ada05 diff --git a/.github/sync/sync.sh b/.github/sync/sync.sh new file mode 100755 index 0000000000..4ca5fb7427 --- /dev/null +++ b/.github/sync/sync.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# Usage: sync.sh +# +# 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]: mirrored from +# +# [2]: +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="noreply@github.com" + +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 diff --git a/.github/sync/webrender.paths b/.github/sync/webrender.paths new file mode 100644 index 0000000000..b6cf81bf98 --- /dev/null +++ b/.github/sync/webrender.paths @@ -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 diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml new file mode 100644 index 0000000000..d23dac8ecb --- /dev/null +++ b/.github/workflows/sync-upstream.yml @@ -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