Skip to content

Sync branches

Sync branches #134

Workflow file for this run

name: 'Sync branches'
on:
schedule:
- cron: '0 0 * * 1' # Run at the start of every monday
workflow_dispatch: # Allow manually invoking this workflow
permissions: {}
env:
base_branch: 'origin/main'
jobs:
sync-non-code:
if: github.repository == 'dotnet/dotnet-monitor'
strategy:
matrix:
branch: ["release/6.x", "release/8.0"]
name: 'Sync non-code to ${{ matrix.branch }}'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: true # We need to persist credentials to push the resulting changes upstream.
fetch-depth: 0 # Fetch the entire repo for the below git operations
ref: ${{ matrix.branch }}
- name: Sync branch
run: |
git checkout --no-overlay "$base_branch" -- \
".github" \
".devcontainer" \
".vscode" \
"eng/actions" \
"cspell.json" \
"documentation/**.md"
- name: Open PR
uses: ./.github/actions/open-pr
with:
files_to_commit: "*"
title: '[${{ matrix.branch }}] Sync non-code with ${{ env.base_branch }}'
commit_message: sync non-code with ${{ env.base_branch }}
body: Sync non-code with ${{ env.base_branch }}. This PR was auto generated and will not be automatically merged in.
branch_name: sync/${{ matrix.branch }}
fail_if_files_unchanged: false
labels: 'automatic-pr'
auth_token: ${{ secrets.GITHUB_TOKEN }}
sync-code:
if: github.repository == 'dotnet/dotnet-monitor'
strategy:
matrix:
branch: ["feature/9.x"]
name: 'Sync branch with ${{ matrix.branch }}'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: true # We need to persist credentials to push the resulting changes upstream.
fetch-depth: 0 # Fetch the entire repo for the below git operations
ref: ${{ matrix.branch }}
- name: Sync branch
run: |
ourFiles=$(perl -ne '/^([^\s]+)\s+merge=ours/gm && print "$1 "' .gitattributes)
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Activate the ours merge driver to respect any branch specific files
git config merge.ours.driver true
MERGE_RESULT=0
# Don't fail if the automatic merge fails, we'll try to handle it later
git merge "$base_branch" --strategy=ort --strategy-option=theirs || MERGE_RESULT=$?
# If the merge failed it's likely due to a (modify/delete) conflict. Try to auto-resolve it by accepting the results.
# If we've deviated more than that the below commands will fail and it requires manual intervention.
if [ $MERGE_RESULT -ne 0 ]; then
for match in $ourFiles; do
git add -- "$match"
done
git commit --no-edit
fi
for match in $ourFiles; do
git checkout --no-overlay "$target_branch" -- "$match"
done
env:
target_branch: origin/${{ matrix.branch }}
- name: Open PR
uses: ./.github/actions/open-pr
with:
files_to_commit: "*"
title: '[${{ matrix.branch }}] Sync branch with ${{ env.base_branch }}'
commit_message: Restore branch-specific files
body: Sync branch with ${{ env.base_branch }}. This PR was auto generated and will not be automatically merged in.
branch_name: sync/${{ matrix.branch }}
fail_if_files_unchanged: false
always_create_pr: true
labels: 'automatic-pr'
auth_token: ${{ secrets.GITHUB_TOKEN }}