-
Notifications
You must be signed in to change notification settings - Fork 2
117 lines (113 loc) · 4.79 KB
/
workflow.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
name: CI/CD
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
name: Build job
runs-on: ubuntu-latest
outputs:
Version: ${{ steps.gitversion.outputs.SemVer }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: 5.x
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Variable Substitution appsettings file for tests
uses: microsoft/variable-substitution@v1
with:
files: 'src/DotNetCensus.Tests/appsettings.json'
env:
AppSettings.GitHubClientId: "${{ secrets.GitHubClientId }}"
AppSettings.GitHubClientSecret: "${{ secrets.GitHubClientSecret }}"
- name: .NET test
run: dotnet test src/DotNetCensus.Tests/DotNetCensus.Tests.csproj -c Debug -e:CollectCoverage=true -e:CoverletOutput=${{ github.workspace }}/TestResults/ -e:CoverletOutputFormat=lcov # using -e parameter to set an environment variable until the /p parameter is fixed: https://github.com/coverlet-coverage/coverlet/issues/1391
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ github.workspace }}/TestResults/coverage.info
- name: .NET pack tool to NuGet package
run: dotnet pack src/DotNetCensus/DotNetCensus.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}'
- name: Upload package back to GitHub
uses: actions/upload-artifact@v4
with:
name: nugetToolPackage
path: src/DotNetCensus/nupkg
- name: .NET pack core projecty to NuGet package
run: dotnet pack src/DotNetCensus.Core/DotNetCensus.Core.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}'
- name: Upload package back to GitHub
uses: actions/upload-artifact@v4
with:
name: nugetCorePackage
path: src/DotNetCensus.Core/nupkg
sonarCloud:
name: Run SonarCloud analysis
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Run Sonarcloud test
uses: samsmithnz/[email protected]
with:
projects: 'src/DotNetCensus/DotNetCensus.csproj,src/DotNetCensus.Core/DotNetCensus.Core.csproj,src/DotNetCensus.Tests/DotNetCensus.Tests.csproj'
dotnet-version: '8.0.x'
sonarcloud-organization: 'samsmithnz-github'
sonarcloud-project: 'samsmithnz_DotNetCensus'
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}'
release:
name: Release job
runs-on: ubuntu-latest
needs:
- build
- sonarCloud
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: nugetToolPackage
path: nugetToolPackage
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: nugetCorePackage
path: nugetCorePackage
- name: Display GitVersion outputs
run: |
echo "Version: ${{ needs.build.outputs.Version }}"
echo "CommitsSinceVersionSource: ${{ needs.build.outputs.CommitsSinceVersionSource }}"
- name: Create Release
uses: ncipollo/release-action@v1
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only create a release if there has been a commit/version change
with:
tag: "v${{ needs.build.outputs.Version }}"
name: "v${{ needs.build.outputs.Version }}"
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
- name: Publish nuget tool package to nuget.org
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only publish a NuGet package if there has been a commit/version change
run: dotnet nuget push nugetToolPackage\*.nupkg --api-key "${{ secrets.NUGETTOOLTOKEN }}" --source "https://api.nuget.org/v3/index.json"
shell: pwsh
- name: Publish nuget core package to nuget.org
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only publish a NuGet package if there has been a commit/version change
run: dotnet nuget push nugetCorePackage\*.nupkg --api-key "${{ secrets.NUGETCORETOKEN }}" --source "https://api.nuget.org/v3/index.json"
shell: pwsh