|
| 1 | +# Branching & CI/CD Guidance |
| 2 | + |
| 3 | +Purpose: Provide a concise, practical policy and examples teams can adopt for integration, branching and CI gating. This page is intentionally short — teams should adapt the policy to their project and toolchain. |
| 4 | + |
| 5 | +## Recommended approach |
| 6 | +- Prefer trunk-based development where possible for new projects. Use short-lived feature branches when necessary and merge frequently into the default integration branch (commonly `main` or `trunk`). |
| 7 | +- Use branch protection rules on the integration branch to enforce quality gates (required passing CI, required code reviews, status checks). |
| 8 | +- Keep releases simple: use tags/releases from the integration branch and keep release process documented separately. |
| 9 | + |
| 10 | +## Example branch protection rules |
| 11 | +- Require at least one approving reviewer for pull requests. |
| 12 | +- Require successful CI pipeline status checks before merge. |
| 13 | +- Require up-to-date branch before merge if your policy prefers. |
| 14 | + |
| 15 | +## Sample minimal GitHub Actions CI gate (example) |
| 16 | +```yaml |
| 17 | +name: ci |
| 18 | +on: [pull_request] |
| 19 | +jobs: |
| 20 | + build-and-test: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + - name: Set up Node.js |
| 25 | + uses: actions/setup-node@v3 |
| 26 | + with: |
| 27 | + node-version: '18' |
| 28 | + - name: Install |
| 29 | + run: npm ci |
| 30 | + - name: Run tests |
| 31 | + run: npm test |
| 32 | +``` |
| 33 | +
|
| 34 | +## Merge policy checklist (suggested) |
| 35 | +- [ ] Code compiles and automated tests pass in CI |
| 36 | +- [ ] At least one approving reviewer has reviewed the change |
| 37 | +- [ ] The change has an associated work item or issue |
| 38 | +- [ ] Documentation updated where applicable |
| 39 | +
|
| 40 | +## Tips |
| 41 | +- Keep feature branches short-lived; frequent merges reduce integration risk. |
| 42 | +- Automate as much of the gate (linting, unit tests, basic security scans) as possible to keep manual review focused on design and architecture. |
| 43 | +- Adapt branch protection to match team size and delivery cadence. |
| 44 | +
|
| 45 | +--- |
| 46 | +
|
| 47 | +## Alignment with CI/CD guidance |
| 48 | +This page complements the central CI/CD guidance in `docs/CI-CD/README.md`. Key expectations teams should follow: |
| 49 | + |
| 50 | +- The integration (main) branch should be continuously shippable and stable — at any point we should be able to deploy a build from `main` to production if needed. |
| 51 | +- Run a quality pipeline (linting, unit tests, basic integration tests) on each PR and on merges to the integration branch. |
| 52 | +- Provision cloud resources and environment configuration via infrastructure-as-code (for example Terraform, Bicep, Pulumi) and exercise them in non-production environments. |
| 53 | +- Deploy release candidates automatically to a non-production environment to validate integration and operational concerns. |
| 54 | +- Automate release and rollback procedures so releases are repeatable and auditable. |
| 55 | + |
| 56 | +## Tools (reference) |
| 57 | +Refer to `docs/CI-CD/README.md` for more detail on recommended tools. Common options include: |
| 58 | +- Azure Pipelines — recommended/used across many Microsoft engagements for CI/CD. |
| 59 | +- GitHub Actions, Jenkins, CircleCI, TravisCI — viable alternatives depending on project constraints. |
| 60 | + |
| 61 | +## AI-assisted CI/CD authoring |
| 62 | +AI tools can accelerate writing CI/CD pipeline YAML, jobs, and scripting snippets, but they must be used with explicit guardrails. |
| 63 | + |
| 64 | +Suggested workflow: |
| 65 | +- Use AI to draft CI/CD pipeline templates or job steps as a starting point (for example, generating a minimal GitHub Actions workflow). |
| 66 | +- Run the draft pipeline in a safe non-production environment or CI sandbox to validate syntax and basic behaviour. |
| 67 | +- Require a human reviewer to validate generated steps for correctness, idempotence, and security implications (especially around secrets, permissions, and external actions). |
| 68 | +- Add tests or smoke checks to the pipeline so changes can be validated automatically when the pipeline runs. |
| 69 | +- Promote approved templates into a central location (for example, `.github/workflows/` or a shared pipeline template repository) so teams reuse vetted, audited pipelines. |
| 70 | + |
| 71 | +Guardrails and checklist (before merging AI-generated pipeline changes): |
| 72 | +- [ ] Human review completed and documented in PR |
| 73 | +- [ ] No secrets or credentials are hard-coded |
| 74 | +- [ ] Required linting and syntax checks pass locally and in CI |
| 75 | +- [ ] Security and license scans run and report no critical issues |
| 76 | +- [ ] Pipeline steps are idempotent and have clear rollback strategies where applicable |
| 77 | +- [ ] Generated content is annotated in the PR description (e.g., "AI-assisted draft") so reviewers know to apply extra scrutiny |
| 78 | + |
| 79 | +Notes: |
| 80 | +- AI-generated pipelines are excellent for reducing boilerplate and accelerating iteration, but they do not replace domain knowledge and security review. |
| 81 | +- Maintain a small set of vetted pipeline templates to reduce risk and improve reproducibility. |
0 commit comments