Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMBQ-178: Fixing test-dotnet path resolution, adding the ability to pass environment variables and repository details to build workflows #381

Merged
merged 31 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2a86310
Pointing GHA to issue branch
Piedone Aug 9, 2024
df34f08
Resolving test project path form the solution path
Piedone Aug 9, 2024
2e023f8
Rename
Piedone Aug 9, 2024
b307911
Fixing path resolution for the actual test execution too
Piedone Aug 9, 2024
32d5ce7
Allowing running tests from individual projects too
Piedone Aug 9, 2024
23625e3
PS syntax
Piedone Aug 10, 2024
453cc15
Pointing GHA to issue branch
Piedone Aug 10, 2024
0cec687
Fixing check-spelling repo reference
Piedone Aug 10, 2024
97c88e2
And again
Piedone Aug 10, 2024
2ce5135
Adding ability to pass environment variables to build-build-and-test-…
Piedone Aug 10, 2024
d487481
Syntax
Piedone Aug 10, 2024
d796d37
Leftover rename
Piedone Aug 10, 2024
5d37bcc
GH workflow syntax
Piedone Aug 10, 2024
4c22595
Linting error
Piedone Aug 10, 2024
499ed47
Debug output
Piedone Aug 10, 2024
47653ae
Syntax
Piedone Aug 10, 2024
1c8f44e
Remove debug output
Piedone Aug 10, 2024
c4155ff
Revert "Remove debug output"
Piedone Aug 10, 2024
cdc8e52
Reapply "Remove debug output"
Piedone Aug 11, 2024
d33a32e
Adding ENVIRONMENT_VARIABLES_JSON to the other build workflows too
Piedone Aug 11, 2024
5ae1bde
Masking env vars passed to build workflows
Piedone Aug 11, 2024
31fb0d7
Adding "iframes" to spelling
Piedone Aug 11, 2024
1382e54
More common words
Piedone Aug 11, 2024
7a36718
Re-adding mistakenly removed code
Piedone Aug 11, 2024
67344d0
Informational output
Piedone Aug 12, 2024
a6fbc2e
Ability to pass the repository explicitly to build-and-test-orchard-core
Piedone Aug 12, 2024
65f9bb0
Ability to pass a ref to build-and-test-orchard-core too
Piedone Aug 12, 2024
075fb6e
Ability to pass repository details in the other build workflows too
Piedone Aug 12, 2024
ae3b01e
Renaming Invoke-SolutionTests to reflect that it also supports projects
Piedone Aug 14, 2024
eb1ed64
Adding newline at the end of the file
DemeSzabolcs Aug 15, 2024
54aabeb
Updating action and workflow references to dev
DemeSzabolcs Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved

- name: Add Azure Application Insights Release Annotation
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/auto-merge-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check Mergeability
id: check-mergeability
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/auto-transition-jira-issue/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check if Should Done
id: check-done
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/build-dotnet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Setup & Detect Cache Configuration
id: detect-cache-configuration
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/cancel-workflow/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Cancel Workflow
# Fork PRs won't have a token with write access to Actions, thus won't be able to cancel the workflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check Current Workflow Equals Latest
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/check-merge-queue-adds/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check Merge Queue Adds
id: check-merge-queue-adds
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/check-pull-request-labels/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check Labels
id: check-labels
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/check-pull-request-reviews/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Check Reviews
id: check-reviews
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/checkout/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Set Checkout Token
uses: Lombiq/GitHub-Actions/.github/actions/set-checkout-token@dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

# Don't do anything for pull requests that are already related to an issue, i.e. their titles start with an issue
# key.
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/get-changed-files-from-git-diff/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ runs:
- name: Setup
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH

- name: Git Diff
id: git-diff
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/get-changed-gha-items/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
- name: Setup
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH

- name: Get GHA Items
id: get-gha-items
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-dotnet-tool/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH
- name: Install tool
shell: pwsh
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/markdown-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ runs:

- name: Setup Scripts
shell: pwsh
run: (Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
run: (Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Copy files updated by markdown-lint automatic fixes
if: inputs.fix == 'true'
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/msbuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Add MSBuild to PATH
# v2.0.0
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/publish-nuget/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Setup NuGet Version
id: setup
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/set-checkout-token/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Set Checkout Token
shell: pwsh
Expand Down
25 changes: 25 additions & 0 deletions .github/actions/set-environment-variables/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Set Environment Variables
description: >
Set environment variables from a JSON string of key-value pairs, passed in via the ENVIRONMENT_VARIABLES_JSON
environment variable. Intentionally not documented in Actions.md since it's only meant for internal use.

runs:
using: composite
steps:
- name: Setup Scripts
if: ${{ env.ENVIRONMENT_VARIABLES_JSON }}
shell: pwsh
run: |
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Set Environment Variables
if: ${{ env.ENVIRONMENT_VARIABLES_JSON }}
shell: pwsh
run: |
$envVars = ConvertFrom-Json $env:ENVIRONMENT_VARIABLES_JSON
foreach ($key in $envVars.PSObject.Properties.Name)
{
Write-Output "Setting environment variable $key."
Write-Output "::add-mask::$($envVars.$key)"
Set-GitHubEnv $key $envVars.$key
}
2 changes: 1 addition & 1 deletion .github/actions/set-gha-refs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runs:
- name: Setup
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH

- name: Set References
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-dotnet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

- name: Set Environment Variables
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-sql-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Setup
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH

- name: Set up SQL Server
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/spelling/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ runs:
- name: Setup Scripts
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
'${{ github.action_path }}' >> $Env:GITHUB_PATH
(Resolve-Path '${{ github.action_path }}/../../../Scripts').Path >> $Env:GITHUB_PATH

# If the configuration path doesn't exist in the workspace, then it means that the workspace repository doesn't have
# its own spell-checking configuration. In that case we don't need to copy anything, because the configuration files
Expand Down
2 changes: 2 additions & 0 deletions .github/actions/spelling/dictionaries/Lombiq.common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ hastlayer
hca
HHmmss
hotfixes
htmlvalidate
idx
iframes
iis
img
importmap
Expand Down
1 change: 1 addition & 0 deletions .github/actions/spelling/dictionaries/Security.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
amd
clickjacking
CORS
Entra
nosniff
openapi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
param (
[string] $Solution,
[string] $SolutionOrProject,
[string] $Verbosity,
[string] $Filter,
[string] $Configuration,
Expand Down Expand Up @@ -44,40 +44,58 @@ $connectionString = @(
$Env:Lombiq_Tests_UI__SqlServerDatabaseConfiguration__ConnectionStringTemplate = $connectionString
$Env:Lombiq_Tests_UI__BrowserConfiguration__Headless = 'true'

$solutionName = [System.IO.Path]::GetFileNameWithoutExtension($Solution)
$solutionDirectory = [System.IO.Path]::GetDirectoryName($Solution)

Write-Output "Running tests for the $Solution solution."

Write-Output 'Gathering test projects.'

$tests = dotnet sln $Solution list |
Select-Object -Skip 2 |
Select-String '\.Tests\.' |
Select-String -NotMatch 'Lombiq.Tests.UI.csproj' |
Select-String -NotMatch 'Lombiq.Tests.csproj' |
Where-Object {
# While the test projects are run individually, passing in the solution name and solution dir via the
# conventional MSBuild properties allows build customization.
$switches = @(
"--configuration:$Configuration"
'--list-tests'
"--verbosity:$Verbosity"
"-p:SolutionName=""$solutionName"""
"-p:SolutionDir=""$solutionDirectory"""
)

# Without Out-String, Contains() below won't work for some reason.
$output = dotnet test @switches $PSItem 2>&1 | Out-String -Width 9999

if ($LASTEXITCODE -ne 0)
{
Write-Error "::error::dotnet test failed for the project $PSItem with the following output:`n$output"
exit 1
if ($SolutionOrProject -like '*.sln')
{
$solutionName = [System.IO.Path]::GetFileNameWithoutExtension($SolutionOrProject)
$solutionDirectory = [System.IO.Path]::GetDirectoryName($SolutionOrProject)

Write-Output "Running tests for the $SolutionOrProject solution."

Write-Output 'Gathering test projects.'

$tests = dotnet sln $SolutionOrProject list |
Select-Object -Skip 2 |
Select-String '\.Tests\.' |
Select-String -NotMatch 'Lombiq.Tests.UI.csproj' |
Select-String -NotMatch 'Lombiq.Tests.csproj' |
ForEach-Object {
$absolutePath = Resolve-Path -Path (Join-Path -Path $solutionDirectory -ChildPath $PSItem)

# While the test projects are run individually, passing in the solution name and solution dir via the
# conventional MSBuild properties allows build customization.
$switches = @(
"--configuration:$Configuration"
'--list-tests'
"--verbosity:$Verbosity"
"-p:SolutionName=""$solutionName"""
"-p:SolutionDir=""$solutionDirectory"""
)

# Without Out-String, Contains() below won't work for some reason.
$output = dotnet test @switches $absolutePath 2>&1 | Out-String -Width 9999

if ($LASTEXITCODE -ne 0)
{
Write-Error "::error::dotnet test failed for the project $absolutePath with the following output:`n$output"
exit 1
}

if (-not [string]::IsNullOrEmpty($output) -and $output.Contains('The following Tests are available'))
{
$absolutePath
}
}

-not [string]::IsNullOrEmpty($output) -and $output.Contains('The following Tests are available')
}
}
elseif ($SolutionOrProject -like '*.csproj')
{
Write-Output "Running tests for the $SolutionOrProject project."
$tests = @($SolutionOrProject)
}
else
{
Write-Error "The $SolutionOrProject is not a solution or project file."
exit 1
}

Set-GitHubOutput 'test-count' $tests.Length
Set-GitHubOutput 'dotnet-test-hang-dump' 0
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/test-dotnet/Test-SolutionTests.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<#
.Synopsis
Local testing script to run the Invoke-SolutionTests script. This needs to be invoked from the solution folder.
Local testing script to run the Invoke-SolutionOrProjectTests script. This needs to be invoked from the solution folder.
#>

$switches = @{
Solution = '.\Lombiq.OSOCE.sln'
SolutionOrProject = '.\Lombiq.OSOCE.sln'
Verbosity = 'quiet'
Filter = ''
Configuration = 'Debug'
BlameHangTimeout = '600000'
TestProcessTimeout = '600000'
}

.\tools\Lombiq.GitHub.Actions\.github\actions\test-dotnet\Invoke-SolutionTests.ps1 @switches
.\tools\Lombiq.GitHub.Actions\.github\actions\test-dotnet\Invoke-SolutionOrProjectTests.ps1 @switches
Loading
Loading