Added repository validation (#51)
This commit is contained in:
Родитель
9bb7f71fba
Коммит
90e7fce3d5
|
@ -0,0 +1,19 @@
|
||||||
|
#
|
||||||
|
# Dependabot configuration
|
||||||
|
#
|
||||||
|
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
|
||||||
|
# Maintain dependencies for GitHub Actions
|
||||||
|
- package-ecosystem: 'github-actions'
|
||||||
|
directory: '/'
|
||||||
|
schedule:
|
||||||
|
interval: 'daily'
|
||||||
|
labels:
|
||||||
|
- 'ci-quality'
|
||||||
|
reviewers:
|
||||||
|
- 'microsoft/psrule-rules-kubernetes'
|
|
@ -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.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
# Synopsis: Check for recommended community files
|
# Synopsis: Check for recommended community files
|
||||||
Rule 'OpenSource.Community' -Type 'System.IO.DirectoryInfo' {
|
Rule 'OpenSource.Community' -Type 'PSRule.Data.RepositoryInfo' {
|
||||||
$requiredFiles = @(
|
$Assert.FilePath($TargetObject, 'FullName', @('CHANGELOG.md'));
|
||||||
'CHANGELOG.md'
|
$Assert.FilePath($TargetObject, 'FullName', @('LICENSE'));
|
||||||
'LICENSE'
|
$Assert.FilePath($TargetObject, 'FullName', @('CODE_OF_CONDUCT.md'));
|
||||||
'CODE_OF_CONDUCT.md'
|
$Assert.FilePath($TargetObject, 'FullName', @('CONTRIBUTING.md'));
|
||||||
'CONTRIBUTING.md'
|
$Assert.FilePath($TargetObject, 'FullName', @('SECURITY.md'));
|
||||||
'SECURITY.md'
|
$Assert.FilePath($TargetObject, 'FullName', @('README.md'));
|
||||||
'README.md'
|
$Assert.FilePath($TargetObject, 'FullName', @('.github/CODEOWNERS'));
|
||||||
'.github/CODEOWNERS'
|
$Assert.FilePath($TargetObject, 'FullName', @('.github/PULL_REQUEST_TEMPLATE.md'));
|
||||||
'.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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Synopsis: Check for license in code files
|
# Synopsis: Check for license in code files
|
||||||
Rule 'OpenSource.License' -Type 'System.IO.FileInfo' -If { $TargetObject.Extension -in '.cs', '.ps1', '.psd1', '.psm1' } {
|
Rule 'OpenSource.License' -Type '.cs', '.ps1', '.psd1', '.psm1' {
|
||||||
$commentPrefix = "`# ";
|
$Assert.FileHeader($TargetObject, 'FullName', @(
|
||||||
if ($TargetObject.Extension -eq '.cs') {
|
|
||||||
$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.'
|
'Copyright (c) Microsoft Corporation.'
|
||||||
'Licensed under the MIT License.'
|
'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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче