-
Notifications
You must be signed in to change notification settings - Fork 4
149 lines (126 loc) · 4.92 KB
/
ci.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
149
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: 'CI'
on:
workflow_dispatch:
inputs:
deploy_nuget_locally:
type: boolean
description: 🚀 deploy package to GH private
default: false
push:
branches:
- 'main'
pull_request:
branches:
- '*'
release:
types:
- published
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
defaults:
run:
shell: pwsh
jobs:
create_nuget:
name: 📦 create NuGet
runs-on: ubuntu-latest
steps:
- name: 🤘 checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
- name: 🔎 setup .NET # Install the .NET SDK indicated in the global.json file
uses: actions/setup-dotnet@v4
- name: 🗎 update release notes
if: github.event_name == 'release'
env:
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_BODY: ${{ github.event.release.body }}
run: |
$name = $env:RELEASE_NAME
$body = $env:RELEASE_BODY
$releaseNotes = "# Release ${{ github.event.release.tag_name }}"
if($name){
$releaseNotes = $releaseNotes + " - " + $name
}
if($body){
$releaseNotes = $releaseNotes + "`r`n`r`n" + $body
}
foreach($propFile in (Get-ChildItem "${{ github.workspace }}" -Recurse -Include "*.csproj", "Directory.Build.props", "Directory.Build.targets")) {
Write-Host "Found project file '$propFile'"
$propFileDoc = [xml](Get-Content $propFile)
$releaseNotesNode = $propFileDoc.SelectSingleNode("Project//PropertyGroup/PackageReleaseNotes[starts-with(., 'RELEASE_NOTES_PLACEHOLDER')]")
if($releaseNotesNode.InnerText -ne $null)
{
Write-Host "`tPATCHING '$propFile' with new release notes"
$releaseNotesNode.InnerText = "$releaseNotes"
$propFileDoc.Save($propFile)
}
}
- name: 📦 pack
run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
- name: ⬆️ upload packages
uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
run_test:
name: 🧪 run tests
runs-on: ubuntu-latest
steps:
- name: 🤘 checkout
uses: actions/checkout@v4
- name: 🔎 setup .NET
uses: actions/setup-dotnet@v4
- name: 🧪 run tests and move results
run: |
dotnet test --configuration Release --logger "trx;LogFilePrefix=Test"
New-Item -Path 'TR' -ItemType Directory -Force | Out-Null
foreach($file in (Get-ChildItem -Recurse -Include *.trx)) {
$newFile = Join-Path (Get-Location).Path 'TR' "$($file.Directory.Parent.Name.Replace('Nemesis.TextParsers.', '').Replace('.Tests', ''))$($file.Name -replace 'Test_','_')"
Move-Item -Path "$($file.FullName)" -Destination "$newFile"
}
- name: ⬆️ upload test results
uses: actions/upload-artifact@v4
if: success() || failure() # run this step even if previous step failed
with:
name: TestResults
if-no-files-found: error
retention-days: 7
path: "**/*.trx"
- name: 📊 tests results
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: 📊 tests results
reporter: dotnet-trx
path: "**/*.trx"
fail-on-error: 'true'
fail-on-empty: 'true'
deploy:
name: 🚀 deploy
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_nuget_locally == 'true')
runs-on: ubuntu-latest
needs: [ create_nuget, run_test ]
steps:
- name: ⬇️ download packages
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: 🔎 setup .NET
uses: actions/setup-dotnet@v4
- name: 📦 publish NuGet package
env:
EVENT_NAME: ${{ github.event_name }}
run: |
$key = ($env:EVENT_NAME -eq 'release') ? "${{ secrets.NUGET_API_KEY }}" : "${{ secrets.GH_PACKAGE_REGISTRY_API_KEY }}"
$source = ($env:EVENT_NAME -eq 'release') ? "https://api.nuget.org/v3/index.json" : "https://nuget.pkg.github.com/MichalBrylka/index.json"
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "$key" --source "$source" --skip-duplicate
}