Skip to content

Commit a3fde2c

Browse files
authored
FEAT: Sync ado with latest github automatically (#371)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#40703](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/40703) <!-- External contributors: GitHub Issue --> > GitHub Issue: #<ISSUE_NUMBER> ------------------------------------------------------------------- ### Summary <!-- Insert your summary of changes below. Minimum 10 characters required. --> This pull request introduces a new Azure DevOps pipeline configuration to automate daily synchronization of the `main` branch from the public GitHub repository to the internal Azure DevOps repository. The pipeline clones the GitHub repository, creates a timestamped sync branch, resets it to match the GitHub `main` exactly, pushes it to Azure DevOps, and opens a pull request for review. This ensures the internal repository stays up-to-date with the public source. Key additions in the new pipeline: **Pipeline Automation for GitHub-to-ADO Sync** * Added a new pipeline file `OneBranchPipelines/github-ado-sync.yml` to automate daily sync from GitHub to Azure DevOps, scheduled at 5pm IST. * The pipeline clones the public GitHub repository, creates a timestamped sync branch based on the latest Azure DevOps `main`, and resets it to match GitHub's `main` branch exactly. * Automates pushing the sync branch to Azure DevOps and creates a pull request targeting `main`, including reviewer assignment and clean-up steps. <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) ### Contribution Guidelines External contributors: - Create a GitHub issue first: https://github.com/microsoft/mssql-python/issues/new - Link the GitHub issue in the "GitHub Issue" section above - Follow the PR title format and provide a meaningful summary mssql-python maintainers: - Create an ADO Work Item following internal processes - Link the ADO Work Item in the "ADO Work Item" section above - Follow the PR title format and provide a meaningful summary -->
1 parent fb7b5c3 commit a3fde2c

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# GitHub-to-ADO Sync Pipeline
2+
# Syncs main branch from public GitHub to internal Azure DevOps daily at 5pm IST
3+
4+
name: GitHub-Sync-$(Date:yyyyMMdd)$(Rev:.r)
5+
6+
schedules:
7+
- cron: "30 11 * * *"
8+
displayName: "Daily sync at 5pm IST"
9+
branches:
10+
include:
11+
- main
12+
always: true
13+
14+
trigger: none
15+
pr: none
16+
17+
jobs:
18+
- job: SyncFromGitHub
19+
displayName: 'Sync main branch from GitHub'
20+
pool:
21+
vmImage: 'windows-latest'
22+
23+
steps:
24+
- checkout: none
25+
26+
- task: CmdLine@2
27+
displayName: 'Clone GitHub repo'
28+
inputs:
29+
script: git clone https://github.com/microsoft/mssql-python.git repo-dir -b main
30+
workingDirectory: $(Agent.TempDirectory)
31+
32+
- task: CmdLine@2
33+
displayName: 'Add Azure DevOps remote'
34+
inputs:
35+
script: git remote add azdo-mirror https://$(System.AccessToken)@sqlclientdrivers.visualstudio.com/mssql-python/_git/mssql-python
36+
workingDirectory: $(Agent.TempDirectory)/repo-dir
37+
38+
- task: CmdLine@2
39+
displayName: 'Fetch ADO repo'
40+
inputs:
41+
script: git fetch azdo-mirror
42+
workingDirectory: $(Agent.TempDirectory)/repo-dir
43+
44+
- task: CmdLine@2
45+
displayName: 'Create timestamped sync branch'
46+
inputs:
47+
script: |
48+
echo Getting current timestamp...
49+
powershell -Command "Get-Date -Format 'yyyyMMdd-HHmmss'" > timestamp.txt
50+
set /p TIMESTAMP=<timestamp.txt
51+
set SYNC_BRANCH=github-sync-%TIMESTAMP%
52+
echo %SYNC_BRANCH% > branchname.txt
53+
echo Creating sync branch: %SYNC_BRANCH%
54+
git fetch azdo-mirror
55+
git show-ref --verify --quiet refs/remotes/azdo-mirror/main
56+
if %ERRORLEVEL% EQU 0 (
57+
git checkout -b %SYNC_BRANCH% -t azdo-mirror/main
58+
) else (
59+
echo azdo-mirror/main does not exist. Exiting.
60+
exit /b 1
61+
)
62+
echo ##vso[task.setvariable variable=SYNC_BRANCH;isOutput=true]%SYNC_BRANCH%
63+
workingDirectory: $(Agent.TempDirectory)/repo-dir
64+
65+
- task: CmdLine@2
66+
displayName: 'Reset branch to match GitHub main exactly'
67+
inputs:
68+
script: |
69+
git -c user.email="sync@microsoft.com" -c user.name="ADO Sync Bot" reset --hard origin/main
70+
workingDirectory: $(Agent.TempDirectory)/repo-dir
71+
72+
- task: CmdLine@2
73+
displayName: 'Push branch to Azure DevOps'
74+
inputs:
75+
script: |
76+
set /p SYNC_BRANCH=<branchname.txt
77+
echo Pushing branch: %SYNC_BRANCH%
78+
79+
git config user.email "sync@microsoft.com"
80+
git config user.name "ADO Sync Bot"
81+
82+
git push azdo-mirror %SYNC_BRANCH% --set-upstream
83+
84+
if %ERRORLEVEL% EQU 0 (
85+
echo Branch pushed successfully!
86+
) else (
87+
echo ERROR: Push failed!
88+
exit /b 1
89+
)
90+
workingDirectory: $(Agent.TempDirectory)/repo-dir
91+
92+
- task: CmdLine@2
93+
displayName: 'Create pull request'
94+
inputs:
95+
script: |
96+
echo Installing Azure DevOps extension...
97+
call az extension add --name azure-devops --only-show-errors
98+
99+
echo Setting up authentication...
100+
set AZURE_DEVOPS_EXT_PAT=$(System.AccessToken)
101+
102+
echo Configuring Azure DevOps defaults...
103+
call az devops configure --defaults organization=https://sqlclientdrivers.visualstudio.com project=mssql-python
104+
105+
set /p SYNC_BRANCH=<branchname.txt
106+
echo Creating PR from branch: %SYNC_BRANCH% to main
107+
108+
call az repos pr create --source-branch %SYNC_BRANCH% --target-branch main --title "ADO-GitHub Sync - %date%" --description "Automated sync from GitHub main branch" --auto-complete true --squash true --delete-source-branch true --output table
109+
110+
if %ERRORLEVEL% EQU 0 (
111+
echo PR created successfully!
112+
echo Adding reviewers...
113+
call az repos pr list --source-branch %SYNC_BRANCH% --target-branch main --status active --output tsv --query "[0].pullRequestId" > pr_id.txt
114+
set /p PR_ID=<pr_id.txt
115+
call az repos pr reviewer add --id %PR_ID% --reviewers gargsaumya@microsoft.com sharmag@microsoft.com sumit.sarabhai@microsoft.com jathakkar@microsoft.com spaitandi@microsoft.com --output table
116+
if %ERRORLEVEL% EQU 0 (
117+
echo Reviewers added successfully!
118+
)
119+
del pr_id.txt
120+
) else (
121+
echo ERROR: Failed to create PR
122+
exit /b 1
123+
)
124+
125+
if exist timestamp.txt del timestamp.txt
126+
if exist branchname.txt del branchname.txt
127+
workingDirectory: $(Agent.TempDirectory)/repo-dir

0 commit comments

Comments
 (0)