|
| 1 | +# GitHub to Azure DevOps (ADO) Sync & CI/CD Setup |
| 2 | + |
| 3 | +This document provides a step-by-step guide for setting up a Python project with GitHub as the primary repository and Azure DevOps (ADO) as a mirror for internal CI/CD pipelines. |
| 4 | + |
| 5 | +## Guidelines |
| 6 | + |
| 7 | +## 1. Repository Structure |
| 8 | +### 1.1 GitHub Repository (Primary Development) |
| 9 | +- **Branches:** |
| 10 | + - `main` (Protected, Stable Release) |
| 11 | + - `dev` (Active Development) |
| 12 | + - `feature/*` (Feature Branches) |
| 13 | + - `hotfix/*` (Hotfixes) |
| 14 | + |
| 15 | +### 1.2 Azure DevOps Repository (Internal Pipeline Execution) |
| 16 | +- **Branches Mirrored:** `main`, `dev`, `release-branches` |
| 17 | +- **Does NOT push back to GitHub** |
| 18 | +- **Changes from Github will be sync-back to ADO** |
| 19 | + |
| 20 | +### 1.3 Folder Structure |
| 21 | +``` |
| 22 | +/MSSQL-Python |
| 23 | + |-- src/ |
| 24 | + |-- tests/ |
| 25 | + |-- .github/ |
| 26 | + | |--ISSUE_Template |
| 27 | + | | |-- bug_report.md |
| 28 | + | | |-- feature-request.md |
| 29 | + | | |-- question.md |
| 30 | + | |--PR_Template |
| 31 | + | | |-- bug_fix.md |
| 32 | + | | |-- feature.md |
| 33 | + | | |-- other.md |
| 34 | + | |-- workflows/ |
| 35 | + | │ |-- pr-checks.yml |
| 36 | + | │ |-- codeql.yml |
| 37 | + | │ |-- sync_to_ado.yml |
| 38 | + | |-- dependabot.yml |
| 39 | + |-- ado-pipelines/ |
| 40 | + | |-- build.yml |
| 41 | + | |-- release.yml |
| 42 | + |-- requirements.txt |
| 43 | + |-- setup.py |
| 44 | + |-- README.md |
| 45 | + |-- CONTRIBUTOR.md |
| 46 | + |-- test-pipeline.yml |
| 47 | +
|
| 48 | +--- |
| 49 | +
|
| 50 | +## 2. Syncing Mechanism Between GitHub & ADO |
| 51 | +### 2.1 GitHub Actions for Sync (`.github/workflows/sync_to_ado.yml`) |
| 52 | +```yaml |
| 53 | +name: Sync to ADO Repo |
| 54 | +
|
| 55 | +on: |
| 56 | + push: |
| 57 | + branches: |
| 58 | + - main |
| 59 | + - dev |
| 60 | +
|
| 61 | +jobs: |
| 62 | + sync: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - name: Checkout Repository |
| 66 | + uses: actions/checkout@v3 |
| 67 | +
|
| 68 | + - name: Push to Azure DevOps |
| 69 | + run: | |
| 70 | + git remote add ado https://<AZURE_USERNAME>:<AZURE_PERSONAL_ACCESS_TOKEN>@sqlclientdrivers.visualstudio.com/mssql-python/_git/mssql-python |
| 71 | + git push ado --mirror |
| 72 | +``` |
| 73 | + |
| 74 | +### 2.2 Azure DevOps Scheduled Sync Pipeline (`ado-github-sync.yml`) |
| 75 | +```yaml |
| 76 | +trigger: none |
| 77 | + |
| 78 | +schedules: |
| 79 | + - cron: "0 * * * *" |
| 80 | + displayName: Hourly Sync |
| 81 | + branches: |
| 82 | + include: |
| 83 | + - main |
| 84 | + - dev |
| 85 | + |
| 86 | +pool: |
| 87 | + vmImage: <image-name> |
| 88 | + |
| 89 | +steps: |
| 90 | + - checkout: none |
| 91 | + - script: | |
| 92 | + git clone --mirror https://github.com/microsoft/mssql-python.git |
| 93 | + cd <REPO>.git |
| 94 | + git push --mirror https://sqlclientdrivers.visualstudio.com/mssql-python/_git/mssql-python |
| 95 | + displayName: "Sync GitHub to ADO" |
| 96 | +``` |
| 97 | +
|
| 98 | +--- |
| 99 | +
|
| 100 | +## 3. GitHub CI/CD Pipeline (PR Checks & Testing) |
| 101 | +### 3.1 GitHub Actions for PR Checks (`.github/workflows/pr-checks.yml`) |
| 102 | +```yaml |
| 103 | +name: PR Checks |
| 104 | +
|
| 105 | +on: |
| 106 | + pull_request: |
| 107 | + branches: |
| 108 | + - main |
| 109 | + - dev |
| 110 | +
|
| 111 | +jobs: |
| 112 | + test: |
| 113 | + runs-on: <image-name> |
| 114 | + steps: |
| 115 | + - name: Checkout Code |
| 116 | + uses: actions/checkout@v3 |
| 117 | +
|
| 118 | + - name: Set up Python |
| 119 | + uses: actions/setup-python@v4 |
| 120 | + with: |
| 121 | + python-version: '3.13' |
| 122 | +
|
| 123 | + - name: Install Dependencies |
| 124 | + run: pip install -r requirements.txt |
| 125 | +
|
| 126 | + - name: Run Linter |
| 127 | + run: pylint src/ |
| 128 | +
|
| 129 | + - name: Run Tests |
| 130 | + run: pytest tests/ |
| 131 | +``` |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## 4. Security & Dependency Management |
| 136 | +### 4.1 Dependabot for Dependency Updates (`.github/dependabot.yml`) |
| 137 | +```yaml |
| 138 | +version: 2 |
| 139 | +updates: |
| 140 | + - package-ecosystem: "pip" |
| 141 | + directory: "/" |
| 142 | + schedule: |
| 143 | + interval: "weekly" |
| 144 | +``` |
| 145 | + |
| 146 | +### 4.2 Bandit Security Scan |
| 147 | +Modify `.github/workflows/pr-checks.yml`: |
| 148 | +```yaml |
| 149 | + - name: Run Security Scan (Bandit) |
| 150 | + run: bandit -r mssql-python/ |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## 5. Azure DevOps CI/CD Pipelines |
| 156 | +### 5.1 ADO Build Pipeline (`build.yml`) |
| 157 | +```yaml |
| 158 | +trigger: |
| 159 | + branches: |
| 160 | + include: |
| 161 | + - main |
| 162 | + - dev |
| 163 | +
|
| 164 | +pool: |
| 165 | + vmImage: ubuntu-latest |
| 166 | +
|
| 167 | +steps: |
| 168 | + - checkout: self |
| 169 | + - task: UsePythonVersion@0 |
| 170 | + inputs: |
| 171 | + versionSpec: "3.13" |
| 172 | + - script: pip install -r requirements.txt |
| 173 | + displayName: "Install dependencies" |
| 174 | + - script: pytest tests/ |
| 175 | + displayName: "Run tests" |
| 176 | + - script: pylint src/ |
| 177 | + displayName: "Run linting" |
| 178 | + - task: PublishBuildArtifacts@1 |
| 179 | + inputs: |
| 180 | + pathtoPublish: "dist" |
| 181 | + artifactName: "mssql-python" |
| 182 | +``` |
| 183 | + |
| 184 | +### 5.2 ADO Release Pipeline (`release.yml`) |
| 185 | +```yaml |
| 186 | +trigger: |
| 187 | + branches: |
| 188 | + include: |
| 189 | + - main |
| 190 | +
|
| 191 | +pool: |
| 192 | + vmImage: |
| 193 | +
|
| 194 | +stages: |
| 195 | + - stage: Deploy |
| 196 | + jobs: |
| 197 | + - job: Deploy |
| 198 | + steps: |
| 199 | + - script: echo "TODO Based on ESRP Release Task" |
| 200 | + displayName: "Deploy Step" |
| 201 | +``` |
| 202 | + |
| 203 | +--- |
| 204 | +## 5. Contribution Guidelines |
| 205 | +### 5.1 Community Contributions |
| 206 | + - Fork -->Feature Branch --> PR --> PR Hooks and Checks --> Review and Approvals --> Merge |
| 207 | + - PR Approval mandatory from internal maintainers |
| 208 | + - PR validation checks triggered via Github Actions |
| 209 | +### 5.2 ADO Coding Contributions |
| 210 | + - Internal Maintainers also code on Github |
| 211 | + - Fork -->Feature Branch --> PR --> PR Hooks and Checks --> Review and Approvals --> Merge |
| 212 | + - PR Approval mandatory from internal maintainers |
| 213 | + - PR validation checks triggered via Github Actions |
| 214 | + - Validate PR Code via ADO build for CI/CD (before merging PRs) |
| 215 | + - can create/code on protected branches for internal fixes |
| 216 | + ### 5.3 Access Controls |
| 217 | + - Github --> Branch protection rules for main and dev. |
| 218 | + - Github --> Enable Dependabot |
| 219 | + - ADO --> Access only to Microsoft internal (for build/release and security fixes) |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
0 commit comments