-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (119 loc) · 5.11 KB
/
dotnet.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: .NET
on:
push:
branches: [ master ]
paths:
- .github/workflows/*
- src/*
- tests/*
pull_request:
branches: [ master ]
types:
- opened
- reopened
- synchronize
- closed
workflow_dispatch:
inputs:
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'
configuration:
required: true
description: "Configuration for builds"
default: 'Release'
jobs:
environment :
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 }}
steps:
- name: declare default values
id: defaults
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"
$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}}"
}
}
$values = @(
@("versionSuffix", $true, "$versionSuffix", "$versionSuffix"),
@("publishRelease", $true, "$publishRelease", "$publishRelease"),
@("verbosity", $true, "${{ github.event.inputs.verbosity }}", "minimal"),
@("configuration", $true, "${{ github.event.inputs.configuration }}", "Release")
)
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
- 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 }}
- 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