-
Notifications
You must be signed in to change notification settings - Fork 4
167 lines (146 loc) · 5.77 KB
/
czishrink_dotnet.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
---
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
permissions:
pull-requests: write
contents: read
name: .NET Build (CziShrink)
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch: {}
jobs:
build:
defaults:
run:
working-directory: czishrink
name: ${{matrix.config.os}}-${{matrix.build}}
runs-on: ${{matrix.config.os}}
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
strategy:
fail-fast: false
matrix:
build: [Release, Debug]
config:
- {os: windows-latest, osfamily: win}
- {os: ubuntu-latest, osfamily: linux}
exclude:
# From https://github.com/actions/runner/issues/1512
- build: Debug
config: {os: windows-latest, osfamily: win}
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Get dotnet version from global.json
id: get_dotnet_version
run: |
$global_json = Get-Content -Path "./global.json" | ConvertFrom-Json
$dotnetversion = $global_json.sdk.version
"dotnetversion=$dotnetversion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
shell: pwsh
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.get_dotnet_version.outputs.dotnetversion }}
- name: Print .NET version
run: dotnet --version
- name: Get Version from Directory.Build.props
id: getversion
run: |
$xml = [xml](Get-Content -Path "Directory.Build.props")
$version = $xml.SelectSingleNode('//VersionPrefix').'#text'
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
shell: pwsh
- name: Add build ID to version in Directory.Build.props
run: |
Write-Output "Add build ID ${{ github.run_id }} to VersionPrefix in Directory.Build.props"
$file = Get-Item "Directory.Build.props"
$xml = [xml](Get-Content -Path $file.FullName)
$versionElement = $xml.SelectSingleNode('//VersionPrefix')
$versionElement.'#text' += '+${{ github.run_id }}'
$xml.Save($file.FullName)
shell: pwsh
- name: Cache nugets
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-czishrink-nuget-${{ hashFiles('czishrink/**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-czishrink-nuget-
- name: Restore dependencies
run: dotnet restore --locked-mode
- name: Build
run: dotnet build --no-restore -c ${{ matrix.build }}
- name: Test
run: >
dotnet test
-c ${{ matrix.build }}
--no-build
--verbosity normal
--logger trx
--results-directory "TestResults"
-p:CollectCoverage=true
-p:CoverletOutputFormat=cobertura
-p:CoverletOutput=${{ github.workspace }}/TestResults/coverage.cobertura.xml
-p:ExcludeByAttribute=GeneratedCodeAttribute%2cObsoleteAttribute
-p:ExcludeByFile=**/*.axaml%2c**/*.g.cs
-p:Exclude='[netczicompress]netczicompress.Views.*'
- name: Upload coverage reports for czishrink to Codecov
if: ${{ (matrix.config.os == 'ubuntu-latest') && (matrix.build == 'Debug') }}
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
directory: ${{ github.workspace }}/TestResults
files: coverage.cobertura.xml
verbose: true
token: ${{ secrets.CODECOV_TOKEN }} # required
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
with:
name: dotnet-results-${{ matrix.config.os }}-${{ matrix.build }}
path: TestResults
# Use always() to also publish test results when there are test failures
if: ${{ always() }}
- name: Publish
if: matrix.build == 'Release'
run: >
dotnet publish netczicompress.Desktop/netczicompress.Desktop.csproj
-c ${{ matrix.build }}
-a x64
--self-contained
-p:PublishSingleFile=true
-p:PublishReadyToRun=true
-p:PublishReadyToRunShowWarnings=true
-o ${{ github.workspace }}/publish
- name: Upload published binaries
uses: actions/upload-artifact@v4
if: ${{ (github.event_name != 'pull_request') && (matrix.build == 'Release') }}
with:
name: CziShrink_${{ steps.getversion.outputs.version }}_${{ matrix.config.osfamily}}-x64
path: publish
- name: Restore Wix installer project
if: ${{ matrix.build == 'Release' && matrix.config.os == 'windows-latest' }}
working-directory: czishrink\netczicompress.Installer\CziShrinkMSI
env:
ArtifactsDirectory: ${{ github.workspace }}/publish
run: dotnet restore --locked-mode
- name: Build Wix installer
if: ${{ matrix.build == 'Release' && matrix.config.os == 'windows-latest' }}
working-directory: czishrink\netczicompress.Installer\CziShrinkMSI
env:
ArtifactsDirectory: ${{ github.workspace }}/publish
run: >
dotnet build
-c ${{ matrix.build }}
--no-restore
-o ${{ github.workspace }}/installer
- name: Upload Wix installer
uses: actions/upload-artifact@v4
if: ${{ (github.event_name != 'pull_request') && (matrix.build == 'Release') && (matrix.config.os == 'windows-latest') }}
with:
name: CziShrink_Installer${{ steps.getversion.outputs.version }}_${{ matrix.config.osfamily}}-x64
path: installer