Core Spark (Azuredevopswiki)

Azuredevopswiki

An Azure DevOps wiki helper

The Git trunk-based development or single-branch strategy is a version control practice where all developers work on a single main branch (often called "trunk" or "main") rather than creating multiple long-lived branches. This strategy is popular in modern software development due to its simplicity and alignment with continuous integration/continuous deployment (CI/CD) practices. write a wiki page to summarize the trunk-based strategy in Azure DevOps include flows for developers Explain how to write build and release pipelines in Azure DevOps pipelines. Discuss how release approval gates can help document the approval process for code to get into production. Explain the flow for both new work and a hot fix situation. Explain how to use GIT tags to flag commits that get deployed to production. Explain how to identify what is in production and how to create branch for the purpose of a hot fix. Also explain that this should be very rare and an outlier. Include basic pros and cons of this approach Include real validated links to resources that discuss the trunk line git strategy in more detail.


Responses From Spark Variants that Implement the Core Spark (AzureDevOpsWiki)

[[_TOC_]]

# Trunk-Based Development Strategy

The Git trunk-based development or single-branch strategy is a version control practice where all developers work on a single main branch (often called "trunk" or "main") rather than creating multiple long-lived branches. This strategy is popular in modern software development due to its simplicity and alignment with continuous integration/continuous deployment (CI/CD) practices.

## Developer Workflow

### New Work

1. Pull the latest changes from the `main` branch.
2. Create a short-lived feature branch for your work.
3. Develop and test the feature.
4. Merge the feature branch back into `main` as soon as possible.
5. Ensure all tests pass and the code is reviewed.

### Hotfix

1. Identify the issue in production.
2. Create a hotfix branch from the `main`.
3. Develop and test the fix.
4. Merge the hotfix branch back into `main`.
5. Tag the commit that includes the fix.
6. Deploy to production.

## Build and Release Pipelines in Azure DevOps

### Build Pipeline

```yaml
trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '5.x'
    installationPath: $(Agent.ToolsDirectory)/dotnet

- script: dotnet build --configuration Release
  displayName: 'Build project'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
```

### Release Pipeline

```yaml
stages:
- stage: Deploy
  jobs:
  - deployment: DeployWeb
    environment: 'Production'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo Deploying to Production
            displayName: 'Deploy'
```

## Release Approval Gates

Release approval gates in Azure DevOps help document the approval process for code to get into production. These gates can include:

- Manual approvals by designated team members.
- Automated checks such as running additional tests or security scans.
- Compliance checks to ensure all necessary criteria are met before deployment.

## Using Git Tags for Production Deployments

Git tags can be used to flag commits that get deployed to production. For example, you can tag a commit with `v1.0.0` to signify a release.

```bash
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
```

This helps in tracking which version is currently in production.

## Identifying Production Versions and Creating Hotfix Branches

To identify what is in production, you can check the latest tag in the `main` branch.

```bash
git log --tags --simplify-by-decoration --pretty="format:%ci %d"
```

Creating a branch for a hotfix should be rare and treated as an outlier. When necessary, create a hotfix branch from the `main`.

```bash
git checkout main
git pull
git checkout -b hotfix-issue-123
```

## Pros and Cons of Trunk-Based Development

### Pros

- Simplifies the CI/CD pipeline.
- Reduces the complexity of merging long-lived branches.
- Encourages frequent integration, reducing integration hell.
- Aligns well with modern DevOps practices.

### Cons

- Requires high discipline in maintaining code quality.
- May lead to more frequent but smaller releases.
- Potential for more frequent conflicts that need resolving.

## Additional Resources

- [Trunk-Based Development](https://trunkbaseddevelopment.com)
- [Continuous Integration with Trunk-Based Development](https://martinfowler.com/articles/continuousIntegration.html)

By following the trunk-based development strategy and using proper CI/CD practices, teams can achieve faster, more reliable software delivery.