From f270d730f76e78e3ecebf18a22012caf7760f303 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 16 Jul 2024 17:51:22 +0800 Subject: [PATCH] add github action to sync main to future (#25562) --- .github/workflows/sync-main-to-future.yml | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/sync-main-to-future.yml diff --git a/.github/workflows/sync-main-to-future.yml b/.github/workflows/sync-main-to-future.yml new file mode 100644 index 000000000000..a2cd5e7aded5 --- /dev/null +++ b/.github/workflows/sync-main-to-future.yml @@ -0,0 +1,46 @@ +name: sync-main +run-name: Sync commit from main to future - temporary +env: + GH_TOKEN: ${{ github.token }} +on: + push: + branches: + - 'main' +jobs: + sync_generation: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: 'future' + - name: sync main + shell: pwsh + run: | + $commitMessage = '${{ github.event.head_commit.message }}' + $commitMessagePatternToIgnore = @() + $commitMessagePatternToIgnore += "^Migrate\s\w+\sfrom\sgeneration\sto\smain" + $commitMessagePatternToIgnore += "^Move\s\w+\sto\smain" + foreach ($pattern in $commitMessagePatternToIgnore) { + if ($commitMessage -match $ignoreCommitPattern) { + Write-Host -ForegroundColor DarkGreen "Commit: [$commitMessage], is for gen2main, skip this run ..." + return + } + } + $commitId = '${{ github.event.head_commit.id }}' + $commitIdShort = $commitId.Subsctring(0,5) + + git config user.email "65331932+azure-powershell-bot@users.noreply.github.com"; + git config user.name "azure-powershell-bot"; + + $branchName = "eng/sync-main-to-future-$commitIdShort" + git checkout -b $branchName + + $prInfo = "Sync commit [$commitMessage ($commitId)] from main branch to future branch .." + Write-Host -ForegroundColor DarkGreen $prInfo + + git fetch origin main + git cherry-pick $commitId --strategy-option theirs + git push origin head + gh pr create -B $branchName -H future --title $commitMessage --body $prInfo \ No newline at end of file