|
1 | | -name: Build, test, pack, push (Release) |
| 1 | +name: Build, pack, push (Release) |
| 2 | + |
2 | 3 | on: |
3 | | - workflow_dispatch: |
4 | | - inputs: |
5 | | - releaseNotes: |
6 | | - description: 'Release Notes (use `n for new line)' |
7 | | - required: true |
8 | | -jobs: |
9 | | - build: |
10 | | - runs-on: windows-latest |
11 | | - env: |
12 | | - ACTIONS_ALLOW_UNSECURE_COMMANDS: true |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +jobs: |
| 9 | + pack-push-ci: |
| 10 | + runs-on: windows-latest |
13 | 11 | steps: |
14 | | - - uses: actions/checkout@v4 |
| 12 | + - uses: actions/checkout@v5 |
15 | 13 | name: Checkout Code |
16 | 14 |
|
17 | | - - name: Install additional .NET SDKs |
18 | | - uses: actions/setup-dotnet@v4 |
| 15 | + - name: Check github.ref starts with 'refs/tags/' |
| 16 | + if: ${{ !startsWith(github.ref, 'refs/tags/') }} |
| 17 | + shell: bash |
| 18 | + run: | |
| 19 | + echo Error! github.ref does not start with 'refs/tags' |
| 20 | + echo github.ref: ${{ github.ref }} |
| 21 | + exit 1 |
| 22 | +
|
| 23 | + - name: Set version number environment variable |
| 24 | + env: |
| 25 | + github_ref: ${{ github.ref }} |
| 26 | + shell: bash |
| 27 | + run: | |
| 28 | + version="${github_ref:10}" |
| 29 | + echo version=$version |
| 30 | + echo "version=$version" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + - name: Install .NET SDK |
| 33 | + uses: actions/setup-dotnet@v5 |
19 | 34 | with: |
20 | | - dotnet-version: | |
21 | | - 1.0.x |
22 | | - 2.0.x |
23 | | - 5.0.x |
24 | | - 6.0.x |
25 | | - 8.0.x |
| 35 | + dotnet-version: 8.0.x |
| 36 | + source-url: https://api.nuget.org/v3/index.json |
| 37 | + env: |
| 38 | + NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}} |
26 | 39 |
|
27 | | - - name: Restore NuGet Packages |
28 | | - run: dotnet restore |
29 | | - |
30 | | - - name: Build library |
31 | | - run: dotnet build -c Release --no-restore |
| 40 | + - name: Build NuGet packages |
| 41 | + shell: bash |
| 42 | + run: dotnet pack -c Release -p:Version=$version -o out |
32 | 43 |
|
33 | 44 | - name: Upload artifacts |
34 | 45 | uses: actions/upload-artifact@v4 |
35 | 46 | with: |
36 | | - name: Compiled project |
37 | | - path: ${{ github.workspace }} |
38 | | - |
39 | | - test: |
40 | | - needs: build |
41 | | - runs-on: windows-latest |
42 | | - steps: |
43 | | - - name: Download artifacts |
44 | | - uses: actions/download-artifact@v4 |
45 | | - with: |
46 | | - name: Compiled project |
47 | | - path: ${{ github.workspace }} |
48 | | - |
49 | | - - name: Install additional .NET SDKs |
50 | | - uses: actions/setup-dotnet@v4 |
51 | | - with: |
52 | | - dotnet-version: | |
53 | | - 1.0.x |
54 | | - 2.0.x |
55 | | - 5.0.x |
56 | | - 6.0.x |
57 | | - 8.0.x |
58 | | -
|
59 | | - - name: Run test .NET 3.5 |
60 | | - working-directory: QRCoderTests |
61 | | - run: dotnet test -c Release -f net35 --nologo --no-build # No coverage for NET3.5 because of bug in combination with Coverlet+Stronh naming |
62 | | - |
63 | | - - name: Run test .NET 4.52 |
64 | | - working-directory: QRCoderTests |
65 | | - run: dotnet test -c Release -f net452 --nologo --no-build # No coverage for NET4.5 because of bug in combination with Coverlet+Strong naming |
66 | | - |
67 | | - - name: Run test .NET Core 1.1 |
68 | | - working-directory: QRCoderTests |
69 | | - run: dotnet test -c Release -f netcoreapp1.1 --nologo # No coverage for .NETCORE 1.1 because Coverlet doesn't support it https://github.com/coverlet-coverage/coverlet/issues/466 |
70 | | - |
71 | | - - name: Run test .NET Core 2.0 |
72 | | - working-directory: QRCoderTests |
73 | | - run: dotnet test -c Release -f netcoreapp2.0 --nologo /p:CollectCoverage=true /p:CoverletOutputFormat=opencover |
74 | | - |
75 | | - - name: Run test .NET 5.0 |
76 | | - working-directory: QRCoderTests |
77 | | - run: dotnet test -c Release -f net5.0 --nologo --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover |
78 | | - |
79 | | - - name: Run test .NET 5.0 Windows |
80 | | - working-directory: QRCoderTests |
81 | | - run: dotnet test -c Release -f net5.0-windows --nologo --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover |
82 | | - |
83 | | - - name: Run test .NET 6.0 |
84 | | - working-directory: QRCoderTests |
85 | | - run: dotnet test -c Release -f net6.0 --nologo --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover |
86 | | - |
87 | | - - name: Run test .NET 6.0 Windows |
88 | | - working-directory: QRCoderTests |
89 | | - run: dotnet test -c Release -f net6.0-windows --nologo --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover |
90 | | - |
91 | | - - name: Run API approval tests |
92 | | - working-directory: QRCoderApiTests |
93 | | - run: dotnet test -c Release --nologo --no-build |
94 | | - |
95 | | - - name: Codecov update netcoreapp2.0 |
96 | | - uses: codecov/codecov-action@v4 |
97 | | - with: |
98 | | - token: ${{ secrets.CODECOV_TOKEN }} |
99 | | - disable_search: true |
100 | | - fail_ci_if_error: true |
101 | | - files: ./QRCoderTests/coverage.netcoreapp2.0.opencover.xml |
102 | | - flags: netcoreapp2.0 |
| 47 | + name: Nuget packages |
| 48 | + path: out/* |
103 | 49 |
|
104 | | - - name: Codecov update net5.0 |
105 | | - uses: codecov/codecov-action@v4 |
106 | | - with: |
107 | | - token: ${{ secrets.CODECOV_TOKEN }} |
108 | | - disable_search: true |
109 | | - fail_ci_if_error: true |
110 | | - files: ./QRCoderTests/coverage.net5.0.opencover.xml |
111 | | - flags: net5.0 |
| 50 | + - name: Publish packages to Github packages |
| 51 | + run: dotnet nuget push "out\*" -k ${{secrets.NUGET_AUTH_TOKEN}} |
112 | 52 |
|
113 | | - - name: Codecov update net5.0-windows |
114 | | - uses: codecov/codecov-action@v4 |
115 | | - with: |
116 | | - token: ${{ secrets.CODECOV_TOKEN }} |
117 | | - disable_search: true |
118 | | - fail_ci_if_error: true |
119 | | - files: ./QRCoderTests/coverage.net5.0-windows.opencover.xml |
120 | | - flags: net5.0-windows |
121 | | - |
122 | | - - name: Codecov update net6.0 |
123 | | - uses: codecov/codecov-action@v4 |
124 | | - with: |
125 | | - token: ${{ secrets.CODECOV_TOKEN }} |
126 | | - disable_search: true |
127 | | - fail_ci_if_error: true |
128 | | - files: ./QRCoderTests/coverage.net5.0.opencover.xml |
129 | | - flags: net6.0 |
130 | | - |
131 | | - - name: Codecov update net6.0-windows |
132 | | - uses: codecov/codecov-action@v4 |
133 | | - with: |
134 | | - token: ${{ secrets.CODECOV_TOKEN }} |
135 | | - disable_search: true |
136 | | - fail_ci_if_error: true |
137 | | - files: ./QRCoderTests/coverage.net5.0-windows.opencover.xml |
138 | | - flags: net6.0-windows |
139 | | - |
140 | | - pack-push-release: |
141 | | - needs: test |
142 | | - runs-on: windows-latest |
143 | | - env: |
144 | | - GH_PKG_SEC: ${{ secrets.GITHUB_TOKEN }} |
145 | | - steps: |
146 | | - - name: Download artifacts |
147 | | - uses: actions/download-artifact@v4 |
148 | | - with: |
149 | | - name: Compiled project |
150 | | - path: ${{ github.workspace }} |
151 | | - |
152 | | - - name: Install additional .NET SDKs |
153 | | - uses: actions/setup-dotnet@v4 |
154 | | - with: |
155 | | - dotnet-version: | |
156 | | - 1.0.x |
157 | | - 2.0.x |
158 | | - 5.0.x |
159 | | - 6.0.x |
160 | | - 8.0.x |
161 | | -
|
162 | | - - name: Restore dependencies |
163 | | - run: dotnet restore |
164 | | - |
165 | | - - name: Get assembly version QRCoder |
166 | | - run: echo "ASSEM_VER=$([Reflection.Assembly]::Loadfile( $(-join($pwd,"\QRCoder\bin\Release\net40\QRCoder.dll"))).GetName().version.ToString())" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append |
167 | | - |
168 | | - - name: Clean assembly version QRCoder |
169 | | - run: echo "ASSEM_VER_SHT=$($env:ASSEM_VER.substring(0, $env:ASSEM_VER.lastIndexOf(".")))" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append |
170 | | - |
171 | | - - name: Get assembly version QRCoder.Xaml |
172 | | - run: echo "ASSEM_VER_XAML=$([Reflection.Assembly]::Loadfile( $(-join($pwd,"\QRCoder.Xaml\bin\Release\net40\QRCoder.Xaml.dll"))).GetName().version.ToString())" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append |
173 | | - |
174 | | - - name: Clean assembly version QRCoder.Xaml |
175 | | - run: echo "ASSEM_VER_SHT_XAML=$($env:ASSEM_VER_XAML.substring(0, $env:ASSEM_VER_XAML.lastIndexOf(".")))" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append |
176 | | - |
177 | | - - name: Build QRCoder NuGet package |
178 | | - run: dotnet pack QRCoder\QRCoder.csproj -c Release --no-build /p:PackageVersion="$env:ASSEM_VER_SHT" /p:PackageReleaseNotes="${{ github.event.inputs.releaseNotes }}" |
179 | | - |
180 | | - - name: Build QRCoder.Xaml NuGet package |
181 | | - run: dotnet pack QRCoder.Xaml\QRCoder.Xaml.csproj -c Release --no-build /p:PackageVersion="$env:ASSEM_VER_SHT_XAML" /p:PackageReleaseNotes="${{ github.event.inputs.releaseNotes }}" |
182 | | - |
183 | | - - name: Publish QRCoder and QRCoder.Xaml to Github packages |
184 | | - run: dotnet nuget push "**/*.nupkg" --no-symbols --skip-duplicate --api-key $env:GH_PKG_SEC --source https://nuget.pkg.github.com/codebude/index.json |
185 | | - |
186 | | - |
187 | | - clean: |
188 | | - needs: [build, test, pack-push-release] |
189 | | - if: always() |
190 | | - runs-on: windows-latest |
191 | | - steps: |
192 | | - - name: Delete artifacts |
193 | | - uses: GeekyEggo/delete-artifact@v5 |
| 53 | + - name: Upload Nuget packages as release artifacts |
| 54 | + uses: actions/github-script@v8 |
194 | 55 | with: |
195 | | - name: Compiled project |
| 56 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 57 | + script: | |
| 58 | + console.log('environment', process.versions); |
| 59 | + const fs = require('fs').promises; |
| 60 | + const { repo: { owner, repo }, sha } = context; |
| 61 | +
|
| 62 | + for (let file of await fs.readdir('out')) { |
| 63 | + console.log('uploading', file); |
| 64 | +
|
| 65 | + await github.rest.repos.uploadReleaseAsset({ |
| 66 | + owner, |
| 67 | + repo, |
| 68 | + release_id: ${{ github.event.release.id }}, |
| 69 | + name: file, |
| 70 | + data: await fs.readFile(`out/${file}`) |
| 71 | + }); |
| 72 | + } |
0 commit comments