-
Notifications
You must be signed in to change notification settings - Fork 2
202 lines (195 loc) · 6.53 KB
/
test-build-release.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Test, Analyse and Release Project
on:
push:
branches:
- main
- dev
jobs:
test-build:
name: Build .NET and Analyse with SonarCloud
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install Coverage Tool
shell: powershell
run: |
dotnet tool install --global dotnet-coverage
- name: Prepare SonarCloud analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: >
.\.sonar\scanner\dotnet-sonarscanner begin
/k:"team-zomsa_aplib.net" /o:"team-zomsa"
/d:sonar.token="${{ secrets.SONAR_TOKEN }}"
/d:sonar.host.url="https://sonarcloud.io"
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
- name: Build the project
shell: powershell
run: |
dotnet build --no-incremental
- name: Upload build as Artifact
uses: actions/upload-artifact@v4
with:
name: build
path: Aplib.Core\bin
- name: Test the project
shell: powershell
run: |
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
- name: Run SonarCloud analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
create-release:
name: Create release
needs: test-build
runs-on: ubuntu-latest
permissions:
contents: write # To be able to publish a GitHub Release
issues: write # To be able to comment on related issues
pull-requests: write # To be able to comment on released pull requests
# id-token: write # To enable use of OIDC for npm provenance
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install Semantic Release
run: npm install semantic-release@23
- name: Install Semantic Release Dependencies
run: npm install @semantic-release/exec@6 @semantic-release/commit-analyzer@11 @semantic-release/release-notes-generator@12
- name: Create and Publish Release
id: create-release
run: |
npx semantic-release@23
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
upload-build:
name: Upload build to GitHub Release
needs: create-release
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Retrieve build from artifact
uses: actions/download-artifact@v4
with:
name: build
path: bin
- name: Get Latest Tag
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1.4.0
with:
fallback: v1.0.0
- name: Zip build
run: zip -r build.zip bin
- name: Upload build to release
uses: softprops/action-gh-release@v2
with:
files: build.zip
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.previoustag.outputs.tag }}
append_body: true
create-nuget-package:
name: Create NuGet Package
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Latest Tag
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1.4.0
with:
fallback: v1.0.0
- name: Get version from release tag
id: get-version
run: echo "::set-output name=tag::$(echo "${{ steps.previoustag.outputs.tag }}" | cut -c 2-)"
- name: Create NuGet Package
run: dotnet pack -c Release -o ./bin --include-source --include-symbols -p:Version=${{ steps.get-version.outputs.tag }} -p:SymbolPackageFormat=snupkg
- name: Upload NuGet Package
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: bin
upload-nuget-package-to-gh-release:
name: Upload NuGet Package to GitHub Release
needs: create-nuget-package
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Retrieve NuGet Package from artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: bin
- name: Get Latest Tag
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1.4.0
with:
fallback: v1.0.0
- name: Zip NuGet Package
run: zip -r nuget-package.zip bin/*.nupkg bin/*.snupkg
- name: Upload NuGet Package to release
uses: softprops/action-gh-release@v2
with:
files: nuget-package.zip
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.previoustag.outputs.tag }}
append_body: true
upload-to-nuget-org:
name: Upload NuGet Package to NuGet.org
needs: create-nuget-package
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Retrieve NuGet Package from artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: bin
- name: Upload NuGet Package to NuGet.org
run: dotnet nuget push bin/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate