Skip to content

Commit

Permalink
Merge pull request #179 from Lombiq/issue/OSOE-501
Browse files Browse the repository at this point in the history
OSOE-501: Enable further analyzer rules for better code styling control and more in Lombiq.Analyzers.PowerShell
  • Loading branch information
sarahelsaig authored Jan 31, 2023
2 parents c7c410d + c316c63 commit c346e3c
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ param(
Write-Output "Adding release annotation with the release name `"$ReleaseName`"."

$annotation = @{
Id = [GUID]::NewGuid();
AnnotationName = $ReleaseName;
EventTime = (Get-Date).ToUniversalTime().GetDateTimeFormats("s")[0];
Id = [Guid]::NewGuid()
AnnotationName = $ReleaseName
EventTime = (Get-Date).ToUniversalTime().GetDateTimeFormats('s')[0]
# AI only displays annotations from the "Deployment" category so this must be this string.
Category = "Deployment";
Category = 'Deployment'
Properties = ConvertTo-Json $ReleaseProperties -Compress
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ param(
[string] $PullRequestId
)

$jiraBrowseUrl = $JiraBaseUrl + '/browse/';
$jiraBrowseUrl = $JiraBaseUrl + '/browse/'

$originalTitle = $Title
$originalBody = $Body

if ($Branch -NotLike "*issue*")
if ($Branch -NotLike '*issue*')
{
Exit
}
Expand All @@ -23,7 +23,7 @@ $issueLink = "[$issueKey]($jiraBrowseUrl$issuekey)"

if ($Title -NotLike "*$issueKey*")
{
$Title = $issueKey + ": " + $Title
$Title = $issueKey + ': ' + $Title
}

if (-Not $Body)
Expand All @@ -41,10 +41,10 @@ elseif ($Body -NotLike "*``[$issueKey``]``($jiraBrowseUrl$issuekey``)*")

if (($Title -ne $originalTitle) -or ($Body -ne $originalBody))
{
# Escape the quote characters. This is necessary because PowerShell mangles the quote characters when passing
# Escape the quote characters. This is necessary because PowerShell mangles the quote characters when passing
# arguments into a native command such as the GitHub CLI. See https://github.com/cli/cli/issues/3425 for details.
$Title = $Title -replace '"','\"'
$Body = $Body -replace '"','\"'
$Title = $Title -replace '"', '\"'
$Body = $Body -replace '"', '\"'

# See https://cli.github.com/manual/gh_pr_edit
gh pr edit $PullRequestId --title $Title --body $Body --repo $GitHubRepository
Expand Down
22 changes: 11 additions & 11 deletions .github/actions/build-dotnet/Build-DotNetSolutionOrProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ param (

function ConvertTo-Array([string] $rawInput)
{
$rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
$rawInput.Replace("`r", '').Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
}

Write-Output "Version number for the .NET build products: $Version"
Expand Down Expand Up @@ -42,25 +42,25 @@ $noErrors = $expectedErrorCodes.Count -eq 0

if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj)
{
Write-Output "::group::Gulp Extensions found. It needs to be explicitly built before the solution."
Write-Output '::group::Gulp Extensions found. It needs to be explicitly built before the solution.'

$startTime = [DateTime]::Now
dotnet build src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj @buildSwitches
$endTime = [DateTime]::Now

Write-Output ("Gulp Extensions build took {0:0.###} seconds." -f ($endTime - $startTime).TotalSeconds)
Write-Output "::endgroup::"
Write-Output ('Gulp Extensions build took {0:0.###} seconds.' -f ($endTime - $startTime).TotalSeconds)
Write-Output '::endgroup::'
}

# This prepares the solution or project with the Lombiq.Analyzers files. The output and exit code are discarded because
# they will be in error if there is a project without the LombiqNetAnalyzers target. Then there is nothing to do, and
# the target will still run on the projects that have it.
dotnet msbuild '-target:Restore;LombiqNetAnalyzers' $SolutionOrProject | Out-Null || bash -c 'true'

Write-Output "Building solution or project with ``dotnet build $SolutionOrProject $($buildSwitches -join " ")``."
Write-Output "Building solution or project with ``dotnet build $SolutionOrProject $($buildSwitches -join ' ')``."

$errorLines = New-Object "System.Collections.Generic.List[string]"
$errorCodes = New-Object "System.Collections.Generic.List[string]"
$errorLines = New-Object 'System.Collections.Generic.List[string]'
$errorCodes = New-Object 'System.Collections.Generic.List[string]'

$errorFormat = '^(.*)\((\d+),(\d+)\): error (.*)'
dotnet build $SolutionOrProject @buildSwitches 2>&1 | ForEach-Object {
Expand All @@ -69,7 +69,7 @@ dotnet build $SolutionOrProject @buildSwitches 2>&1 | ForEach-Object {
($null, $file, $line, $column, $message) = [regex]::Match($PSItem, $errorFormat, 'Compiled').Groups.Value

$errorLines.Add($PSItem)
if ($message.Contains(":")) { $errorCodes.Add($message.Split(":")[0].Trim()) }
if ($message.Contains(':')) { $errorCodes.Add($message.Split(':')[0].Trim()) }
if ($noErrors) { Write-Output "::error file=$file,line=$line,col=$column::$message" }
}

Expand All @@ -84,7 +84,7 @@ if ($expectedErrorCodes)
{
$errorCodes = $errorCodes | Sort-Object
$fail = 0
$report = New-Object "System.Text.StringBuilder" "`n"
$report = New-Object 'System.Text.StringBuilder' "`n"

if ($null -eq $errorCodes -or -not $errorCodes.Count)
{
Expand Down Expand Up @@ -115,11 +115,11 @@ if ($expectedErrorCodes)
if ($fail -gt 0)
{
Write-Warning $report.ToString() # We use warning so it doesn't stop prematurely.
Write-Output ("::error::Verification Mismatch " + ($errorLines -join " "))
Write-Output ('::error::Verification Mismatch ' + ($errorLines -join ' '))
exit 1
}

Write-Output "Verification complete, the solution or project only has the expected errors!"
Write-Output 'Verification complete, the solution or project only has the expected errors!'
exit 0
}

10 changes: 5 additions & 5 deletions .github/actions/build-dotnet/Test-Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ $expectedCodeAnalysisErrors = @'
'@

$switches = @{
Configuration = "Release"
SolutionOrProject = "../../../../../Lombiq.OSOCE.sln"
Verbosity = "quiet"
EnableCodeAnalysis = "true"
Version = "1.2.3"
Configuration = 'Release'
SolutionOrProject = '../../../../../Lombiq.OSOCE.sln'
Verbosity = 'quiet'
EnableCodeAnalysis = 'true'
Version = '1.2.3'
Switches = $buildSwitches
ExpectedCodeAnalysisErrors = $expectedCodeAnalysisErrors
CreateBinaryLog = $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,66 @@
)

$context = [string]::IsNullOrEmpty($IssueComponent) ? $GitHub.repository : $IssueComponent
$titleSuffix = $SuffixIssueTitles ? " in $context" : ""
$titleSuffix = $SuffixIssueTitles ? " in $context" : ''
Write-Output "Suffix: $titleSuffix"

switch ($GitHub.event_name)
{
"discussion"
'discussion'
{
$summary = "Respond to `"$($GitHub.event.discussion.title)`"$titleSuffix"
$description = $DiscussionJiraIssueDescription
$linkUrl = $GitHub.event.discussion.html_url
$linkTitle = "GitHub discussion"
$linkTitle = 'GitHub discussion'
}
"issues"
'issues'
{
$summary = "$($GitHub.event.issue.title)$titleSuffix"
$description = $IssueJiraIssueDescription
$linkUrl = $GitHub.event.issue.html_url
$linkTitle = "GitHub issue"
$linkTitle = 'GitHub issue'

foreach ($label in $GitHub.event.issue.labels)
{
$labelName = $label.name

if ($labelName -eq "bug")
if ($labelName -eq 'bug')
{
$type = "Bug"
$type = 'Bug'
break
}
elseif ($labelName -eq "enhancement")
elseif ($labelName -eq 'enhancement')
{
$type = "New Feature"
$type = 'New Feature'
break
}
}
}
"pull_request"
'pull_request'
{
$summary = "Review `"$($GitHub.event.pull_request.title)`"$titleSuffix"
$description = $PullReqestJiraIssueDescription
$linkUrl = $GitHub.event.pull_request.html_url
$linkTitle = "GitHub pull request"
$linkTitle = 'GitHub pull request'
}
default
{
$message = "Unknown event `"$($GitHub.event_name)`". Please only call this script for one of the following " +
"events: discussion, issues, pull_request."
$message = @(
"Unknown event `"$($GitHub.event_name)`". Please only call this script for one of the following events:"
'discussion, issues, pull_request.'
) -join ' '
Write-Error "::error::$message"
exit 1
}
}

if ($null -eq $type)
{
$type = "Task"
$type = 'Task'
}

Set-GitHubOutput "summary" $summary
Set-GitHubOutput "json-description" $($description | ConvertTo-Json)
Set-GitHubOutput "type" $type
Set-GitHubOutput "link-url" $linkUrl
Set-GitHubOutput "link-title" $linkTitle
Set-GitHubOutput 'summary' $summary
Set-GitHubOutput 'json-description' $($description | ConvertTo-Json)
Set-GitHubOutput 'type' $type
Set-GitHubOutput 'link-url' $linkUrl
Set-GitHubOutput 'link-title' $linkTitle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if ([string]::IsNullOrEmpty($Env:DISCUSSION_JIRA_ISSUE_DESCRIPTION))
{
$templates["DISCUSSION_JIRA_ISSUE_DESCRIPTION"] = @"
$templates['DISCUSSION_JIRA_ISSUE_DESCRIPTION'] = @'
h1. Summary
See the linked GitHub discussion, including all the comments. Please do all communication there, unless it's confidential or administrative.
Expand All @@ -12,16 +12,16 @@ h1. Checklist
h1. After resolve
Add notes here if anything needs to be done after the issue is resolved, like manual configuration changes. Write in English, suitable to be included in release notes.
"@
'@
}
else
{
$templates["DISCUSSION_JIRA_ISSUE_DESCRIPTION"] = $Env:DISCUSSION_JIRA_ISSUE_DESCRIPTION;
$templates['DISCUSSION_JIRA_ISSUE_DESCRIPTION'] = $Env:DISCUSSION_JIRA_ISSUE_DESCRIPTION
}

if ([string]::IsNullOrEmpty($Env:ISSUE_JIRA_ISSUE_DESCRIPTION))
{
$templates["ISSUE_JIRA_ISSUE_DESCRIPTION"] = @"
$templates['ISSUE_JIRA_ISSUE_DESCRIPTION'] = @'
h1. Summary
See the linked GitHub issue, including all the comments. Please do all communication there, unless it's confidential or administrative.
Expand All @@ -35,16 +35,16 @@ h1. Checklist
h1. After resolve
Add notes here if anything needs to be done after the issue is resolved, like manual configuration changes. Write in English, suitable to be included in release notes.
"@
'@
}
else
{
$templates["ISSUE_JIRA_ISSUE_DESCRIPTION"] = $Env:ISSUE_JIRA_ISSUE_DESCRIPTION;
$templates['ISSUE_JIRA_ISSUE_DESCRIPTION'] = $Env:ISSUE_JIRA_ISSUE_DESCRIPTION
}

if ([string]::IsNullOrEmpty($Env:PULL_REQUEST_JIRA_ISSUE_DESCRIPTION))
{
$templates["PULL_REQUEST_JIRA_ISSUE_DESCRIPTION"] = @"
$templates['PULL_REQUEST_JIRA_ISSUE_DESCRIPTION'] = @'
h1. Summary
See the linked GitHub pull request, including all the comments. Please do all communication there, unless it's confidential or administrative.
Expand All @@ -54,11 +54,11 @@ h1. Checklist
h1. After resolve
Add notes here if anything needs to be done after the issue is resolved, like manual configuration changes. Write in English, suitable to be included in release notes.
"@
'@
}
else
{
$templates["PULL_REQUEST_JIRA_ISSUE_DESCRIPTION"] = $Env:PULL_REQUEST_JIRA_ISSUE_DESCRIPTION;
$templates['PULL_REQUEST_JIRA_ISSUE_DESCRIPTION'] = $Env:PULL_REQUEST_JIRA_ISSUE_DESCRIPTION
}

return $templates
24 changes: 12 additions & 12 deletions .github/actions/msbuild/Build-DotNetFrameworkSolutionOrProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

function ConvertTo-Array([string] $rawInput)
{
$rawInput.Replace("`r", "").Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
$rawInput.Replace("`r", '').Split("`n") | ForEach-Object { $PSItem.Trim() } | Where-Object { $PSItem }
}

nuget restore $SolutionOrProject
Expand All @@ -23,32 +23,32 @@ $commonSwitches = ConvertTo-Array @"
-p:Version=$Version
"@

if ($TreatWarningsAsErrors -eq "true")
if ($TreatWarningsAsErrors -eq 'true')
{
$commonSwitches += ConvertTo-Array @"
$commonSwitches += ConvertTo-Array @'
--warnaserror
-p:TreatWarningsAsErrors=true
"@
'@
}

if (Test-Path src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj)
{
Write-Output "::group::Gulp Extensions found. It needs to be explicitly built before the solution."
Write-Output '::group::Gulp Extensions found. It needs to be explicitly built before the solution.'

# These need to be different than those for msbuild.
$gulpBuildSwitches = $commonSwitches + (ConvertTo-Array @"
$gulpBuildSwitches = $commonSwitches + (ConvertTo-Array @'
--configuration:Release
--nologo
--warnAsMessage:MSB3026
--consoleLoggerParameters:NoSummary
"@)
'@)

$startTime = [DateTime]::Now
dotnet build src/Utilities/Lombiq.Gulp.Extensions/Lombiq.Gulp.Extensions.csproj @gulpBuildSwitches
$endTime = [DateTime]::Now

Write-Output ("Gulp Extensions build took {0:0.###} seconds." -f ($endTime - $startTime).TotalSeconds)
Write-Output "::endgroup::"
Write-Output ('Gulp Extensions build took {0:0.###} seconds.' -f ($endTime - $startTime).TotalSeconds)
Write-Output '::endgroup::'
}

# -p:Retries and -p:RetryDelayMilliseconds are used to retry builds when they fail due to random locks.
Expand All @@ -59,7 +59,7 @@ $buildSwitches = $commonSwitches + (ConvertTo-Array @"
$Switches
"@)

Write-Output "Building solution or project with ``msbuild $SolutionOrProject $($buildSwitches -join " ")``."
Write-Output "Building solution or project with ``msbuild $SolutionOrProject $($buildSwitches -join ' ')``."

msbuild $SolutionOrProject @buildSwitches

Expand All @@ -72,11 +72,11 @@ msbuild $SolutionOrProject @buildSwitches

if ($?)
{
Write-Output "Build successful."
Write-Output 'Build successful.'
Stop-DotNetBuildServers
}
else
{
Write-Output "::error::Build failed. See the errors above in the build log."
Write-Output '::error::Build failed. See the errors above in the build log.'
exit 1
}
2 changes: 1 addition & 1 deletion .github/actions/publish-nuget/Update-ManifestVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$PackageVersion
)

$manifests = Get-ChildItem $WorkDir -File -Recurse -Filter "Manifest.cs" |
$manifests = Get-ChildItem $WorkDir -File -Recurse -Filter 'Manifest.cs' |
Select-String -List -Pattern '(OrchardCore.Modules.Manifest|OrchardCore.DisplayManagement.Manifest)' |
Select-Object -ExpandProperty Path

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-sql-server/Initialize-SqlServer.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if ($Env:RUNNER_OS -eq "Windows")
if ($Env:RUNNER_OS -eq 'Windows')
{
choco install sql-server-express --no-progress
}
Expand Down
Loading

0 comments on commit c346e3c

Please sign in to comment.