-
Notifications
You must be signed in to change notification settings - Fork 33
FEAT: Sync ado with latest github automatically #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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=<timestamp.txt | ||
| set SYNC_BRANCH=github-sync-%TIMESTAMP% | ||
| echo %SYNC_BRANCH% > 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% | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workingDirectory: $(Agent.TempDirectory)/repo-dir | ||
|
|
||
| - task: CmdLine@2 | ||
| displayName: 'Reset branch to match GitHub main exactly' | ||
| inputs: | ||
| script: | | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| git -c user.email="[email protected]" -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=<branchname.txt | ||
| echo Pushing branch: %SYNC_BRANCH% | ||
|
|
||
| git config user.email "[email protected]" | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| git config user.name "ADO Sync Bot" | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| git push azdo-mirror %SYNC_BRANCH% --set-upstream | ||
|
|
||
| if %ERRORLEVEL% EQU 0 ( | ||
| echo Branch pushed successfully! | ||
| ) else ( | ||
| echo ERROR: Push failed! | ||
| exit /b 1 | ||
| ) | ||
| workingDirectory: $(Agent.TempDirectory)/repo-dir | ||
|
|
||
| - task: CmdLine@2 | ||
| displayName: 'Create pull request' | ||
| inputs: | ||
| script: | | ||
| echo Installing Azure DevOps extension... | ||
| call az extension add --name azure-devops --only-show-errors | ||
|
|
||
| echo Setting up authentication... | ||
| set AZURE_DEVOPS_EXT_PAT=$(System.AccessToken) | ||
|
|
||
| echo Configuring Azure DevOps defaults... | ||
| call az devops configure --defaults organization=https://sqlclientdrivers.visualstudio.com project=mssql-python | ||
|
|
||
| set /p SYNC_BRANCH=<branchname.txt | ||
| echo Creating PR from branch: %SYNC_BRANCH% to main | ||
|
|
||
| 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 | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if %ERRORLEVEL% EQU 0 ( | ||
| echo PR created successfully! | ||
| echo Adding reviewers... | ||
| call az repos pr list --source-branch %SYNC_BRANCH% --target-branch main --status active --output tsv --query "[0].pullRequestId" > pr_id.txt | ||
| set /p PR_ID=<pr_id.txt | ||
| call az repos pr reviewer add --id %PR_ID% --reviewers [email protected] [email protected] [email protected] [email protected] [email protected] --output table | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if %ERRORLEVEL% EQU 0 ( | ||
| echo Reviewers added successfully! | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| del pr_id.txt | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) else ( | ||
| echo ERROR: Failed to create PR | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| if exist timestamp.txt del timestamp.txt | ||
| if exist branchname.txt del branchname.txt | ||
gargsaumya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workingDirectory: $(Agent.TempDirectory)/repo-dir | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.