diff --git a/OneBranchPipelines/github-ado-sync.yml b/OneBranchPipelines/github-ado-sync.yml new file mode 100644 index 000000000..76266c462 --- /dev/null +++ b/OneBranchPipelines/github-ado-sync.yml @@ -0,0 +1,127 @@ +# GitHub-to-ADO Sync Pipeline +# Syncs main branch from public GitHub to internal Azure DevOps daily at 5pm IST + +name: GitHub-Sync-$(Date:yyyyMMdd)$(Rev:.r) + +schedules: + - cron: "30 11 * * *" + displayName: "Daily sync at 5pm IST" + branches: + include: + - main + always: true + +trigger: none +pr: none + +jobs: +- job: SyncFromGitHub + displayName: 'Sync main branch from GitHub' + pool: + vmImage: 'windows-latest' + + steps: + - checkout: none + + - task: CmdLine@2 + displayName: 'Clone GitHub repo' + inputs: + script: git clone https://github.com/microsoft/mssql-python.git repo-dir -b main + workingDirectory: $(Agent.TempDirectory) + + - task: CmdLine@2 + displayName: 'Add Azure DevOps remote' + inputs: + script: git remote add azdo-mirror https://$(System.AccessToken)@sqlclientdrivers.visualstudio.com/mssql-python/_git/mssql-python + workingDirectory: $(Agent.TempDirectory)/repo-dir + + - task: CmdLine@2 + displayName: 'Fetch ADO repo' + inputs: + script: git fetch azdo-mirror + workingDirectory: $(Agent.TempDirectory)/repo-dir + + - task: CmdLine@2 + displayName: 'Create timestamped sync branch' + inputs: + script: | + echo Getting current timestamp... + powershell -Command "Get-Date -Format 'yyyyMMdd-HHmmss'" > timestamp.txt + set /p TIMESTAMP= branchname.txt + echo Creating sync branch: %SYNC_BRANCH% + git fetch azdo-mirror + git show-ref --verify --quiet refs/remotes/azdo-mirror/main + if %ERRORLEVEL% EQU 0 ( + git checkout -b %SYNC_BRANCH% -t azdo-mirror/main + ) else ( + echo azdo-mirror/main does not exist. Exiting. + exit /b 1 + ) + echo ##vso[task.setvariable variable=SYNC_BRANCH;isOutput=true]%SYNC_BRANCH% + workingDirectory: $(Agent.TempDirectory)/repo-dir + + - task: CmdLine@2 + displayName: 'Reset branch to match GitHub main exactly' + inputs: + script: | + git -c user.email="sync@microsoft.com" -c user.name="ADO Sync Bot" reset --hard origin/main + workingDirectory: $(Agent.TempDirectory)/repo-dir + + - task: CmdLine@2 + displayName: 'Push branch to Azure DevOps' + inputs: + script: | + set /p SYNC_BRANCH= pr_id.txt + set /p PR_ID=