Skip to content

Commit 78fea0d

Browse files
committed
Add PR validation for AssemblyInfo.cs
1 parent 304e401 commit 78fea0d

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

scripts/ci/common.psm1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,20 @@ function IsMetaFile {
107107
process {
108108
[IO.Path]::GetExtension($Filename).ToLower() -eq ".meta"
109109
}
110-
}
110+
}
111+
112+
<#
113+
.SYNOPSIS
114+
Returns true if the given file is a Unity asmdef file and
115+
false otherwise. Uses the extension of the file, not the actual
116+
content to determine this.
117+
#>
118+
function IsAsmDef {
119+
[CmdletBinding()]
120+
param(
121+
[string]$Filename
122+
)
123+
process {
124+
[IO.Path]::GetExtension($Filename).ToLower() -eq ".asmdef"
125+
}
126+
}

scripts/ci/validatecode.ps1

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,25 @@ function CheckForActualFile {
274274
}
275275
}
276276

277+
<#
278+
.SYNOPSIS
279+
Checks if all assembly definitions have a corresponding AssemblyInfo.cs checked in.
280+
Returns true if the AssemblyInfo is missing.
281+
#>
282+
function CheckForAssemblyInfo {
283+
[CmdletBinding()]
284+
param(
285+
[string]$FileName
286+
)
287+
process {
288+
if (-not (Test-Path (Join-Path -Path (Split-Path $FileName) -ChildPath "AssemblyInfo.cs"))) {
289+
Write-Warning "AssemblyInfo.cs missing for $FileName. Please be sure to check it in alongside this asmdef."
290+
$true;
291+
}
292+
$false;
293+
}
294+
}
295+
277296
function CheckScript {
278297
[CmdletBinding()]
279298
param(
@@ -346,9 +365,9 @@ function CheckUnityScene {
346365
[string]$FileName
347366
)
348367
process {
349-
# Checks if there is more than one MixedRealityPlayspace objects in each example unity scene
350368
$containsIssue = $false
351369

370+
# Checks if there is more than one MixedRealityPlayspace objects in each example unity scene
352371
$MatchesPlayspaces = Select-String MixedRealityPlayspace $FileName -AllMatches
353372
$NumPlayspaces = $MatchesPlayspaces.Matches.Count
354373

@@ -369,6 +388,22 @@ function CheckUnityScene {
369388
}
370389
}
371390

391+
function CheckAssemblyDefinition {
392+
[CmdletBinding()]
393+
param(
394+
[string]$FileName
395+
)
396+
process {
397+
$containsIssue = $false
398+
399+
if (CheckForAssemblyInfo $FileName) {
400+
$containsIssue = $true
401+
}
402+
403+
$containsIssue
404+
}
405+
}
406+
372407
# If the file containing the list of changes was provided and actually exists,
373408
# this validation should scope to only those changed files.
374409
if ($ChangesFile -and (Test-Path $ChangesFile -PathType leaf)) {
@@ -383,7 +418,8 @@ if ($ChangesFile -and (Test-Path $ChangesFile -PathType leaf)) {
383418
if (((IsCSharpFile -Filename $changedFile) -and (CheckScript $changedFile)) -or
384419
((IsAssetFile -Filename $changedFile) -and (CheckAsset $changedFile)) -or
385420
((IsUnityScene -Filename $changedFile) -and (CheckUnityScene $changedFile)) -or
386-
((IsMetaFile -Filename $changedFile) -and (CheckForActualFile $changedFile))) {
421+
((IsMetaFile -Filename $changedFile) -and (CheckForActualFile $changedFile)) -or
422+
((IsAsmDef -Filename $changedFile) -and (CheckAssemblyDefinition $changedFile))) {
387423
$containsIssue = $true;
388424
}
389425
}
@@ -420,6 +456,13 @@ else {
420456
$containsIssue = $true
421457
}
422458
}
459+
460+
$asmdefs = Get-ChildItem $Directory *.asmdef -File -Recurse | Select-Object FullName
461+
foreach ($asmdef in $asmdefs) {
462+
if (CheckAssemblyDefinition $asmdef.FullName) {
463+
$containsIssue = $true
464+
}
465+
}
423466
}
424467

425468
$folders = Get-ChildItem $Directory -Directory -Recurse | Select-Object FullName

0 commit comments

Comments
 (0)