Skip to content

Commit a9245e3

Browse files
authored
Build & Release with GitHub Actions (#383)
Add GitHub Actions
1 parent 21f14ef commit a9245e3

File tree

4 files changed

+345
-337
lines changed

4 files changed

+345
-337
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/CommunityToolkit.*

.github/workflows/benchmarks.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Benchmarks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
paths-ignore:
10+
- README.md
11+
pull_request:
12+
branches:
13+
- '*'
14+
15+
env:
16+
LATEST_NET_VERSION: '9.0.x'
17+
PathToCommunityToolkitBenchmarkCsproj: 'src/CommunityToolkit.Maui.Markup.Benchmarks/CommunityToolkit.Maui.Markup.Benchmarks.csproj'
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
run_benchmarks:
25+
name: Run Benchmarks
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: [windows-latest, macos-15]
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- uses: maxim-lobanov/setup-xcode@v1
37+
if: runner.os == 'macOS'
38+
with:
39+
xcode-version: latest-stable
40+
41+
- name: Install Latest Version of .NET, v${{ env.LATEST_NET_VERSION }}
42+
uses: actions/setup-dotnet@v4
43+
with:
44+
dotnet-version: ${{ env.LATEST_NET_VERSION }}
45+
dotnet-quality: 'ga'
46+
47+
- name: Install .NET MAUI Workload
48+
run: |
49+
dotnet workload install maui
50+
dotnet workload update
51+
52+
- name: Install Tizen Workload
53+
run: |
54+
Invoke-WebRequest 'https://raw.githubusercontent.com/Samsung/Tizen.NET/main/workload/scripts/workload-install.ps1' -OutFile 'workload-install.ps1'
55+
.\workload-install.ps1
56+
shell: pwsh
57+
58+
- name: Display dotnet info
59+
run: dotnet --info
60+
61+
- name: Run Benchmarks
62+
run: dotnet run --project ${{ env.PathToCommunityToolkitBenchmarkCsproj }} -c Release -- -a ${{ runner.temp }}
63+
64+
- name: Publish Benchmarks
65+
if: runner.os == 'Windows'
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: Benchmarks
69+
path: |
70+
${{ runner.temp }}/**/*.md

.github/workflows/dotnet-build.yml

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
paths-ignore:
10+
- README.md
11+
pull_request:
12+
branches:
13+
- main
14+
paths-ignore:
15+
- README.md
16+
17+
env:
18+
CurrentSemanticVersionBase: '99.0.0'
19+
PreviewNumber: $[counter(variables['CurrentSemanticVersionBase'], 1001)]
20+
CurrentSemanticVersion: '$(CurrentSemanticVersionBase)-preview$(PreviewNumber)'
21+
NugetPackageVersion: '$(CurrentSemanticVersion)'
22+
NET_VERSION: '9.0.x'
23+
RunPoliCheck: false
24+
PathToLibrarySolution: 'src/CommunityToolkit.Maui.Markup.sln'
25+
PathToSamplesSolution: 'samples/CommunityToolkit.Maui.Markup.Sample.sln'
26+
PathToCommunityToolkitCsproj: 'src/CommunityToolkit.Maui.Markup/CommunityToolkit.Maui.Markup.csproj'
27+
PathToCommunityToolkitSampleCsproj: 'samples/CommunityToolkit.Maui.Markup.Sample/CommunityToolkit.Maui.Markup.Sample.csproj'
28+
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.Markup.UnitTests/CommunityToolkit.Maui.Markup.UnitTests.csproj'
29+
PathToCommunityToolkitSourceGeneratorsCsproj: 'src/CommunityToolkit.Maui.Markup.SourceGenerators/CommunityToolkit.Maui.Markup.SourceGenerators.csproj'
30+
Xcode_Version: '16.3'
31+
ShouldCheckDependencies: true
32+
33+
concurrency:
34+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
35+
cancel-in-progress: true
36+
37+
jobs:
38+
build_sample:
39+
name: Build Sample App using Latest .NET SDK
40+
runs-on: ${{ matrix.os }}
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
os: [windows-latest, macos-15]
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
49+
- name: Set Latest Xcode Version
50+
if: runner.os == 'macOS'
51+
uses: maxim-lobanov/setup-xcode@v1
52+
with:
53+
xcode-version: latest-stable
54+
55+
- name: Install Latest .NET SDK, v${{ env.NET_VERSION }}
56+
uses: actions/setup-dotnet@v4
57+
with:
58+
dotnet-version: ${{ env.NET_VERSION }}
59+
dotnet-quality: 'ga'
60+
61+
- uses: actions/setup-java@v4
62+
with:
63+
distribution: 'microsoft'
64+
java-version: '17'
65+
66+
- name: Install .NET MAUI Workload
67+
run: |
68+
dotnet workload install maui
69+
dotnet workload update
70+
71+
- name: Install Tizen Workload
72+
run: |
73+
Invoke-WebRequest 'https://raw.githubusercontent.com/Samsung/Tizen.NET/main/workload/scripts/workload-install.ps1' -OutFile 'workload-install.ps1'
74+
.\workload-install.ps1
75+
shell: pwsh
76+
77+
- name: Display dotnet info
78+
run: dotnet --info
79+
80+
- name: Build CommunityToolkit.Maui.Markup.Sample
81+
run: dotnet build -c Release ${{ env.PathToCommunityToolkitSampleCsproj }}
82+
83+
build_library:
84+
name: Build Library
85+
runs-on: ${{ matrix.os }}
86+
strategy:
87+
fail-fast: false
88+
matrix:
89+
os: [windows-latest, macos-15]
90+
steps:
91+
- name: Checkout code
92+
uses: actions/checkout@v4
93+
94+
- name: Set NuGet Version to Tag Number
95+
if: startsWith(github.ref, 'refs/tags/')
96+
run: echo "NugetPackageVersion=${{ github.ref }}" >> $GITHUB_ENV
97+
98+
- name: Set NuGet Version to PR Version
99+
if: ${{ github.event_name == 'pull_request' }}
100+
run: echo "NugetPackageVersion=${{ env.CurrentSemanticVersionBase }}-build-${{ github.event.pull_request.number }}.${{ github.run_number }}+${{ github.sha }}" >> $GITHUB_ENV
101+
shell: bash
102+
103+
- name: Set Xcode Version
104+
if: runner.os == 'macOS'
105+
uses: maxim-lobanov/setup-xcode@v1
106+
with:
107+
xcode-version: ${{ env.Xcode_Version }}
108+
109+
- name: Install .NET SDK v${{ env.NET_VERSION }}
110+
uses: actions/setup-dotnet@v4
111+
with:
112+
dotnet-version: ${{ env.NET_VERSION }}
113+
dotnet-quality: 'ga'
114+
115+
- uses: actions/setup-java@v4
116+
with:
117+
distribution: 'microsoft'
118+
java-version: '17'
119+
120+
- name: Install .NET MAUI Workload
121+
run: |
122+
dotnet workload install maui
123+
dotnet workload update
124+
125+
- name: Install Tizen Workload
126+
run: |
127+
Invoke-WebRequest 'https://raw.githubusercontent.com/Samsung/Tizen.NET/main/workload/scripts/workload-install.ps1' -OutFile 'workload-install.ps1'
128+
.\workload-install.ps1
129+
shell: pwsh
130+
131+
- name: Display dotnet info
132+
run: dotnet --info
133+
134+
- name: 'Build CommunityToolkit.Maui.Markup.SourceGenerators'
135+
run: dotnet build ${{ env.PathToCommunityToolkitSourceGeneratorsCsproj }} -c Release
136+
137+
- name: 'Build CommunityToolkit.Maui.Markup'
138+
run: dotnet build ${{ env.PathToCommunityToolkitCsproj }} -c Release
139+
140+
- name: 'Build CommunityToolkit.Maui.Markup.UnitTests'
141+
run: dotnet build ${{ env.PathToCommunityToolkitUnitTestCsproj }} -c Release
142+
143+
- name: Run Unit Tests
144+
run: dotnet run -c Release --project ${{ env.PathToCommunityToolkitUnitTestCsproj }} --results-directory "${{ runner.temp }}" --coverage --coverage-output "${{ runner.temp }}/coverage.cobertura.xml" --coverage-output-format cobertura
145+
146+
- name: Publish Code Coverage Results
147+
if: ${{ runner.os == 'Windows' && (success() || failure()) }}
148+
run: |
149+
dotnet tool install -g dotnet-reportgenerator-globaltool
150+
reportgenerator -reports:'${{ runner.temp }}\*cobertura.xml' -targetdir:CodeCoverage -reporttypes:'MarkdownSummaryGithub'
151+
cat CodeCoverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
152+
shell: bash
153+
154+
- name: Build and Pack CommunityToolkit.Maui.Markup
155+
run: dotnet pack -c Release ${{ env.PathToCommunityToolkitCsproj }} -p:PackageVersion=${{ env.NugetPackageVersion }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
156+
157+
- name: 'Check Dependencies'
158+
if: ${{ runner.os == 'Windows' && (success() || failure()) }}
159+
run: |
160+
cd src
161+
dotnet list package --include-transitive # Print all transitive packages
162+
dotnet list package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages"; # Print all transitive packages with vulnerabilities
163+
if ($LastExitCode -ne 1)
164+
{
165+
dotnet list package --vulnerable --include-transitive;
166+
exit 1;
167+
}
168+
169+
exit 0;
170+
shell: pwsh
171+
172+
- name: Copy NuGet Packages to Staging Directory
173+
if: ${{ runner.os == 'Windows' }} && !startsWith(github.ref, 'refs/tags/')
174+
run: |
175+
mkdir -p ${{ github.workspace }}/nuget
176+
Get-ChildItem -Path "./src" -Recurse | Where-Object { $_.Extension -match "nupkg" } | Copy-Item -Destination "${{ github.workspace }}/nuget"
177+
shell: pwsh
178+
179+
- name: Upload Package List
180+
uses: actions/upload-artifact@v4
181+
if: ${{ runner.os == 'Windows' }}
182+
with:
183+
name: nuget-list
184+
if-no-files-found: error
185+
path: |
186+
${{ github.workspace }}/.github/workflows/SignClientFileList.txt
187+
188+
- name: Publish Packages
189+
if: ${{ runner.os == 'Windows' }}
190+
uses: actions/upload-artifact@v4
191+
with:
192+
name: packages
193+
path: ${{ github.workspace }}/nuget/
194+
195+
sign:
196+
needs: [build_library]
197+
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/rel/') }}
198+
runs-on: windows-latest
199+
permissions:
200+
id-token: write # Required for requesting the JWT
201+
202+
steps:
203+
- name: Install .NET SDK v${{ env.NET_VERSION }}
204+
uses: actions/setup-dotnet@v4
205+
with:
206+
dotnet-version: ${{ env.NET_VERSION }}
207+
dotnet-quality: 'ga'
208+
209+
- name: Download NuGet List
210+
uses: actions/download-artifact@v4
211+
with:
212+
name: nuget-list
213+
path: ./
214+
215+
- name: Download Package List
216+
uses: actions/download-artifact@v4
217+
with:
218+
name: packages
219+
path: ./packages
220+
221+
- name: Install Signing Tool
222+
run: dotnet tool install --tool-path ./tools sign --version 0.9.1-beta.23356.1
223+
224+
- name: Sign Packages
225+
run: >
226+
./tools/sign code azure-key-vault
227+
**/*.nupkg
228+
--base-directory "${{ github.workspace }}/packages"
229+
--file-list "${{ github.workspace }}/SignClientFileList.txt"
230+
--timestamp-url "http://timestamp.digicert.com"
231+
--publisher-name ".NET Foundation"
232+
--description "Community Toolkit MAUI"
233+
--description-url "https://github.com/CommunityToolkit/Maui"
234+
--azure-key-vault-url "${{ secrets.SIGN_KEY_VAULT_URL }}"
235+
--azure-key-vault-client-id ${{ secrets.SIGN_CLIENT_ID }}
236+
--azure-key-vault-client-secret "${{ secrets.SIGN_CLIENT_SECRET }}"
237+
--azure-key-vault-tenant-id ${{ secrets.SIGN_TENANT_ID }}
238+
--azure-key-vault-certificate "${{ secrets.SIGN_CERTIFICATE }}"
239+
--verbosity Information
240+
241+
- name: Publish Packages
242+
uses: actions/upload-artifact@v4
243+
with:
244+
name: signed-packages
245+
if-no-files-found: error
246+
path: |
247+
${{ github.workspace }}/packages/**/*.nupkg
248+
249+
release:
250+
if: ${{ startsWith(github.ref, 'refs/heads/rel/') }}
251+
needs: [sign]
252+
environment: nuget-release-gate # This gates this job until manually approved
253+
runs-on: ubuntu-latest
254+
255+
steps:
256+
- name: Install .NET SDK
257+
uses: actions/setup-dotnet@v4
258+
with:
259+
dotnet-version: ${{ env.NET_VERSION }}
260+
dotnet-quality: 'ga'
261+
262+
- name: Download signed packages for ${{ matrix.platform }}
263+
uses: actions/download-artifact@v4
264+
with:
265+
name: signed-packages
266+
path: ./packages
267+
268+
- name: Push to NuGet.org
269+
run: >
270+
dotnet nuget push
271+
**/*.nupkg
272+
--source https://api.nuget.org/v3/index.json
273+
--api-key ${{ secrets.NUGET_PACKAGE_PUSH_TOKEN }}
274+
--skip-duplicate

0 commit comments

Comments
 (0)