|
| 1 | +# https://docs.github.com/actions/using-workflows/about-workflows |
| 2 | +# https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions |
| 3 | + |
| 4 | +name: CI-build |
| 5 | + |
| 6 | +# Controls when the action will run. |
| 7 | +on: |
| 8 | + |
| 9 | + # Triggers the workflow on push or PR events, but only for the 'main', development, or release branches |
| 10 | + push: |
| 11 | + branches: [ main, 'dev/*', 'rel/*' ] |
| 12 | + pull_request: |
| 13 | + branches: [ main, 'dev/*' ] |
| 14 | + |
| 15 | + # Allows running this workflow manually from the 'Actions' tab |
| 16 | + workflow_dispatch: |
| 17 | + merge_group: |
| 18 | + |
| 19 | +env: |
| 20 | + IS_MAIN: ${{ github.ref == 'refs/heads/main' }} |
| 21 | + IS_PR: ${{ startsWith(github.ref, 'refs/pull/') }} |
| 22 | + IS_RELEASE: ${{ startsWith(github.ref, 'refs/heads/rel/') }} |
| 23 | + |
| 24 | + # The version of .NET to use just for NuGet package operations. |
| 25 | + # This doesn't have to be exactly in sync with the .NET SDK |
| 26 | + # version defined in 'global.json', as it's not used for builds. |
| 27 | + DOTNET_NUGET_VERSION: ${{ '9.0.x' }} |
| 28 | + |
| 29 | +jobs: |
| 30 | + |
| 31 | + # Build the solution, run all tests, push packages to the PR feed. |
| 32 | + # We want to avoid the CI being triggered twice for PRs from the |
| 33 | + # repository owner, however the repo is now under 'CommunityToolkit'. |
| 34 | + # So we just hardcode the username and skip this job for PR triggers |
| 35 | + # from that user. This ensures the workflow only runs once per commit. |
| 36 | + build-and-test: |
| 37 | + if: >- |
| 38 | + github.event_name == 'push' || |
| 39 | + github.event.pull_request.user.login != 'sergio0694' |
| 40 | + strategy: |
| 41 | + matrix: |
| 42 | + configuration: [Debug, Release] |
| 43 | + runs-on: windows-2022 |
| 44 | + steps: |
| 45 | + - name: Git checkout |
| 46 | + uses: actions/checkout@v5 |
| 47 | + with: |
| 48 | + fetch-depth: 0 # We need the full history for proper versioning |
| 49 | + |
| 50 | + - name: Install .NET SDK |
| 51 | + uses: actions/setup-dotnet@v5 |
| 52 | + with: |
| 53 | + global-json-file: global.json |
| 54 | + |
| 55 | + # Build the whole solution |
| 56 | + - name: Build solution |
| 57 | + run: dotnet build -c ${{matrix.configuration}} /bl |
| 58 | + - name: Upload MSBuild binary log |
| 59 | + uses: actions/upload-artifact@v5 |
| 60 | + with: |
| 61 | + name: msbuild_log_${{matrix.configuration}} |
| 62 | + path: ${{ github.workspace }}/msbuild.binlog |
| 63 | + if-no-files-found: error |
| 64 | + |
| 65 | + # Run tests |
| 66 | + - name: Test solution |
| 67 | + run: dotnet test --no-build -c ${{matrix.configuration}} -l "console;verbosity=detailed" |
| 68 | + |
| 69 | + # Pack solution |
| 70 | + - name: Pack solution |
| 71 | + run: dotnet pack --no-build -c ${{matrix.configuration}} |
| 72 | + |
| 73 | + # Push PR packages to our DevOps artifacts feed (see nuget.config) |
| 74 | + - name: Push PR packages (if not fork) |
| 75 | + if: ${{ env.IS_PR == 'true' && matrix.configuration == 'Release' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }} |
| 76 | + run: | |
| 77 | + dotnet nuget add source https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-PullRequests/nuget/v3/index.json ` |
| 78 | + --name PullRequests ` |
| 79 | + --username dummy --password ${{ secrets.DEVOPS_PACKAGE_PUSH_TOKEN }} |
| 80 | + dotnet nuget push "*.nupkg" --api-key dummy --source PullRequests --skip-duplicate |
| 81 | +
|
| 82 | + - name: Upload packages list |
| 83 | + uses: actions/upload-artifact@v5 |
| 84 | + if: ${{ env.IS_PR == 'false' && matrix.configuration == 'Release' }} |
| 85 | + with: |
| 86 | + name: nuget-list-dotnet |
| 87 | + path: ${{ github.workspace }}/.github/workflows/SignClientFileList.txt |
| 88 | + if-no-files-found: error |
| 89 | + |
| 90 | + # If we're not doing a PR build (or it's a PR from a fork) then we upload our packages so we can sign as a separate job or have available to test |
| 91 | + - name: Upload packages artifacts |
| 92 | + uses: actions/upload-artifact@v5 |
| 93 | + if: ${{ (env.IS_PR == 'false' || github.event.pull_request.head.repo.full_name != github.repository) && matrix.configuration == 'Release' }} |
| 94 | + with: |
| 95 | + name: nuget-packages-dotnet |
| 96 | + path: ${{ github.workspace }}/bin/nupkg/*.nupkg |
| 97 | + if-no-files-found: error |
| 98 | + |
| 99 | + # Sign the packages for release. |
| 100 | + # Note: here and below we're explicitly repeating the conditions, rather than using 'env.'. |
| 101 | + # Doing so doesn't seem to work for conditions of jobs themselves, only for individual steps. |
| 102 | + sign: |
| 103 | + needs: [build-and-test] |
| 104 | + if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/rel/') }} |
| 105 | + runs-on: windows-latest |
| 106 | + permissions: |
| 107 | + id-token: write # Required for requesting the JWT |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Install .NET SDK |
| 111 | + uses: actions/setup-dotnet@v5 |
| 112 | + with: |
| 113 | + dotnet-version: ${{ env.DOTNET_NUGET_VERSION }} |
| 114 | + |
| 115 | + - name: Download packages list |
| 116 | + uses: actions/download-artifact@v5 |
| 117 | + with: |
| 118 | + name: nuget-list-dotnet |
| 119 | + path: ${{ github.workspace }} |
| 120 | + |
| 121 | + - name: Download built packages for .NCT |
| 122 | + uses: actions/download-artifact@v5 |
| 123 | + with: |
| 124 | + name: nuget-packages-dotnet |
| 125 | + path: ${{ github.workspace }}/packages |
| 126 | + |
| 127 | + - name: Install Signing Tool |
| 128 | + run: dotnet tool install --tool-path ./tools sign --version 0.9.1-beta.25379.1 |
| 129 | + |
| 130 | + - name: Sign packages |
| 131 | + run: > |
| 132 | + ./tools/sign code azure-key-vault |
| 133 | + **/*.nupkg |
| 134 | + --base-directory "${{ github.workspace }}/packages" |
| 135 | + --file-list "${{ github.workspace }}/SignClientFileList.txt" |
| 136 | + --timestamp-url "http://timestamp.digicert.com" |
| 137 | + --publisher-name ".NET Foundation" |
| 138 | + --description ".NET Community Toolkit" |
| 139 | + --description-url "https://github.com/CommunityToolkit/dotnet" |
| 140 | + --azure-key-vault-url "${{ secrets.SIGN_KEY_VAULT_URL }}" |
| 141 | + --azure-key-vault-client-id ${{ secrets.SIGN_CLIENT_ID }} |
| 142 | + --azure-key-vault-client-secret "${{ secrets.SIGN_CLIENT_SECRET }}" |
| 143 | + --azure-key-vault-tenant-id ${{ secrets.SIGN_TENANT_ID }} |
| 144 | + --azure-key-vault-certificate "${{ secrets.SIGN_CERTIFICATE }}" |
| 145 | + --verbosity Information |
| 146 | +
|
| 147 | + - name: Push signed packages |
| 148 | + run: | |
| 149 | + dotnet nuget add source https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json ` |
| 150 | + --name MainLatest ` |
| 151 | + --username dummy --password ${{ secrets.DEVOPS_PACKAGE_PUSH_TOKEN }} |
| 152 | + dotnet nuget push "**/*.nupkg" --api-key dummy --source MainLatest --skip-duplicate |
| 153 | +
|
| 154 | + - name: Upload signed packages as artifacts (for release) |
| 155 | + uses: actions/upload-artifact@v5 |
| 156 | + if: ${{ env.IS_RELEASE == 'true' }} |
| 157 | + with: |
| 158 | + name: signed-nuget-packages-dotnet |
| 159 | + path: ${{ github.workspace }}/packages/**/*.nupkg |
| 160 | + if-no-files-found: error |
| 161 | + |
| 162 | + # Push official packages to NuGet |
| 163 | + release: |
| 164 | + if: ${{ startsWith(github.ref, 'refs/heads/rel/') }} |
| 165 | + needs: [sign] |
| 166 | + environment: nuget-release-gate # This gates this job until manually approved |
| 167 | + runs-on: ubuntu-latest |
| 168 | + |
| 169 | + steps: |
| 170 | + - name: Install .NET SDK |
| 171 | + uses: actions/setup-dotnet@v5 |
| 172 | + with: |
| 173 | + dotnet-version: ${{ env.DOTNET_NUGET_VERSION }} |
| 174 | + |
| 175 | + - name: Download signed packages for .NCT |
| 176 | + uses: actions/download-artifact@v5 |
| 177 | + with: |
| 178 | + name: signed-nuget-packages-dotnet |
| 179 | + path: ./packages |
| 180 | + |
| 181 | + - name: Push to NuGet.org |
| 182 | + run: > |
| 183 | + dotnet nuget push |
| 184 | + **/*.nupkg |
| 185 | + --source https://api.nuget.org/v3/index.json |
| 186 | + --api-key ${{ secrets.NUGET_PACKAGE_PUSH_TOKEN }} |
| 187 | + --skip-duplicate |
0 commit comments