|
| 1 | +# SPDX-FileCopyrightText: © 2022 MONAI Consortium |
| 2 | +# SPDX-License-Identifier: Apache License 2.0 |
| 3 | + |
| 4 | +name: ci |
| 5 | + |
| 6 | +on: |
| 7 | + # Triggers on pushes and on pull requests |
| 8 | + push: |
| 9 | + |
| 10 | + # Allows you to run this workflow manually from the Actions tab |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +env: |
| 14 | + BUILD_CONFIG: "Release" |
| 15 | + SOLUTION: "Monai.Deploy.Messaging.sln" |
| 16 | + TEST_RESULTS: "results/" |
| 17 | + |
| 18 | +jobs: |
| 19 | + |
| 20 | + analyze: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + actions: read |
| 24 | + contents: read |
| 25 | + security-events: write |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + language: [ 'csharp' ] |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v2 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + - uses: actions/setup-dotnet@v1 |
| 37 | + with: |
| 38 | + dotnet-version: "6.0.x" |
| 39 | + |
| 40 | + - name: Enable NuGet cache |
| 41 | + |
| 42 | + with: |
| 43 | + path: ~/.nuget/packages |
| 44 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-nuget |
| 47 | +
|
| 48 | + - name: Initialize CodeQL |
| 49 | + uses: github/codeql-action/init@v1 |
| 50 | + with: |
| 51 | + languages: ${{ matrix.language }} |
| 52 | + |
| 53 | + - name: Restore dependencies |
| 54 | + run: dotnet restore |
| 55 | + working-directory: ./src |
| 56 | + |
| 57 | + - name: Build Solution |
| 58 | + run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }} |
| 59 | + working-directory: ./src |
| 60 | + |
| 61 | + - name: Perform CodeQL Analysis |
| 62 | + uses: github/codeql-action/analyze@v1 |
| 63 | + |
| 64 | + - name: Secret detection |
| 65 | + uses: zricethezav/gitleaks-action@master |
| 66 | + |
| 67 | + unit-test: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Set up JDK 11 |
| 71 | + uses: actions/setup-java@v1 |
| 72 | + with: |
| 73 | + java-version: 1.11 |
| 74 | + |
| 75 | + - uses: actions/setup-dotnet@v1 |
| 76 | + with: |
| 77 | + dotnet-version: "6.0.x" |
| 78 | + |
| 79 | + - name: Enable NuGet cache |
| 80 | + |
| 81 | + with: |
| 82 | + path: ~/.nuget/packages |
| 83 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 84 | + restore-keys: | |
| 85 | + ${{ runner.os }}-nuget |
| 86 | +
|
| 87 | + - uses: actions/checkout@v2 |
| 88 | + with: |
| 89 | + fetch-depth: 0 |
| 90 | + |
| 91 | + - name: Install SonarCloud scanner |
| 92 | + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' |
| 93 | + run: dotnet tool install --global dotnet-sonarscanner |
| 94 | + |
| 95 | + - name: Restore dependencies |
| 96 | + run: dotnet restore |
| 97 | + working-directory: ./src |
| 98 | + |
| 99 | + - name: Begin SonarScanner |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 103 | + run: dotnet sonarscanner begin /k:"Project-MONAI_monai-deploy-messaging" /o:"project-monai" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="${{ env.TEST_RESULTS }}/**/*.xml" |
| 104 | + working-directory: ./src |
| 105 | + |
| 106 | + - name: Build |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 110 | + run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo "${{ env.SOLUTION }}" |
| 111 | + working-directory: ./src |
| 112 | + |
| 113 | + - name: Test |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 117 | + run: find ~+ -type f -name "*.Test.csproj" | xargs -L1 dotnet test -c ${{ env.BUILD_CONFIG }} -v=minimal -r "${{ env.TEST_RESULTS }}" --collect:"XPlat Code Coverage" --settings coverlet.runsettings |
| 118 | + working-directory: ./src |
| 119 | + |
| 120 | + - name: End SonarScanner |
| 121 | + env: |
| 122 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 124 | + run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" |
| 125 | + working-directory: ./src |
| 126 | + |
| 127 | + - uses: codecov/codecov-action@v2 |
| 128 | + with: |
| 129 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 130 | + directory: "src/${{ env.TEST_RESULTS }}" |
| 131 | + files: "**/coverage.opencover.xml" |
| 132 | + flags: unittests |
| 133 | + name: codecov-umbrella |
| 134 | + fail_ci_if_error: true |
| 135 | + verbose: true |
| 136 | + |
| 137 | + build: |
| 138 | + runs-on: ${{ matrix.os }} |
| 139 | + |
| 140 | + outputs: |
| 141 | + majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }} |
| 142 | + |
| 143 | + strategy: |
| 144 | + matrix: |
| 145 | + os: [ubuntu-latest, windows-latest] |
| 146 | + fail-fast: true |
| 147 | + |
| 148 | + permissions: |
| 149 | + contents: write |
| 150 | + packages: write |
| 151 | + checks: write |
| 152 | + security-events: write |
| 153 | + |
| 154 | + steps: |
| 155 | + - name: Checkout repository |
| 156 | + uses: actions/checkout@v2 |
| 157 | + with: |
| 158 | + fetch-depth: 0 |
| 159 | + |
| 160 | + - uses: actions/setup-dotnet@v1 |
| 161 | + with: |
| 162 | + dotnet-version: "6.0.x" |
| 163 | + |
| 164 | + - name: Enable NuGet cache |
| 165 | + |
| 166 | + with: |
| 167 | + path: ~/.nuget/packages |
| 168 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 169 | + restore-keys: | |
| 170 | + ${{ runner.os }}-nuget |
| 171 | +
|
| 172 | + - name: Restore dependencies |
| 173 | + run: dotnet restore |
| 174 | + working-directory: ./src |
| 175 | + |
| 176 | + - name: Install GitVersion |
| 177 | + run: dotnet tool install --global GitVersion.Tool |
| 178 | + |
| 179 | + - name: Determine Version |
| 180 | + id: gitversion |
| 181 | + uses: gittools/actions/gitversion/[email protected] |
| 182 | + with: |
| 183 | + useConfigFile: true |
| 184 | + updateAssemblyInfo: true |
| 185 | + updateAssemblyInfoFilename: src/AssemblyInfo.cs |
| 186 | + |
| 187 | + - name: Build Solution |
| 188 | + run: dotnet build -c ${{ env.BUILD_CONFIG }} --nologo ${{ env.SOLUTION }} |
| 189 | + working-directory: ./src |
| 190 | + |
| 191 | + - name: Package |
| 192 | + env: |
| 193 | + PACKAGEDIR: '${{ github.workspace }}/release/' |
| 194 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 195 | + run: | |
| 196 | + mkdir $PACKAGEDIR |
| 197 | + dotnet pack --no-build -c ${{ env.BUILD_CONFIG }} -o $PACKAGEDIR -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 198 | + ls -lR $PACKAGEDIR |
| 199 | + working-directory: ./src |
| 200 | + |
| 201 | + - name: Upload |
| 202 | + if: ${{ matrix.os == 'ubuntu-latest' }} |
| 203 | + |
| 204 | + with: |
| 205 | + path: ${{ github.workspace }}/release/*.nupkg |
| 206 | + retention-days: 30 |
| 207 | + |
| 208 | + publish: |
| 209 | + runs-on: ubuntu-latest |
| 210 | + needs: [build, unit-test] |
| 211 | + steps: |
| 212 | + - uses: actions/download-artifact@v2 |
| 213 | + id: download |
| 214 | + |
| 215 | + - name: List artifacts |
| 216 | + run: ls -ldR ${{steps.download.outputs.download-path}}/**/* |
| 217 | + |
| 218 | + - uses: actions/setup-dotnet@v1 |
| 219 | + env: |
| 220 | + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 221 | + with: |
| 222 | + dotnet-version: "6.0.x" |
| 223 | + source-url: https://nuget.pkg.github.com/Project-MONAI/index.json |
| 224 | + |
| 225 | + - name: Publish to GitHub |
| 226 | + run: dotnet nuget push ${{ steps.download.outputs.download-path }}/artifact/*.nupkg |
| 227 | + |
| 228 | + release: |
| 229 | + if: ${{ contains(github.ref, 'refs/heads/main') ||contains(github.head_ref, 'release/') }} |
| 230 | + runs-on: ubuntu-latest |
| 231 | + needs: [build, unit-test] |
| 232 | + env: |
| 233 | + MAJORMINORPATCH: ${{ needs.build.outputs.majorMinorPatch }} |
| 234 | + |
| 235 | + steps: |
| 236 | + - uses: actions/checkout@v2 |
| 237 | + with: |
| 238 | + fetch-depth: 0 |
| 239 | + |
| 240 | + - uses: actions/download-artifact@v2 |
| 241 | + id: download |
| 242 | + |
| 243 | + - name: List artifacts |
| 244 | + run: ls -ldR ${{steps.download.outputs.download-path}}/**/* |
| 245 | + |
| 246 | + - name: Publish to NuGet.org |
| 247 | + run: dotnet nuget push release/*.nupkg -s https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET }} --skip-duplicate |
| 248 | + |
| 249 | + - name: Extract owner and repo |
| 250 | + uses: jungwinter/split@v1 |
| 251 | + id: repo |
| 252 | + with: |
| 253 | + seperator: "/" |
| 254 | + msg: ${{ github.repository }} |
| 255 | + |
| 256 | + - name: Install GitReleaseManager |
| 257 | + uses: gittools/actions/gitreleasemanager/[email protected] |
| 258 | + with: |
| 259 | + versionSpec: "0.13.x" |
| 260 | + |
| 261 | + - name: Create release with GitReleaseManager |
| 262 | + uses: gittools/actions/gitreleasemanager/[email protected] |
| 263 | + with: |
| 264 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 265 | + owner: ${{ steps.repo.outputs._0 }} |
| 266 | + repository: ${{ steps.repo.outputs._1 }} |
| 267 | + milestone: ${{ env.MAJORMINORPATCH }} |
| 268 | + name: Release v${{ env.MAJORMINORPATCH }} |
| 269 | + |
| 270 | + - name: Publish release with GitReleaseManager |
| 271 | + uses: gittools/actions/gitreleasemanager/[email protected] |
| 272 | + if: ${{ contains(github.ref, 'refs/heads/main') }} |
| 273 | + with: |
| 274 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 275 | + owner: ${{ steps.repo.outputs._0 }} |
| 276 | + repository: ${{ steps.repo.outputs._1 }} |
| 277 | + tagName: ${{ env.MAJORMINORPATCH }} |
| 278 | + |
| 279 | + - name: Close release with GitReleaseManager |
| 280 | + uses: gittools/actions/gitreleasemanager/[email protected] |
| 281 | + if: ${{ contains(github.ref, 'refs/heads/main') }} |
| 282 | + with: |
| 283 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 284 | + owner: ${{ steps.repo.outputs._0 }} |
| 285 | + repository: ${{ steps.repo.outputs._1 }} |
| 286 | + milestone: ${{ env.MAJORMINORPATCH }} |
0 commit comments