162 lines (134 loc) · 5.03 KB
/
build-release-publish.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
name: Build, Release, Publish
on:
push:
pull_request:
branches: [ "main" ]
jobs:
unit-test:
runs-on: ${{ matrix.os }}
needs: []
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- uses: actions/checkout@v4
with:
path: app
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- name: Build with dotnet
run: dotnet build --configuration Release
working-directory: app
- name: Generate coverage report
run: dotnet test --collect:"XPlat Code Coverage" --results-directory "test-results"
working-directory: app
- name: Move coverage report from GUID folder to test-results
run: find test-results -name "coverage.cobertura.xml" -exec mv {} test-results \;
shell: bash
working-directory: app
if: ${{ always() }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: app/test-results/coverage.cobertura.xml
fail_ci_if_error: true
if: ${{ always() && matrix.os == 'ubuntu-latest' }}
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
with:
name: testresults-unit-${{ matrix.os }}
path: app/test-results
if: ${{ always() }}
- name: Upload binaries as ${platform}-artifact
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.os }}
path: app/WikiPageStatsGenerator/bin/Release/net7.0/*
if: ${{ always() }}
release:
runs-on: ubuntu-latest
needs: [ unit-test ]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && secrets.ELEVATED_GITHUB_TOKEN || github.token }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Setup git
run: |
git config --local user.email "versionize-bot@by.vincent.mahn.ke"
git config --local user.name "Versionize Bot"
- name: Install Versionize
run: dotnet tool install --global Versionize
- name: Run Versionize
id: versionize
run: 'versionize --changelog-all --exit-insignificant-commits --commit-suffix " [skip ci]"'
continue-on-error: true
- name: No release required
if: steps.versionize.outcome != 'success'
run: echo "Skipping Release. No release required."
- name: Push changes to GitHub
if: steps.versionize.outcome == 'success'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
- name: Create NuPkg
if: steps.versionize.outcome == 'success'
run: dotnet pack --configuration Release
- name: Download ubuntu artifacts
if: steps.versionize.outcome == 'success'
uses: actions/download-artifact@v4
with:
name: binaries-ubuntu-latest
path: ubuntu-artifacts
- name: Download windows artifacts
if: steps.versionize.outcome == 'success'
uses: actions/download-artifact@v4
with:
name: binaries-windows-latest
path: windows-artifacts
- name: Download macos artifacts
if: steps.versionize.outcome == 'success'
uses: actions/download-artifact@v4
with:
name: binaries-macos-latest
path: macos-artifacts
- run: |
version=$(git describe --tags --abbrev=0)
zip -r WikiPageStatsGenerator-ubuntu-x64-$version.zip ubuntu-artifacts
zip -r WikiPageStatsGenerator-windows-x64-$version.zip windows-artifacts
zip -r WikiPageStatsGenerator-macos-x64-$version.zip macos-artifacts
zip -r WikiPageStatsGenerator-nupkg-x64-$version.zip WikiPageStatsGenerator/nupkg/*.nupkg -j
if: steps.versionize.outcome == 'success'
- name: "Create release with all artifacts"
if: steps.versionize.outcome == 'success'
run: |
version=$(git describe --tags --abbrev=0)
gh release create $version \
-t "$version" \
-R ${{ github.repository }} \
--target ${{ github.sha }} \
--title "$version" \
-F CHANGELOG.md \
WikiPageStatsGenerator-nupkg-x64-$version.zip \
WikiPageStatsGenerator-ubuntu-x64-$version.zip \
WikiPageStatsGenerator-windows-x64-$version.zip \
WikiPageStatsGenerator-macos-x64-$version.zip
env:
GITHUB_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
shell: bash
- name: Publish to NuGet
if: steps.versionize.outcome == 'success'
run: |
version=$(git describe --tags --abbrev=0)
dotnet nuget push WikiPageStatsGenerator/nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
env:
GITHUB_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
shell: bash