-
Notifications
You must be signed in to change notification settings - Fork 4
154 lines (129 loc) · 6.06 KB
/
main.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
150
151
152
153
154
name: ENMARCHA NuGet
on:
push:
branches:
- releases/**
- main
paths-ignore:
- '/**/*.md'
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
branches:
- releases/**
- main
workflow_dispatch:
env:
BuildConfiguration: ${{ (startsWith(github.ref, 'refs/heads/releases') || startsWith(github.ref, 'refs/heads/main')) && 'Release' || 'Debug' }}
jobs:
CI:
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.PassOutputReleaseVersion.releaseVersion }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Java for SonarCloud
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '21'
- name: Using .NET from 'global.json'
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore NuGet Packages
run: dotnet restore --configfile NuGet.config --verbosity Minimal
- name: Sonar - Install SonarCloud scanners
run: dotnet tool install --global dotnet-sonarscanner --version 6.0.0
- name: Sonar - Begin Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"${{ secrets.SONAR_ORGANIZATION }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.exclusions="**/tst/**/*" /d:sonar.cs.opencover.reportsPaths="**/tst/**/coverage.opencover.xml"
- name: Test
run: dotnet test --nologo --no-restore --collect:"XPlat Code Coverage" --configuration ${{env.BuildConfiguration}} --settings coverlet.runsettings
- name: Install Report Generator Tool
run: dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools --ignore-failed-sources
- name: Generate Coverage Report
run: ./tools/reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:coverage/Cobertura -reporttypes:'MarkdownSummaryGithub;Cobertura'
- name: Publish Coverage Report
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage/Cobertura/
- name: Write Coverage Report to Job Summary
run: cat coverage/Cobertura/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
- name: Build & Pack Libraries
run: dotnet pack --nologo --no-restore --configuration ${{env.BuildConfiguration}} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:SourceLinkCreate=true -p:DebugType=full --output nupkg
- name: Sonar - End Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Zip Libraries
run: |
cd ${{ github.workspace }}/nupkg
zip -r nupkg.zip *
mv ./nupkg.zip ${{ github.workspace }}
- name: Upload Libraries for Continuous Deployment
uses: actions/upload-artifact@v4
with:
name: enmarcha-libraries-${{ github.run_number }}
path: nupkg.zip
CD:
runs-on: ubuntu-latest
needs: CI
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/heads/releases') || github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Read and Store Version
id: PassOutputReleaseVersion
shell: pwsh
run: |
$xml = [Xml] (Get-Content "${{ github.workspace }}/Directory.Build.props")
$prefix = [System.Linq.Enumerable]::FirstOrDefault($xml.Project.PropertyGroup.VersionPrefix, [Func[object,bool]]{ param($x) $x -ne $null })
$suffix = [System.Linq.Enumerable]::FirstOrDefault($xml.Project.PropertyGroup.VersionSuffix, [Func[object,bool]]{ param($x) $x -ne $null })
$release_version = ($prefix, $suffix) | ? { $_ } | Join-String -Separator "-"
echo "RELEASE_VERSION=$release_version" >> $env:GITHUB_OUTPUT
- name: Download Libraries for Continuous Deployment
uses: actions/download-artifact@v4
with:
name: enmarcha-libraries-${{ github.run_number }}
path: ./
- name: Unzip Libraries
run: |
cd ${{ github.workspace }}
unzip nupkg.zip -d nupkg
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# When retrying a failed workflow, already published packages will be skipped without error.
- name: Push Libraries to NuGet.org
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Create Tag
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a "Release-${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}" -m "Version from build ${{ github.run_number }}"
- name: Create Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: "v${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}"
title: "Release ${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}"
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="$title" \
--generate-notes
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
releaseAssetName: enmarcha-libraries-${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}.zip
tag: "v${{ steps.PassOutputReleaseVersion.outputs.RELEASE_VERSION }}"
run: |
mv nupkg.zip $releaseAssetName
gh release upload "$tag" "$releaseAssetName" --repo="$GITHUB_REPOSITORY"