diff --git a/.github/workflows/pr_labeler.yaml b/.github/workflows/pr_labeler.yaml index 9a3c67832..0ac925fc2 100644 --- a/.github/workflows/pr_labeler.yaml +++ b/.github/workflows/pr_labeler.yaml @@ -2,7 +2,7 @@ name: "PR Labeling" on: pull_request_target: types: [opened, closed, synchronize, reopened, edited, ready_for_review] - + permissions: contents: read pull-requests: write diff --git a/.github/workflows/validation_mrtk3.yaml b/.github/workflows/validation_mrtk3.yaml index 2f7e1f9c3..ae6c4a419 100644 --- a/.github/workflows/validation_mrtk3.yaml +++ b/.github/workflows/validation_mrtk3.yaml @@ -4,7 +4,7 @@ on: push: branches: - main - - 'feature/*' + - "feature/*" pull_request: jobs: @@ -12,22 +12,28 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v6 - - name: Get Pull Request changes - if: github.event_name == 'pull_request' - run: | - ${{ github.workspace }}/Pipelines/Scripts/gitchanges.ps1 -TargetBranch '${{ github.base_ref }}' -OutputFile '${{ runner.temp }}/build/changed_files.txt' -RepoRoot '${{ github.workspace }}' - shell: pwsh + - name: Get Pull Request changes + if: github.event_name == 'pull_request' + run: | + ${{ github.workspace }}/Pipelines/Scripts/gitchanges.ps1 -TargetBranch '${{ github.base_ref }}' -OutputFile '${{ runner.temp }}/build/changed_files.txt' -RepoRoot '${{ github.workspace }}' + shell: pwsh - - name: Scoped code validation - if: github.event_name == 'pull_request' - run: | - ${{ github.workspace }}/Pipelines/Scripts/validatecode.ps1 -Directory '${{ github.workspace }}' -ChangesFile '${{ runner.temp }}/build/changed_files.txt' - shell: pwsh + - name: Scoped code validation + if: github.event_name == 'pull_request' + run: | + ${{ github.workspace }}/Pipelines/Scripts/validatecode.ps1 -Directory '${{ github.workspace }}' -ChangesFile '${{ runner.temp }}/build/changed_files.txt' + shell: pwsh - - name: Global code validation - if: github.event_name == 'push' - run: | - ${{ github.workspace }}/Pipelines/Scripts/validatecode.ps1 -Directory '${{ github.workspace }}' - shell: pwsh \ No newline at end of file + - name: Global code validation + if: github.event_name == 'push' + run: | + ${{ github.workspace }}/Pipelines/Scripts/validatecode.ps1 -Directory '${{ github.workspace }}' + shell: pwsh + + - name: Check changelogs + if: github.event_name == 'pull_request' + run: | + ${{ github.workspace }}/Pipelines/Scripts/check-changelogs.ps1 -ChangesFile '${{ runner.temp }}/build/changed_files.txt' + shell: pwsh diff --git a/Pipelines/Scripts/check-changelogs.ps1 b/Pipelines/Scripts/check-changelogs.ps1 new file mode 100644 index 000000000..8ac993d1d --- /dev/null +++ b/Pipelines/Scripts/check-changelogs.ps1 @@ -0,0 +1,63 @@ +# Copyright (c) Mixed Reality Toolkit Contributors +# Licensed under the BSD 3-Clause + +<# +.SYNOPSIS + Validates that changelogs have been properly updated for changed files. +.DESCRIPTION + Validates that changelogs have been properly updated for changed files. +.EXAMPLE + .\check-changelogs.ps1 -ChangesFile c:\path\to\changes\file.txt +#> +param( + # The filename containing the list of files to scope the code validation + # to. This is useful in pull request validation when there isn't a need + # to check every single file in the repo for changes (i.e. only the list + # of changed files) + [Parameter(Mandatory = $true)] + [string]$ChangesFile +) + +$changelogUpdated = @{ } + +# If the file containing the list of changes was provided and actually exists, +# this validation should scope to only those changed files. +if ($ChangesFile -and (Test-Path $ChangesFile -PathType leaf)) { + Get-Content $ChangesFile | ForEach-Object { + Write-Host "Checking file: $_" + $packageName = $_ | Select-String -Pattern "org\.mixedrealitytoolkit\.\w+(\.\w+)*" | Select-Object -First 1 + + if (-not $packageName) { + return # this is not an MRTK package, so skip + } + + $packageName = $packageName.Matches[0].Value + + $isChangelog = $_ -match "CHANGELOG.md" + if ($changelogUpdated.ContainsKey($packageName)) { + if ($isChangelog) { + $changelogUpdated[$packageName] = $true + } + } + else { + $changelogUpdated[$packageName] = $isChangelog + } + } +} + +$containsIssue = $false +$changelogUpdated.GetEnumerator() | ForEach-Object { + if (-not $_.Value) { + Write-Warning "Package '$($_.Key)' has changes, but its CHANGELOG.md was not updated. This is not always an issue but usually is" + $containsIssue = $true + } +} + +if ($containsIssue) { + Write-Output "Potential issues found, please see above for details" + exit 1; +} +else { + Write-Output "No issues found" + exit 0; +}