Skip to content

Commit 264b825

Browse files
authored
FIX: Updating sync pipeline to resolve merge issues between ado and github (#373)
### 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 primarily refactors the Azure DevOps pipeline for GitHub synchronization and makes minor code style improvements across the C++ and Python codebases. The pipeline changes simplify the sync process and improve conflict handling, while the codebase changes mostly involve formatting for better readability and maintainability. **Azure DevOps Pipeline Improvements:** - Simplified the sync process by checking out the repository directly (`checkout: self`) and removing redundant clone and remote-add steps. The pipeline now adds the GitHub remote and fetches the main branch in a single step. - Improved branch creation and sync logic: now creates the sync branch directly from the current state and pulls from GitHub main, handling merge conflicts by always accepting the GitHub version as the source of truth. - Changed the push target from the previous Azure DevOps remote to the default `origin` remote, aligning with the new checkout approach. - Cleaned up unnecessary `workingDirectory` specifications after refactoring the pipeline steps. **C++ Code Formatting and Readability:** - Reformatted function calls and object constructions in `connection.cpp` and `connection_pool.cpp` to improve readability, especially for multi-argument lines. [[1]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL28-R29) [[2]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL37-R39) [[3]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL64-R67) [[4]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL122-R126) [[5]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL132-R137) [[6]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL174-R183) [[7]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL341-R349) [[8]](diffhunk://#diff-35a698bc3405cc30c1bf656066bd0575302239b5e39083a8160a6202026ca360L40-R41) [[9]](diffhunk://#diff-35a698bc3405cc30c1bf656066bd0575302239b5e39083a8160a6202026ca360L66-R68) [[10]](diffhunk://#diff-35a698bc3405cc30c1bf656066bd0575302239b5e39083a8160a6202026ca360L124-R127) [[11]](diffhunk://#diff-396cb5eb8f38803cad4ec84bad73aa55c78a528275be99cb1f710aace9593f5eL53-R54) [[12]](diffhunk://#diff-85167a2d59779df18704284ab7ce46220c3619408fbf22c631ffdf29f794d635L394-R395) - Minor code cleanup in `ddbc_bindings.cpp`, including duplicate attribute resets in `FetchAll_wrap` (possibly unintentional). [[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R2626) [[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R4199-R4206) **Python Code Formatting:** - Reformatted long lines in test files and utility code for better readability, especially in SQL statements and exception handling. [[1]](diffhunk://#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128L46-R48) [[2]](diffhunk://#diff-ca315ffd463e0f93f3d45ace0869a4a3b1e572941da6723d7e9ce028cf9d2278L265-R270) [[3]](diffhunk://#diff-ca315ffd463e0f93f3d45ace0869a4a3b1e572941da6723d7e9ce028cf9d2278L338-R344) [[4]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L293-R299) [[5]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L355-R361) [[6]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L378-R386) [[7]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L424-R434) [[8]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L439-R451) [[9]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L474-R488) - Removed an unnecessary blank line in `type.py`. These changes collectively improve CI/CD reliability and code maintainability. <!-- ### 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 db68b2a commit 264b825

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

OneBranchPipelines/github-ado-sync.yml

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# GitHub-to-ADO Sync Pipeline
22
# Syncs main branch from public GitHub to internal Azure DevOps daily at 5pm IST
3+
#
4+
# SYNC STRATEGY RATIONALE:
5+
# This pipeline uses a "replace-all" approach rather than traditional git merge/rebase because:
6+
# 1. DIVERGENT HISTORY: ADO repository contains commits from early development that don't exist
7+
# in GitHub. These historical commits were made before GitHub became the source of truth.
8+
# 2. AVOIDING CONFLICTS: Standard git operations (merge, rebase, reset --hard) fail when
9+
# repositories have divergent commit histories. Attempting to merge results in conflicts
10+
# that cannot be automatically resolved.
11+
# 3. IMPLEMENTATION: We use 'git fetch + git rm + git checkout' to completely replace ADO's
12+
# working tree with GitHub's files without attempting to reconcile git history. This creates
13+
# a clean sync commit that updates all files to match GitHub exactly.
14+
# 4. CHANGE DETECTION: The pipeline checks if any files actually differ before creating PRs,
15+
# avoiding unnecessary sync operations when repositories are already aligned.
316

417
name: GitHub-Sync-$(Date:yyyyMMdd)$(Rev:.r)
518

@@ -21,25 +34,15 @@ jobs:
2134
vmImage: 'windows-latest'
2235

2336
steps:
24-
- checkout: none
37+
- checkout: self
38+
persistCredentials: true
2539

2640
- task: CmdLine@2
27-
displayName: 'Clone GitHub repo'
41+
displayName: 'Add GitHub remote'
2842
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+
script: |
44+
git remote add github https://github.com/microsoft/mssql-python.git
45+
git fetch github main
4346
4447
- task: CmdLine@2
4548
displayName: 'Create timestamped sync branch'
@@ -51,26 +54,35 @@ jobs:
5154
set SYNC_BRANCH=github-sync-%TIMESTAMP%
5255
echo %SYNC_BRANCH% > branchname.txt
5356
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-
)
57+
git checkout -b %SYNC_BRANCH%
6258
echo ##vso[task.setvariable variable=SYNC_BRANCH;isOutput=true]%SYNC_BRANCH%
63-
workingDirectory: $(Agent.TempDirectory)/repo-dir
6459
6560
- task: CmdLine@2
66-
displayName: 'Reset branch to match GitHub main exactly'
61+
displayName: 'Sync with GitHub main'
6762
inputs:
6863
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
64+
echo Syncing with GitHub main...
65+
git config user.email "sync@microsoft.com"
66+
git config user.name "ADO Sync Bot"
67+
68+
git fetch github main
69+
git rm -rf .
70+
git checkout github/main -- .
71+
echo timestamp.txt >> .git\info\exclude
72+
echo branchname.txt >> .git\info\exclude
73+
git diff --cached --quiet
74+
if %ERRORLEVEL% EQU 0 (
75+
echo No changes detected. Skipping commit.
76+
echo ##vso[task.setvariable variable=HAS_CHANGES]false
77+
) else (
78+
echo Changes detected. Creating commit...
79+
git add . && git commit -m "Sync from GitHub main"
80+
echo ##vso[task.setvariable variable=HAS_CHANGES]true
81+
)
7182
7283
- task: CmdLine@2
7384
displayName: 'Push branch to Azure DevOps'
85+
condition: eq(variables['HAS_CHANGES'], 'true')
7486
inputs:
7587
script: |
7688
set /p SYNC_BRANCH=<branchname.txt
@@ -79,18 +91,18 @@ jobs:
7991
git config user.email "sync@microsoft.com"
8092
git config user.name "ADO Sync Bot"
8193
82-
git push azdo-mirror %SYNC_BRANCH% --set-upstream
94+
git push origin %SYNC_BRANCH% --set-upstream
8395
8496
if %ERRORLEVEL% EQU 0 (
8597
echo Branch pushed successfully!
8698
) else (
8799
echo ERROR: Push failed!
88100
exit /b 1
89101
)
90-
workingDirectory: $(Agent.TempDirectory)/repo-dir
91102
92103
- task: CmdLine@2
93104
displayName: 'Create pull request'
105+
condition: eq(variables['HAS_CHANGES'], 'true')
94106
inputs:
95107
script: |
96108
echo Installing Azure DevOps extension...
@@ -124,4 +136,3 @@ jobs:
124136
125137
if exist timestamp.txt del timestamp.txt
126138
if exist branchname.txt del branchname.txt
127-
workingDirectory: $(Agent.TempDirectory)/repo-dir

0 commit comments

Comments
 (0)