|
36 | 36 | # For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications, |
37 | 37 | # refer to https://github.com/microsoft/github-actions-for-desktop-apps |
38 | 38 |
|
39 | | -name: .NET Core Desktop |
| 39 | +name: .NET 9 build & run |
40 | 40 |
|
41 | 41 | on: |
42 | 42 | push: |
43 | | - branches: [ "main" ] |
44 | | - pull_request: |
45 | | - branches: [ "main" ] |
| 43 | + branches: [ main ] |
| 44 | + workflow_dispatch: |
46 | 45 |
|
47 | 46 | jobs: |
48 | | - |
49 | 47 | build: |
50 | | - |
51 | | - strategy: |
52 | | - matrix: |
53 | | - configuration: [Debug, Release] |
54 | | - |
55 | | - runs-on: windows-latest # For a list of available runner types, refer to |
56 | | - # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on |
57 | | - |
58 | | - env: |
59 | | - Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln. |
60 | | - Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj. |
61 | | - Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package. |
62 | | - Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj. |
63 | | - |
| 48 | + runs-on: ubuntu-latest |
64 | 49 | steps: |
65 | | - - name: Checkout |
66 | | - uses: actions/checkout@v4 |
67 | | - with: |
68 | | - fetch-depth: 0 |
| 50 | + - uses: actions/checkout@v4 |
69 | 51 |
|
70 | | - # Install the .NET Core workload |
71 | | - - name: Install .NET Core |
72 | | - uses: actions/setup-dotnet@v4 |
73 | | - with: |
74 | | - dotnet-version: 8.0.x |
| 52 | + - name: Setup .NET 9 SDK |
| 53 | + uses: actions/setup-dotnet@v4 |
| 54 | + with: |
| 55 | + dotnet-version: '9.0.x' |
75 | 56 |
|
76 | | - # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild |
77 | | - - name: Setup MSBuild.exe |
78 | | - uses: microsoft/setup-msbuild@v2 |
| 57 | + - name: Restore |
| 58 | + run: dotnet restore ./LibrarySystem.csproj |
79 | 59 |
|
80 | | - # Execute all unit tests in the solution |
81 | | - - name: Execute unit tests |
82 | | - run: dotnet test |
| 60 | + - name: Build (Release) |
| 61 | + run: dotnet build ./LibrarySystem.csproj -c Release --no-restore |
83 | 62 |
|
84 | | - # Restore the application to populate the obj folder with RuntimeIdentifiers |
85 | | - - name: Restore the application |
86 | | - run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration |
87 | | - env: |
88 | | - Configuration: ${{ matrix.configuration }} |
89 | | - |
90 | | - # Decode the base 64 encoded pfx and save the Signing_Certificate |
91 | | - - name: Decode the pfx |
92 | | - run: | |
93 | | - $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}") |
94 | | - $certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx |
95 | | - [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte) |
96 | | -
|
97 | | - # Create the app package by building and packaging the Windows Application Packaging project |
98 | | - - name: Create the app package |
99 | | - run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }} |
100 | | - env: |
101 | | - Appx_Bundle: Always |
102 | | - Appx_Bundle_Platforms: x86|x64 |
103 | | - Appx_Package_Build_Mode: StoreUpload |
104 | | - Configuration: ${{ matrix.configuration }} |
105 | | - |
106 | | - # Remove the pfx |
107 | | - - name: Remove the pfx |
108 | | - run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx |
| 63 | + run-demo: |
| 64 | + needs: build |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + - uses: actions/setup-dotnet@v4 |
| 69 | + with: |
| 70 | + dotnet-version: '9.0.x' |
| 71 | + |
| 72 | + - name: Build |
| 73 | + run: dotnet build ./LibrarySystem.csproj -c Release |
| 74 | + |
| 75 | + # 你個程式係互動式;用 printf 餵輸入(按你 Program.cs 菜單改) |
| 76 | + - name: Run with scripted input |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + printf "3\n" | dotnet run --project ./LibrarySystem.csproj -c Release --no-build | tee run.log |
| 80 | +
|
| 81 | + - name: Upload console output |
| 82 | + uses: actions/upload-artifact@v4 |
| 83 | + with: |
| 84 | + name: console-output |
| 85 | + path: run.log |
109 | 86 |
|
110 | | - # Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact |
111 | | - - name: Upload build artifacts |
112 | | - uses: actions/upload-artifact@v4 |
113 | | - with: |
114 | | - name: MSIX Package |
115 | | - path: ${{ env.Wap_Project_Directory }}\AppPackages |
0 commit comments