Skip to content

Document and automate the process to fetch from upstream #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2021
Merged
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
41 changes: 41 additions & 0 deletions .yamato/scripts/update_from_upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

# Prequisites:
# This script assumes git and github CLR (gh) are installed.

# Cause the script to fail if any individual command fails
set -e

# Fetch from upstream
git remote add upstream https://github.com/dotnet/runtime
git fetch upstream

# Create a new branch for a pull request to merge in upstream/main
# using the current date in the branch name.
git checkout unity-main
branch_name=bot-upstream-main-merge-$(date '+%Y-%m-%d')
git checkout -b $branch_name
git merge upstream/main -m "Merge with main from upstream"
git push --set-upstream origin $branch_name

# Login to Github
set -u
echo "$GITHUB_TOKEN" > .githubtoken
unset GITHUB_TOKEN
gh auth login --hostname github.com --with-token < .githubtoken
rm .githubtoken

# Yamato has a local mirror of github.com for cloning. This configuration
# causes problems for Github CLI, so set the remote manually here.
git remote set-url origin $GIT_REPOSITORY_URL

# Create a pull request back to unity-main
gh pr create --fill

# For some unknown reason we often see this error from Github CLI:
#
# pull request create failed: HTTP 502: Something went wrong while executing your query.
# This may be the result of a timeout, or it could be a GitHub bug.
# Please include `B96C:2166:B667D:BCDCF:61A53AF5` when reporting this issue. (https://api.github.com/graphql)
#
# Often the pull request was actually created though, so manually check for it if this happens.
19 changes: 19 additions & 0 deletions .yamato/update_from_upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Update from upstream
agent:
type: Unity::VM
image: platform-foundation/linux-ubuntu18.04-il2cpp-bokken:latest
flavor: b1.xlarge

commands:
- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
- sudo apt update
- sudo apt install gh
- git config --global user.email "joshuap@unity3d.com"
- git config --global user.name "Josh Peterson"
- .yamato/scripts/update_from_upstream.sh

triggers:
recurring:
- branch: unity-main
frequency: weekly
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unity's Fork of the .NET Runtime

See [unity/README.md](unity/README.md) for details specific to Unity's fork.

# .NET Runtime
[![Build Status](https://dnceng.visualstudio.com/public/_apis/build/status/dotnet/runtime/runtime?branchName=main)](https://dnceng.visualstudio.com/public/_build/latest?definitionId=686&branchName=main)
[![Help Wanted](https://img.shields.io/github/issues/dotnet/runtime/up-for-grabs?style=flat-square&color=%232EA043&label=help%20wanted)](https://github.com/dotnet/runtime/issues?q=is%3Aissue+is%3Aopen+label%3A%22up-for-grabs%22)
Expand Down
17 changes: 17 additions & 0 deletions unity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# .NET Runtime - Unity Details

This is Unity's fork of the .NET Runtime repository.

The difference between this fork and the upstream repository should be as small as possible, with all of the differences specific to Unity. Our goal is to upstream as many changes made here as possible.

## Pulling changes from upstream

There is a job in Unity's internal CI which runs weekly to pull the latest code from the upstream [dotnet/runtime](https://github.com/dotnet/runtime) repository `main` branch and create a pull request to merge these changes to the [`unity-main`](https://github.com/Unity-Technologies/runtime/tree/unity-main) branch.

## Pushing changes to upstream

When a pull request is open against this fork, we should determine if the changes in that pull request should be pushed upstream (most should). Ideally, pull request should be organized so that all changes in a given pull request can be directly applied upstream. Any changes specific to the Unity fork should be done in a separate pull request.

Assuming the branch with changes to upstream is named `great-new-feature` then a new branch of upstream [`main`](https://github.com/dotnet/runtime/tree/main) named `upstream-great-new-feature` should be created. Each commit from `great-new-feature` should be cherry-picked `upstream-great-new-feature`, and then a pull request should be opened from `upstream-great-new-feature` to [`main`](https://github.com/dotnet/runtime/tree/main) in the upstream repository.

It is acceptable to _merge_ changes to this fork from `great-new-feature` before `upstream-great-new-feature` is merged, but we should at least _open_ an upstream pull request first.