-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
139 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,163 @@ | ||
name: .NET | ||
name: CI | ||
|
||
permissions: | ||
contents: | ||
write | ||
pull-requests: | ||
write | ||
pages: | ||
write | ||
id-token: | ||
write | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
paths: | ||
paths: | ||
- .github/workflows/* | ||
- src/* | ||
- tests/* | ||
- src/**/* | ||
- tests/**/* | ||
|
||
pull_request: | ||
branches: [ master ] | ||
types: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- closed | ||
|
||
workflow_dispatch: | ||
- synchronize | ||
|
||
inputs: | ||
|
||
workflow_dispatch: | ||
inputs: | ||
versionPrefix: | ||
type: string | ||
description: e.g 1.1.1 | ||
default: "" | ||
|
||
versionSuffix: | ||
description: "Version suffix for nupkg" | ||
|
||
nugetRelease: | ||
required: true | ||
description: "release? (1/0)" | ||
default: '0' | ||
|
||
verbosity: | ||
required: true | ||
description: "verbosity of pipeline output" | ||
default: 'minimal' | ||
|
||
type: string | ||
description: e.g alpha.1 | ||
default: "alpha" | ||
|
||
publish: | ||
type: boolean | ||
description: run dotnet publish? | ||
default: true | ||
|
||
removePrereleases: | ||
type: boolean | ||
description: nuget unlist preleases? | ||
default: false | ||
|
||
configuration: | ||
required: true | ||
description: "Configuration for builds" | ||
default: 'Release' | ||
description: build configuration | ||
required: false | ||
default: Release | ||
type: choice | ||
options: | ||
- Debug | ||
- Release | ||
|
||
verbosity: | ||
description: build log verbosity | ||
required: false | ||
default: minimal | ||
type: choice | ||
options: | ||
- quiet | ||
- minimal | ||
- normal | ||
- detailed | ||
- diagnostic | ||
jobs: | ||
environment : | ||
|
||
parameters: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
versionSuffix : ${{ steps.defaults.outputs.versionSuffix }} | ||
publishRelease : ${{ steps.defaults.outputs.publishRelease }} | ||
verbosity : ${{ steps.defaults.outputs.verbosity }} | ||
configuration : ${{ steps.defaults.outputs.configuration }} | ||
outputs: | ||
versionSuffix: ${{ steps.parameters.outputs.versionSuffix }} | ||
versionPrefix: ${{ steps.parameters.outputs.versionPrefix }} | ||
configuration: ${{ steps.parameters.outputs.configuration }} | ||
verbosity: ${{ steps.parameters.outputs.verbosity }} | ||
publish: ${{ steps.parameters.outputs.publish }} | ||
package: ${{ steps.parameters.outputs.package }} | ||
publishSymbols: ${{ steps.parameters.outputs.publishSymbols }} | ||
removePrereleases: ${{ steps.parameters.outputs.removePrereleases }} | ||
skipTests: ${{ steps.parameters.outputs.skipTests }} | ||
runCoverage: ${{ steps.parameters.outputs.runCoverage }} | ||
|
||
steps: | ||
|
||
- name: declare default values | ||
id: defaults | ||
|
||
- name: nuget secret verification | ||
env: | ||
NUGET: ${{ secrets.NUGET }} | ||
if: "${{ env.NUGET == '' }}" | ||
uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
core.setFailed('"nuget" secret is missing') | ||
- name: Setting up parameters | ||
id: parameters | ||
shell: pwsh | ||
run: | | ||
$automaticTrigger = "$env:GITHUB_EVENT_NAME" -ne "workflow_dispatch" | ||
$mergePR = "master|pull_request|closed|true" -eq "${{github.base_ref}}|${{github.event_name}}|${{github.event.action}}|${{github.event.pull_request.merged}}" | ||
$publishRelease = ("${{ github.event.inputs.nugetRelease }}" -eq "1") -Or ($automaticTrigger -And $mergePR) | ||
Write-Host "publishRelease: $publishRelease, mergePR: $mergePR, automaticTrigger: $automaticTrigger" | ||
run: | | ||
Write-Host "Setting up parameters" | ||
$versionSuffix = ""; | ||
if($automaticTrigger) { | ||
if("${{github.base_ref}}" -eq "master") { | ||
$versionSuffix = "beta${{github.run_number}}" | ||
} else { | ||
$versionSuffix = "alpha${{github.run_number}}" | ||
} | ||
} else { | ||
if([string]::IsNullOrEmpty("${{ github.event.inputs.versionSuffix }}") -eq $true){ | ||
$versionSuffix = "" | ||
} else { | ||
$versionSuffix = "${{ github.event.inputs.versionSuffix }}${{github.run_number}}" | ||
} | ||
} | ||
$suffixMap = @{ | ||
"push"="alpha.${{github.run_number}}"; | ||
"pull_request"="beta.${{github.run_number}}"; | ||
"workflow_dispatch"="${{github.event.inputs.versionSuffix}}" | ||
}; | ||
$suffix = $suffixMap['${{github.event_name}}'] | ||
if( $suffixMap['workflow_dispatch'] -ne '' -and '${{github.event_name}}' -eq 'workflow_dispatch'){ | ||
$suffix = $($suffix.TrimEnd('.') + ".") | ||
$suffix = "$($suffix)${{github.run_number}}" | ||
} | ||
# key name workflow value fallback value | ||
$values = @( | ||
@("versionSuffix", $true, "$versionSuffix", "$versionSuffix"), | ||
@("publishRelease", $true, "$publishRelease", "$publishRelease"), | ||
@("verbosity", $true, "${{ github.event.inputs.verbosity }}", "minimal"), | ||
@("configuration", $true, "${{ github.event.inputs.configuration }}", "Release") | ||
) | ||
@("versionSuffix", "$suffix", "$suffix"), | ||
@("versionPrefix", "${{github.event.inputs.versionPrefix}}", "alpha"), | ||
@("configuration", "${{github.event.inputs.configuration}}", "Release"), | ||
@("verbosity", "${{github.event.inputs.verbosity}}", "minimal"), | ||
@("publish", "${{github.event.inputs.publish}}", "true"), | ||
@("package", "${{github.event.inputs.package}}", "true"), | ||
@("publishSymbols", "${{github.event.inputs.publishSymbols}}", "true"), | ||
@("removePrereleases", "${{github.event.inputs.removePrereleases}}", "false"), | ||
@("skipTests", "${{github.event.inputs.skipTests}}", "false"), | ||
@("runCoverage", "${{github.event.inputs.runCoverage}}", "true") | ||
) | ||
$manual = $('${{github.event_name}}' -eq 'workflow_dispatch') | ||
foreach($pair in $values){ | ||
$value = $pair[2] | ||
if($pair[1] -eq $true -And [string]::IsNullOrEmpty("$value") -eq $true){ | ||
$value = $pair[3] | ||
} | ||
Write-Host "Assigning $($pair[0]) => $value" | ||
echo "::set-output name=$($pair[0])::$value" | ||
} | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
needs: environment | ||
|
||
env: | ||
versionSuffix : ${{ needs.environment.outputs.versionSuffix }} | ||
publishRelease : ${{ needs.environment.outputs.publishRelease }} | ||
verbosity : ${{ needs.environment.outputs.verbosity }} | ||
configuration : ${{ needs.environment.outputs.configuration }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 5.0.x | ||
|
||
#- name: stop | ||
# run: exit 1 | ||
- name: Restore dependencies | ||
run: dotnet restore src/All.sln | ||
- name: Build | ||
run: dotnet build src/All.sln --verbosity $verbosity -c $configuration --no-restore | ||
- name: Test | ||
run: dotnet test src/All.sln --verbosity $verbosity -c $configuration --no-build | ||
|
||
- name: Pack | ||
if: ${{ needs.environment.outputs.publishRelease == 'True' }} | ||
run: dotnet pack src/Amusoft.XUnit.NLog.Extensions/Amusoft.XUnit.NLog.Extensions.csproj --verbosity $verbosity -c $configuration -o artifacts/nupkg --no-build /p:VersionSuffix=$versionSuffix | ||
$value = $pair[2] | ||
if($manual -eq $true){ | ||
$value = $pair[1] | ||
} | ||
Write-Host "Setting parameter $($pair[0]) => $value" | ||
#echo "::set-output name=$($pair[0])::$value" | ||
echo "$($pair[0])=$value" >> $env:GITHUB_OUTPUT | ||
} | ||
- name: Remove snupkg | ||
if: ${{ needs.environment.outputs.publishRelease == 'True' }} | ||
run: find artifacts/nupkg/ -name "*.snupkg" -type f -delete | ||
|
||
- name: Release | ||
if: ${{ needs.environment.outputs.publishRelease == 'True' }} | ||
run: dotnet nuget push "artifacts/nupkg/*.nupkg" -k $NUGETKEY -s https://api.nuget.org/v3/index.json | ||
env: | ||
NUGETKEY: ${{ secrets.NUGET }} | ||
package: | ||
needs: parameters | ||
uses: taori/actions/.github/workflows/nupkg.yml@v9 | ||
with: | ||
solutionPath: src/All.sln | ||
packProjects: src/Amusoft.XUnit.NLog.Extensions/Amusoft.XUnit.NLog.Extensions.csproj | ||
versionSuffix: ${{ needs.parameters.outputs.versionSuffix }} | ||
versionPrefix: ${{ needs.parameters.outputs.versionPrefix }} | ||
package: ${{ needs.parameters.outputs.package == 'true' }} | ||
publish: ${{ needs.parameters.outputs.publish == 'true' }} | ||
publishSymbols: ${{ needs.parameters.outputs.publishSymbols == 'true' }} | ||
removePrereleases: ${{ needs.parameters.outputs.removePrereleases == 'true' }} | ||
skipTests: ${{ needs.parameters.outputs.skipTests == 'true' }} | ||
configuration: ${{ needs.parameters.outputs.configuration }} | ||
verbosity: ${{ needs.parameters.outputs.verbosity }} | ||
runCoverage: ${{ needs.parameters.outputs.runCoverage == 'true' }} | ||
testArguments: "--filter Category!=SkipInCI" | ||
concurrencyAbortable: true | ||
coverageThreshold: '85 95' | ||
dotnetVersion: 6.0.x | ||
secrets: | ||
nuget: ${{ secrets.NUGET }} | ||
|
||
- name: Remove old prereleases | ||
if: ${{ needs.environment.outputs.publishRelease == 'True' && github.event_name =='workflow_dispatch' && needs.environment.outputs.versionSuffix == ''}} | ||
id: defaults | ||
shell: pwsh | ||
env: | ||
NUGETKEY: ${{ secrets.NUGET }} | ||
run: | | ||
& dotnet tool install --global NugetUnlister | ||
$packageVersion = Get-ChildItem -Recurse -Filter '*.nupkg' | select { $_.Name } -ExpandProperty Name -First 1 | Select-String -Pattern "\d[\d\w\.\+-]+(?=.nupkg)" | %{$_.Matches.Value} | ||
& nuget-unlist drop prereleasebefore Amusoft.XUnit.NLog.Extensions $packageVersion $env:NUGETKEY | ||