Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions .github/workflows/CommitMessage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,33 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
pip install --upgrade gitlint
- name: Lint git commit messages
shell: bash
# run the linter and tee the output to a file, this will make the check fail but allow us to use the results in summary
run: gitlint --ignore body-is-missing --commits origin/$GITHUB_BASE_REF.. 2>&1 | tee check_results.log
- name: Propegate Error Summary
id: lint_commit_messages
shell: pwsh
run: ./Build/Agent/commit-messages.ps1
- name: Propagate Error Summary
id: commit_message_summary
if: always()
shell: bash
# put the output of the commit message linting into the summary for the job and in an environment variable
run: |
# Change the commit part of the log into a markdown link to the commit
commitsUrl="https:\/\/github.com\/${{ github.repository_owner }}\/${{ github.event.repository.name }}\/commit\/"
sed -i "s/Commit \([0-9a-f]\{7,40\}\)/[commit \1]($commitsUrl\1)/g" check_results.log
# Put the results into the job summary
cat check_results.log >> "$GITHUB_STEP_SUMMARY"
# Put the results into a multi-line environment variable to use in the next step
echo "check_results<<###LINT_DELIMITER###" >> "$GITHUB_ENV"
echo "$(cat check_results.log)" >> "$GITHUB_ENV"
echo "###LINT_DELIMITER###" >> "$GITHUB_ENV"
shell: pwsh
run: >
./Build/Agent/publish-commit-message-summary.ps1
-LintOutcome '${{ steps.lint_commit_messages.outcome }}'
-RepositoryOwner '${{ github.repository_owner }}'
-RepositoryName '${{ github.event.repository.name }}'
# add a comment on the PR if the commit message linting failed
- name: Comment on PR
if: failure()
if: steps.lint_commit_messages.outcome == 'failure'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Commit Comment
message: |
⚠️ Commit Message Format Issues ⚠️
${{ env.check_results }}
[WARN] Commit message format issues
${{ steps.commit_message_summary.outputs.check_results }}
- name: Clear PR Comment
if: success()
if: steps.lint_commit_messages.outcome == 'success'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Commit Comment
only_update: true
hide: true
hide_classify: "RESOLVED"

4 changes: 2 additions & 2 deletions .github/workflows/check-whitespace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
fetch-depth: 0

- name: Run whitespace check script
shell: bash
run: bash ./Build/Agent/check-whitespace.sh
shell: pwsh
run: ./Build/Agent/check-whitespace.ps1
15 changes: 14 additions & 1 deletion Build/Agent/check-and-fix-whitespace.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Continue'

$resultsLogPath = 'check-results.log'
$checkSucceededCode = 0
$checkFoundIssuesCode = 2

if (Test-Path -LiteralPath $resultsLogPath) {
Remove-Item -LiteralPath $resultsLogPath -Force
}

& "$PSScriptRoot/check-whitespace.ps1"
$ec = $LASTEXITCODE

& "$PSScriptRoot/fix-whitespace.ps1"
if ($ec -eq $checkSucceededCode -or $ec -eq $checkFoundIssuesCode) {
& "$PSScriptRoot/fix-whitespace.ps1"
}
else {
Write-Error 'Whitespace checker failed unexpectedly; skipping fixer.'
}

exit $ec
6 changes: 0 additions & 6 deletions Build/Agent/check-and-fix-whitespace.sh

This file was deleted.

25 changes: 18 additions & 7 deletions Build/Agent/check-whitespace.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Mirrored from .github/workflows/check-whitespace.yml, ported to PowerShell for local use
# Exits non-zero if any whitespace problems are found
# Runs the whitespace check used by CI and local validation.
# Exit codes:
# 0 = checker completed and found no whitespace issues
# 2 = checker completed and found whitespace issues
# 1 = checker could not complete successfully

$ErrorActionPreference = 'Stop'

$resultsLogPath = 'check-results.log'

if (Test-Path -LiteralPath $resultsLogPath) {
Remove-Item -LiteralPath $resultsLogPath -Force
}

New-Item -ItemType File -Path $resultsLogPath -Force | Out-Null

# Import shared git helpers
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. (Join-Path $ScriptDir 'GitHelpers.ps1')
Expand Down Expand Up @@ -34,9 +45,9 @@ if (-not $baseSha) {

Write-Host "Base ref: $baseRef ($baseSha)"

# Run git log --check and tee output to a file (like CI)
# Run git log --check and tee output to a file for later inspection.
$log = git log --check --pretty=format:'---% h% s' "$baseSha.." 2>&1
$null = $log | Tee-Object -FilePath check-results.log
$null = $log | Tee-Object -FilePath $resultsLogPath -Append
$log | Out-Host

$problems = New-Object System.Collections.Generic.List[string]
Expand All @@ -46,7 +57,7 @@ $commitTextmd = ''
$repoPath = Get-RepoPath
$headRef = (git rev-parse --abbrev-ref HEAD 2>$null)

Get-Content check-results.log | ForEach-Object {
$log | ForEach-Object {
$line = $_
switch -regex ($line) {
'^---\s' {
Expand Down Expand Up @@ -83,14 +94,14 @@ Get-Content check-results.log | ForEach-Object {
}

if ($problems.Count -gt 0) {
Write-Host "`u26A0`uFE0F Please review the output for further information."
Write-Host '[WARN] Please review the output for further information.'
Write-Host '### A whitespace issue was found in one or more of the commits.'
Write-Host 'This check validates commit history from origin/main..HEAD, not just the current working tree.'
Write-Host 'If the report names an older commit, fix the file and then amend, squash, or rebase so that commit no longer appears in the branch history.'
Write-Host ''
Write-Host 'Errors:'
$problems | ForEach-Object { Write-Host $_ }
exit 1
exit 2
}

Write-Host 'No problems found'
Expand Down
72 changes: 0 additions & 72 deletions Build/Agent/check-whitespace.sh

This file was deleted.

38 changes: 31 additions & 7 deletions Build/Agent/commit-messages.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# Mirrored from .github/workflows/CommitMessage.yml, ported to PowerShell
# Installs gitlint and lints commit messages since PR base (or origin default branch)
# Runs the commit-message lint used by CI and local validation.
# Exits with gitlint's exit code.

$ErrorActionPreference = 'Stop'

$resultsLogPath = 'check_results.log'

if (Test-Path -LiteralPath $resultsLogPath) {
Remove-Item -LiteralPath $resultsLogPath -Force
}

New-Item -ItemType File -Path $resultsLogPath -Force | Out-Null

# Import shared git helpers
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
. (Join-Path $ScriptDir 'GitHelpers.ps1')

# Ensure Python/pip can install gitlint
python -m pip install --upgrade gitlint
function Install-GitLint {
$pythonCommand = $null
foreach ($candidate in @('python', 'python3')) {
if (Get-Command $candidate -ErrorAction SilentlyContinue) {
$pythonCommand = $candidate
break
}
}

if (-not $pythonCommand) {
throw 'Unable to locate python or python3 to install gitlint.'
}

& $pythonCommand -m pip install --upgrade gitlint
}

if (-not (Get-Command gitlint -ErrorAction SilentlyContinue)) {
Install-GitLint
}

# Ensure we have up-to-date refs
git fetch origin 2>$null | Out-Null
Expand All @@ -25,11 +50,10 @@ else {
$range = 'HEAD~20..HEAD'
}

# Run gitlint and tee to check_results.log like CI
# Note: PowerShell uses Tee-Object instead of POSIX tee
# Run gitlint and tee output to a file for CI summaries and local inspection.
$cmd = @('gitlint', '--ignore', 'body-is-missing', '--commits', $range)
Write-Host "Running: $($cmd -join ' ')"
$proc = & gitlint --ignore body-is-missing --commits $range 2>&1 | Tee-Object -FilePath check_results.log
$proc = & gitlint --ignore body-is-missing --commits $range 2>&1 | Tee-Object -FilePath $resultsLogPath -Append
$exit = $LASTEXITCODE
$proc | Out-Host
exit $exit
32 changes: 0 additions & 32 deletions Build/Agent/commit-messages.sh

This file was deleted.

5 changes: 3 additions & 2 deletions Build/Agent/fix-whitespace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ if (Test-Path -LiteralPath 'check-results.log') {
}
if (-not $fixFiles -or $fixFiles.Count -eq 0) {
$base = Get-BaseRef
Write-Host "Fixing whitespace for files changed since $base..HEAD"
$fixFiles = git diff --name-only "$base"..HEAD
Write-Host "Fixing whitespace for files changed on the current branch since it diverged from $base"
Write-Host "This compares merge-base($base, HEAD) to HEAD, so only branch-introduced file changes are considered."
$fixFiles = git diff --name-only "$base...HEAD"
}

$files = $fixFiles | Where-Object { $_ -and (Test-Path $_) }
Expand Down
36 changes: 0 additions & 36 deletions Build/Agent/fix-whitespace.sh

This file was deleted.

Loading
Loading