This commit is contained in:
Bernie White 2020-12-15 17:30:07 +10:00 коммит произвёл GitHub
Родитель 97101b88d7
Коммит 8d2a92da2e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 31 добавлений и 46 удалений

17
.github/workflows/analyze.yaml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
#
# Repository validation
#
name: Analyze
on:
- pull_request
jobs:
analyze:
name: Analyze repository
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run PSRule analysis
uses: Microsoft/ps-rule@main

Просмотреть файл

@ -2,53 +2,21 @@
# Licensed under the MIT License.
# Synopsis: Check for recommended community files
Rule 'OpenSource.Community' -Type 'System.IO.DirectoryInfo' {
$requiredFiles = @(
'CHANGELOG.md'
'LICENSE'
'CODE_OF_CONDUCT.md'
'CONTRIBUTING.md'
'SECURITY.md'
'README.md'
'.github/CODEOWNERS'
'.github/PULL_REQUEST_TEMPLATE.md'
)
Test-Path -Path $TargetObject.FullName;
for ($i = 0; $i -lt $requiredFiles.Length; $i++) {
$filePath = Join-Path -Path $TargetObject.FullName -ChildPath $requiredFiles[$i];
$Assert.Create((Test-Path -Path $filePath -PathType Leaf), "$($requiredFiles[$i]) does not exist");
}
Rule 'OpenSource.Community' -Type 'PSRule.Data.RepositoryInfo' {
$Assert.FilePath($TargetObject, 'FullName', @('CHANGELOG.md'));
$Assert.FilePath($TargetObject, 'FullName', @('LICENSE'));
$Assert.FilePath($TargetObject, 'FullName', @('CODE_OF_CONDUCT.md'));
$Assert.FilePath($TargetObject, 'FullName', @('CONTRIBUTING.md'));
$Assert.FilePath($TargetObject, 'FullName', @('SECURITY.md'));
$Assert.FilePath($TargetObject, 'FullName', @('README.md'));
$Assert.FilePath($TargetObject, 'FullName', @('.github/CODEOWNERS'));
$Assert.FilePath($TargetObject, 'FullName', @('.github/PULL_REQUEST_TEMPLATE.md'));
}
# Synopsis: Check for license in code files
Rule 'OpenSource.License' -Type 'System.IO.FileInfo' -If { $TargetObject.Extension -in '.cs', '.ts', '.ps1', '.psd1', '.psm1' } {
$commentPrefix = "`# ";
if ($TargetObject.Extension -in '.cs', '.ts') {
$commentPrefix = '// '
}
$header = GetLicenseHeader -CommentPrefix $commentPrefix;
$content = Get-Content -Path $TargetObject.FullName -Raw;
$content.StartsWith($header);
}
function global:GetLicenseHeader {
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(Mandatory = $True)]
[String]$CommentPrefix
)
process {
$text = @(
'Copyright (c) Microsoft Corporation.'
'Licensed under the MIT License.'
)
$builder = [System.Text.StringBuilder]::new();
foreach ($line in $text) {
$Null = $builder.Append($CommentPrefix);
$Null = $builder.Append($line);
$Null = $builder.Append([System.Environment]::NewLine);
}
return $builder.ToString();
}
Rule 'OpenSource.License' -Type '.cs', '.ps1', '.psd1', '.psm1', '.ts' {
$Assert.FileHeader($TargetObject, 'FullName', @(
'Copyright (c) Microsoft Corporation.'
'Licensed under the MIT License.'
));
}