Skip to content

Commit

Permalink
feat: Implement conventional commit validation stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Takla authored and mahdichtioui committed Dec 6, 2024
1 parent 7da83f2 commit 7c08a8d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 9 deletions.
16 changes: 12 additions & 4 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ trigger:
- main

variables:
#-if false
- name: IsReleaseBranch
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
#-endif
- template: build/variables.yml

stages:
- stage: Commit_Validation
dependsOn: []
jobs:
- template: build/stage-commit-validation.yaml

#-if false
# This special if is used to remove those Dotnet_New stages for generated application.
- stage: Dotnet_New_GeneratedApp
dependsOn: Commit_Validation
jobs:
- template: .template.config/build/stage-donetnew.yaml

Expand All @@ -49,7 +59,7 @@ stages:
iosVariableGroup: 'ApplicationTemplate.Distribution.Internal.iOS'

- stage: Publish_Template_Package
condition: and(succeeded(), eq(variables['IsLightBuild'], 'false'))
condition: and(succeeded(), eq(variables['IsLightBuild'], 'false'), eq(variables['IsReleaseBranch'], 'true'))
dependsOn:
- Build_Staging_GeneratedApp
- Build_Staging
Expand All @@ -58,9 +68,7 @@ stages:

#-endif
- stage: Build_Staging
#-if false
dependsOn: []
#-endif
dependsOn: Commit_Validation
jobs:
- template: build/stage-build.yml
parameters:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

Prefix your items with `(Template)` if the change is about the template and not the resulting application.

## 3.6.X
- Added conventional commit validation stage `stage-build.yml`

## 3.5.X
- Bump Uno packages to 5.2.121 to fix a crash on iOS.
- Ensure NV.Template.Mobile nuget is only deployed from the main branch.
- Updated `System.Text.Json` to resolve security vulnerabilities.
- Remove UWP references in Diagnostics.md
- Updated `Refit` package to 8.0.0 to address security advisory.
- Updated `MallardMessageHandlers` package to 2.0.0.

## 3.4.X
- Added a kill switch feature to the app.
Expand Down
7 changes: 7 additions & 0 deletions build/stage-commit-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This stage is responsible for running the template to validate the commits of the PR
jobs:
- job: OnWindows_ValidateCommits
pool:
vmImage : $(windowsHostedAgentImage)
steps:
- template: templates/validate-commits.yaml
46 changes: 46 additions & 0 deletions build/templates/validate-commits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This template is used to validate that the commit messages follow the Conventional Commits specification (https://www.conventionalcommits.org/en/v1.0.0/).
# Consider placing this at the beginning of the build pipeline to ensure that the commits are valid before proceeding with longer build steps.
steps:
- task: PowerShell@2
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
targetType: 'inline'
script: |
# Pre-Validation Logging
Write-Host "Starting PR Validation..."
Write-Host "Source Branch: $(System.PullRequest.SourceBranch)"
Write-Host "Target Branch: $(System.PullRequest.TargetBranch)"
Write-Host "Pull Request ID: $(System.PullRequest.PullRequestId)"
write-Host "Repository: $(Build.Repository.Name)"
Write-Host "Build.SourceBranch: $(Build.SourceBranch)"
# Fetch commit range
Write-Host "Retrieving commits..."
git fetch origin
Write-Host "Commit Range: origin/$(System.PullRequest.TargetBranch)..origin/$(System.PullRequest.SourceBranch)"
$commits = git log origin/$(System.PullRequest.TargetBranch)..origin/$(System.PullRequest.SourceBranch) --pretty=format:"%H %B"
$commitCount = ($commits | Measure-Object).Count
Write-Host "Commits found: $commitCount"
# Regex pattern for Conventional Commits
$pattern = '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\.\-]+\))?(!)?: ([\w ])+([\s\S]*)|^(Merged PR \d+: .+)|^(Merge pull request #/d+ from .+)|^(Merge branch .+)'
Write-Host "Regular Expression: $pattern"
# Validate each commit message
$invalidCommits = @()
foreach ($commit in $commits -split "`n") {
$commitMessage = $commit.Substring($commit.IndexOf(" ") + 1)
Write-Host "Validating commit: $commitMessage"
if ($commitMessage -notmatch $pattern) {
$invalidCommits += $commitMessage
}
}
if($invalidCommits.count -gt 0) {
Write-Error "The following commit messages do no follow the Conventional Commits standard: `n$($invalidCommits -join "`n")"
exit 1
} else {
Write-Host "All commit messages are valid."
}
displayName: 'Validate Commit Messages'
4 changes: 2 additions & 2 deletions doc/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The page also allows you to manually set some configuration values.
It also has various diagnostics utilities such as the following.
- Send information via email (including log files as attachements).
- Throw exceptions from various threads (to test the error handling or crash reporting).
- Open the settings folder where the settings files can be found (UWP only).
- Open the settings folder where the settings files can be found (WinUI only).

## Http Debugger

Expand All @@ -52,7 +52,7 @@ Check the following for more details.
- [`IHttpDebuggerService`](..\src\app\ApplicationTemplate.Access\Framework\HttpDebugger\IHttpDebuggerService.cs)
- [`HttpDebuggerHandler`](..\src\app\ApplicationTemplate.Access\Framework\HttpDebugger\HttpDebuggerHandler.cs)
- [`HttpDebuggerViewModel`](..\src\app\ApplicationTemplate.Presentation\ViewModels\Diagnostics\HttpDebugger\HttpDebuggerViewModel.cs)
- [`HttpDebuggerView`](..\src\app\ApplicationTemplate.UWP\Views\Content\Diagnostics\HttpDebuggerView.xaml)
- [`HttpDebuggerView`](..\src\app\ApplicationTemplate.Shared.Views\Content\Diagnostics\HttpDebuggerView.xaml)

## Configuration Debugger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.0" />
<PackageReference Include="Reactive.Annex" Version="2.0.0" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="ReviewService.Abstractions" Version="1.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="MallardMessageHandlers" Version="1.2.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="MallardMessageHandlers" Version="2.0.0" />
<PackageReference Include="Nventive.Persistence.Reactive" Version="0.5.0" />
<PackageReference Include="Nventive.Persistence" Version="0.5.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
Expand Down

0 comments on commit 7c08a8d

Please sign in to comment.