Skip to content

Sync branches

Sync branches #3712

Workflow file for this run

# This workflow is used to create PRs to merge changes from the main branch to the next branch. It's mostly a front-end
# to `flub merge branches`, which is where the source code can be found. This also means you can replicate this workflow
# manually by running `flub merge branches` locally and providing a PAT.
#
# When run, the workflow executes `flub merge branches`, which first checks if a main/next merge PR is already open. If
# it is, the workflow exits with no error.
#
# If there is no PR, then the tool will open one by following this logic
#
# - Find the commits that need to be merged into next.
# - Take a batch of commits and iterate over them.
# - Test each commit for mergeability into next.
# - If all commits merge cleanly, open a PR at the last commit in the batch.
# - If a commit cannot be merged cleanly, open a PR at the _previous_ commit.
# - Once that PR is merged, then the next time the workflow runs, it will detect the conflicting commit and open a PR
# with that commit only.
#
# Each time the workflow runs, the tool will determine the commits to merge based entirely on the git repo state.
name: Sync branches
on:
schedule:
# At 0 minutes past the hour, every 1 hour, Monday through Friday. Cron timezone is in UTC.
- cron: "0 */1 * * 1-5"
# Each commit to next should trigger a run, so we create new PRs as quickly as possible.
push:
branches:
- "next"
# Support running the workflow manually through the GitHub UI.
workflow_dispatch:
inputs:
batchSize:
description: The maximum number of commits to include in a single PR.
type: number
default: 20
required: true
env:
TARGET_BRANCH: next
SOURCE_BRANCH: main
USERNAME: msfluid-bot
EMAIL: [email protected]
# The inputs context is only available when triggered by workflow_dispatch. For the scheduled runs this uses the
# default value
BATCH: ${{ inputs.batchSize || 20 }}
REVIEWER1: sonalideshpandemsft
jobs:
sync-branches:
runs-on: ubuntu-latest
if: github.repository_owner == 'microsoft'
steps:
- run: |
echo "TARGET_BRANCH: $TARGET_BRANCH"
echo "SOURCE_BRANCH: $SOURCE_BRANCH"
echo "USERNAME: $USERNAME"
echo "EMAIL: $EMAIL"
echo "BATCH: $BATCH"
echo "REVIEWER1: $REVIEWER1"
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
fetch-depth: "0" # all history
persist-credentials: false
# always check out the main branch by default. Otherwise the starting branch is based on the
# triggering event which can seem unpredictable when the workflow is triggered in different branches.
ref: main
- uses: pnpm/action-setup@c3b53f6a16e57305370b4ae5a540c2077a1d50dd # ratchet:pnpm/action-setup@v2
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # ratchet:actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- name: Install Fluid build tools
continue-on-error: true
run: |
cd build-tools
pnpm install --frozen-lockfile
pnpm run build:compile
# add the bin dir of build-cli to the path
cd packages/build-cli/bin
echo "$(pwd)" >> $GITHUB_PATH
# the `url.https://${secret}@github.com/.insteadOf` configuration is used to substitute the default GitHub URL
# with a custom URL that includes a secret token for secure authentication and authorization during Git operations,
# such as pushing to a remote repository on GitHub.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf
- name: Set Git config
env:
TOKEN: ${{ secrets.BOT_MAIN_NEXT_WORKFLOW_PAT }}
run: |
git config user.name $USERNAME
git config user.email $EMAIL
git config url.https://${{ env.TOKEN }}@github.com/.insteadOf https://github.com/
- name: Run merge command
env:
# PAT is loaded automatically from env variable
GITHUB_PAT: ${{ secrets.BOT_MAIN_NEXT_WORKFLOW_PAT }}
run: |
flub merge branches -s $SOURCE_BRANCH -t $TARGET_BRANCH -b $BATCH --reviewers $REVIEWER1 -v