|
| 1 | +name: ci |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - v2 |
| 8 | + paths: |
| 9 | + - 'src/**' |
| 10 | + - 'tests/**' |
| 11 | + |
| 12 | + pull_request: |
| 13 | + types: |
| 14 | + - opened |
| 15 | + - synchronize |
| 16 | + - reopened |
| 17 | + |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: verification-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +env: |
| 25 | + VSTEST_CONNECTION_TIMEOUT: 180 |
| 26 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 |
| 27 | + DOTNET_NOLOGO: true |
| 28 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 29 | + NUGET_DIRECTORY: ${{ github.workspace }}/nuget |
| 30 | + NUGET_PACKAGES_ARTIFACT: nuget-packages |
| 31 | + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 |
| 32 | + TERM: xterm |
| 33 | + |
| 34 | +jobs: |
| 35 | + create-nuget: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 # Get all history to allow automatic versioning using MinVer |
| 41 | + |
| 42 | + # Install the .NET SDK indicated in the global.json file |
| 43 | + - name: ⚙️ Setup dotnet versions |
| 44 | + uses: actions/setup-dotnet@v4 |
| 45 | + with: |
| 46 | + dotnet-version: | |
| 47 | + 3.1.x |
| 48 | + 5.0.x |
| 49 | + 6.0.x |
| 50 | + 7.0.x |
| 51 | + 8.0.x |
| 52 | +
|
| 53 | + - name: ⚙️ Setup GIT versioning |
| 54 | + |
| 55 | + with: |
| 56 | + setAllVars: true |
| 57 | + |
| 58 | + - name: 🛠️ Get Changelog Entry |
| 59 | + id: changelog_reader |
| 60 | + uses: mindsers/changelog-reader-action@v2 |
| 61 | + with: |
| 62 | + version: Unreleased |
| 63 | + path: ./CHANGELOG.md |
| 64 | + |
| 65 | + - name: 🛠️ Update tokens in project files |
| 66 | + uses: cschleiden/replace-tokens@v1 |
| 67 | + with: |
| 68 | + files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' |
| 69 | + env: |
| 70 | + RELEASE_VERSION: ${{ env.NBGV_SimpleVersion }}${{ env.NBGV_PrereleaseVersion }} |
| 71 | + RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} |
| 72 | + |
| 73 | + # Create the NuGet package in the folder from the environment variable NuGetDirectory |
| 74 | + - run: | |
| 75 | + dotnet pack src/bunit/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true |
| 76 | + dotnet pack src/bunit.core/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true |
| 77 | + dotnet pack src/bunit.web/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true |
| 78 | + dotnet pack src/bunit.template/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true |
| 79 | + dotnet pack src/bunit.generators/ -c release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true |
| 80 | +
|
| 81 | + # Publish the NuGet package as an artifact, so they can be used in the following jobs |
| 82 | + - uses: actions/upload-artifact@v4 |
| 83 | + with: |
| 84 | + name: ${{ env.NUGET_PACKAGES_ARTIFACT }} |
| 85 | + if-no-files-found: error |
| 86 | + compression-level: 0 # nuget files already compressed |
| 87 | + retention-days: 7 |
| 88 | + path: ${{ env.NUGET_DIRECTORY }}/*.nupkg |
| 89 | + |
| 90 | + validate-nuget: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: [ create-nuget ] |
| 93 | + steps: |
| 94 | + - name: Setup .NET |
| 95 | + uses: actions/setup-dotnet@v4 |
| 96 | + |
| 97 | + - uses: actions/download-artifact@v4 |
| 98 | + with: |
| 99 | + name: ${{ env.NUGET_PACKAGES_ARTIFACT }} |
| 100 | + path: ${{ env.NUGET_DIRECTORY }} |
| 101 | + |
| 102 | + - name: Install nuget validator |
| 103 | + run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global |
| 104 | + |
| 105 | + # Validate metadata and content of the NuGet package |
| 106 | + # https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab |
| 107 | + # If some rules are not applicable, you can disable them |
| 108 | + # using the --excluded-rules or --excluded-rule-ids option |
| 109 | + - name: Validate package |
| 110 | + shell: pwsh |
| 111 | + run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*.nupkg") --excluded-rules IconMustBeSet |
| 112 | + |
| 113 | + run-test: |
| 114 | + strategy: |
| 115 | + fail-fast: false |
| 116 | + matrix: |
| 117 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 118 | + runs-on: ${{ matrix.os }} |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: 🛒 Checkout repository |
| 122 | + uses: actions/checkout@v4 |
| 123 | + with: |
| 124 | + fetch-depth: 0 |
| 125 | + |
| 126 | + - name: ⚙️ Setup dotnet versions |
| 127 | + uses: actions/setup-dotnet@v4 |
| 128 | + with: |
| 129 | + dotnet-version: | |
| 130 | + 3.1.x |
| 131 | + 5.0.x |
| 132 | + 6.0.x |
| 133 | + 7.0.x |
| 134 | + 8.0.x |
| 135 | +
|
| 136 | + - name: 🧪 Run unit tests |
| 137 | + run: dotnet test -c release --blame --blame-crash --blame-hang |
| 138 | + |
| 139 | + - name: 📛 Upload hang- and crash-dumps on test failure |
| 140 | + if: failure() |
| 141 | + uses: actions/upload-artifact@v3 |
| 142 | + with: |
| 143 | + if-no-files-found: ignore |
| 144 | + name: test-dumps |
| 145 | + path: | |
| 146 | + **/*hangdump.dmp |
| 147 | + **/*crashdump.dmp |
| 148 | +
|
| 149 | + validate_template: |
| 150 | + runs-on: ubuntu-latest |
| 151 | + needs: [ create-nuget ] |
| 152 | + steps: |
| 153 | + - uses: actions/checkout@v4 |
| 154 | + with: |
| 155 | + fetch-depth: 0 # Get all history to allow automatic versioning using MinVer |
| 156 | + |
| 157 | + - name: Setup .NET |
| 158 | + uses: actions/setup-dotnet@v4 |
| 159 | + |
| 160 | + - uses: actions/download-artifact@v4 |
| 161 | + with: |
| 162 | + name: ${{ env.NUGET_PACKAGES_ARTIFACT }} |
| 163 | + path: ${{ env.NUGET_DIRECTORY }} |
| 164 | + |
| 165 | + - name: ⚙️ Setup GIT versioning |
| 166 | + |
| 167 | + with: |
| 168 | + setAllVars: true |
| 169 | + |
| 170 | + - name: ✳ Install bUnit template |
| 171 | + run: | |
| 172 | + dotnet new install bunit.template::${NBGV_SimpleVersion}${NBGV_PrereleaseVersion} --nuget-source ${{ env.NUGET_DIRECTORY }} |
| 173 | +
|
| 174 | + - name: ✔ Verify xUnit template |
| 175 | + run: | |
| 176 | + dotnet new bunit --no-restore -o ${{ github.workspace }}/TemplateTestXunit |
| 177 | + echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${{ github.workspace }}/TemplateTestXunit/Directory.Build.props |
| 178 | + dotnet restore ${{ github.workspace }}/TemplateTestXunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} |
| 179 | + dotnet test ${{ github.workspace }}/TemplateTestXunit |
| 180 | +
|
| 181 | + - name: ✔ Verify NUnit template |
| 182 | + run: | |
| 183 | + dotnet new bunit --framework nunit --no-restore -o ${{ github.workspace }}/TemplateTestNunit |
| 184 | + echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${{ github.workspace }}/TemplateTestNunit/Directory.Build.props |
| 185 | + dotnet restore ${{ github.workspace }}/TemplateTestNunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} |
| 186 | + dotnet test ${{ github.workspace }}/TemplateTestNunit |
| 187 | +
|
| 188 | + - name: ✔ Verify MSTest template |
| 189 | + run: | |
| 190 | + dotnet new bunit --framework mstest --no-restore -o ${{ github.workspace }}/TemplateTestMstest |
| 191 | + echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${{ github.workspace }}/TemplateTestMstest/Directory.Build.props |
| 192 | + dotnet restore ${{ github.workspace }}/TemplateTestMstest --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} |
| 193 | + dotnet test ${{ github.workspace }}/TemplateTestMstest |
| 194 | +
|
| 195 | + validate-docs: |
| 196 | + runs-on: ubuntu-latest |
| 197 | + steps: |
| 198 | + - name: 🛒 Checkout repository |
| 199 | + uses: actions/checkout@v4 |
| 200 | + with: |
| 201 | + fetch-depth: 0 |
| 202 | + |
| 203 | + - name: ⚙️ Setup dotnet versions |
| 204 | + uses: actions/setup-dotnet@v4 |
| 205 | + with: |
| 206 | + dotnet-version: | |
| 207 | + 3.1.x |
| 208 | + 5.0.x |
| 209 | + 6.0.x |
| 210 | + 7.0.x |
| 211 | + 8.0.x |
| 212 | +
|
| 213 | + - name: ⚙️ Setup GIT versioning |
| 214 | + |
| 215 | + with: |
| 216 | + setAllVars: true |
| 217 | + |
| 218 | + - name: 🍥 Replace tokens in files |
| 219 | + uses: cschleiden/replace-tokens@v1 |
| 220 | + with: |
| 221 | + files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' |
| 222 | + env: |
| 223 | + RELEASE_VERSION: ${{ env.NBGV_SimpleVersion }}${{ env.NBGV_PrereleaseVersion }} |
| 224 | + RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} |
| 225 | + |
| 226 | + - name: 📄 Build bUnit |
| 227 | + run: dotnet build -c release |
| 228 | + |
| 229 | + - name: 🧪 Run sample unit tests |
| 230 | + run: dotnet test docs/samples/samples.sln |
| 231 | + |
| 232 | + - name: 📄 Build docs |
| 233 | + working-directory: ./docs/site |
| 234 | + run: | |
| 235 | + dotnet tool install --global docfx --version 2.74.1 |
| 236 | + docfx metadata --logLevel error |
| 237 | + docfx build --logLevel warning --warningsAsErrors |
| 238 | +
|
| 239 | + dependency-review: |
| 240 | + runs-on: ubuntu-latest |
| 241 | + permissions: |
| 242 | + contents: read |
| 243 | + if: github.event_name == 'pull_request' && github.repository_owner == 'bunit-dev' |
| 244 | + steps: |
| 245 | + - name: 'Checkout Repository' |
| 246 | + uses: actions/checkout@v4 |
| 247 | + - name: 'Dependency Review' |
| 248 | + uses: actions/dependency-review-action@v3 |
| 249 | + |
| 250 | + release-preview: |
| 251 | + if: github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/v2') |
| 252 | + runs-on: ubuntu-latest |
| 253 | + needs: [ validate-nuget, run-test, validate_template, validate-docs ] |
| 254 | + steps: |
| 255 | + - uses: actions/download-artifact@v4 |
| 256 | + with: |
| 257 | + name: ${{ env.NUGET_PACKAGES_ARTIFACT }} |
| 258 | + path: ${{ env.NUGET_DIRECTORY }} |
| 259 | + |
| 260 | + - name: Setup .NET Core |
| 261 | + uses: actions/setup-dotnet@v4 |
| 262 | + |
| 263 | + - name: 🛠️ Upload library to GitHub Package Repository |
| 264 | + run: dotnet nuget push ${{ env.NUGET_DIRECTORY }}/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/bunit-dev/index.json --skip-duplicate --no-symbols |
| 265 | + |
| 266 | + - name: 🛠️ Upload library to NuGet.org repository |
| 267 | + run: dotnet nuget push ${{ env.NUGET_DIRECTORY }}/*.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols |
0 commit comments