Update CI.yml #103
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
name: CI | |
permissions: | |
contents: | |
write | |
pull-requests: | |
write | |
pages: | |
write | |
id-token: | |
write | |
on: | |
push: | |
branches: [ main ] | |
paths: | |
- .github/workflows/* | |
- src/**/* | |
- tests/**/* | |
pull_request: | |
branches: [ main ] | |
types: | |
- opened | |
- synchronize | |
workflow_dispatch: | |
inputs: | |
versionPrefix: | |
type: string | |
description: e.g 1.1.1 | |
default: "" | |
versionSuffix: | |
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: | |
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: | |
parameters: | |
runs-on: ubuntu-latest | |
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: 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: | | |
Write-Host "Setting up parameters" | |
$branch = "main" | |
$conf = "${{github.event.inputs.configuration}}" | |
$verb = "${{github.event.inputs.verbosity}}" | |
$publ = "${{github.event.inputs.publish}}" | |
$removePrereleases = "${{github.event.inputs.removePrereleases}}" | |
$prefix = "${{github.event.inputs.versionPrefix}}" | |
$suffix = "${{github.event.inputs.versionSuffix}}" | |
$bnr = "${{github.run_number}}" | |
$commitMode = "noop" | |
if("${{github.event_name}}" -eq "workflow_dispatch"){ | |
$commitMode = "dispatch" | |
} | |
else | |
{ | |
$commitModeMergedPr = "$branch|pull_request|closed|true" -eq "${{github.base_ref}}|${{github.event_name}}|${{github.event.action}}|${{github.event.pull_request.merged}}" | |
$commitModePush = "$branch|push" -eq "${{github.base_ref}}|${{github.event_name}}" | |
if($commitModeMergedPr -eq $true) | |
{ | |
$commitMode = "pushMerge" | |
} | |
if($commitModeMergedPr -eq $true) | |
{ | |
$commitMode = "push" | |
} | |
} | |
$data = @{ #prefix #suffix #configuration #verbosity #publish #removeprerelease | |
"dispatch" = @("$prefix", "$suffix", "$conf", "$verb", "$publ", "$removePrereleases") | |
"push" = @("", "alpha.$bnr", "Release", "n", "true", "false") | |
"pushMerge" = @("", "beta.$bnr", "Release", "n", "true", "false") | |
"noop" = @("", "noop", "Release", "n", "false", "false") | |
}; | |
$names = @("versionPrefix","versionSuffix","configuration","verbosity","publish","removePrereleases") | |
if($data[$commitMode] -eq $null){ | |
Write-Host "Unidentified commit mode $commitMode" | |
echo "Commit mode could not be identified." >> $env:GITHUB_STEP_SUMMARY | |
exit 1; | |
} | |
foreach($item in $names){ | |
$index = $names.IndexOf($item) | |
Write-Host "$item=$($data[$commitMode][$index])" | |
echo "$item=$($data[$commitMode][$index])" >> $env:GITHUB_OUTPUT | |
echo "$item=$($data[$commitMode][$index])" >> $env:GITHUB_STEP_SUMMARY | |
} | |
package: | |
needs: parameters | |
uses: taori/actions/.github/workflows/nupkg.yml@v9 | |
with: | |
solutionPath: src/Amusoft.DotnetNew.Tests.sln | |
packProjects: src/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests.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 }} | |