diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index f0a0194..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Build and test - -on: - push: - branches: - - master - pull_request: - workflow_dispatch: - -jobs: - build: - strategy: - matrix: - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - permissions: - contents: read - - steps: - - uses: actions/checkout@v7 - - - name: Setup .NET - uses: actions/setup-dotnet@v6 - with: - dotnet-version: '8.0.x' - - - name: Restore - run: dotnet restore src/NLog.MailKit.sln - - - name: Build - run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore - - - name: Test - run: dotnet test src/NLog.MailKit.sln --configuration Release --no-build --logger "console;verbosity=normal" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2167601 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,124 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + inputs: + force_nuget_publish: + description: Force NuGet publish # for non-master. The package version gets a suffix. See Create NuGet Package step + type: boolean + default: false + +env: + SOLUTION: src/NLog.MailKit.sln + DOTNET_VERSION: 8.0.x + +jobs: + build: + name: ${{ matrix.name }} + strategy: + matrix: + include: + - os: windows-latest + name: Build, test & NuGet package (Windows) + create_nuget_package: true + - os: ubuntu-latest + name: Build & test (Ubuntu) + create_nuget_package: false + runs-on: ${{ matrix.os }} + permissions: + contents: read + + steps: + - uses: actions/checkout@v7 + + - name: Setup .NET + uses: actions/setup-dotnet@v6 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Restore + run: dotnet restore ${{ env.SOLUTION }} + + - name: Build + run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore + + - name: Test + run: dotnet test ${{ env.SOLUTION }} --configuration Release --no-restore --no-build --logger "console;verbosity=normal" + + - name: Determine version suffix + if: matrix.create_nuget_package + id: version + shell: pwsh + env: + REF: ${{ github.ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + RUN_NUMBER: ${{ github.run_number }} + run: | + if ($env:REF -eq "refs/heads/master") { + echo "suffix=" >> $env:GITHUB_OUTPUT + } elseif ($env:PR_NUMBER) { + echo "suffix=pr.$($env:PR_NUMBER).ci.$($env:RUN_NUMBER)" >> $env:GITHUB_OUTPUT + } else { + echo "suffix=ci.$($env:RUN_NUMBER)" >> $env:GITHUB_OUTPUT + } + + - name: Create NuGet package + if: matrix.create_nuget_package + shell: pwsh + env: + VERSION_SUFFIX: ${{ steps.version.outputs.suffix }} + run: | + if ($env:VERSION_SUFFIX) { + dotnet pack $env:SOLUTION --no-build --configuration Release --output artifacts --version-suffix "$env:VERSION_SUFFIX" + } else { + dotnet pack $env:SOLUTION --no-build --configuration Release --output artifacts + } + + - name: Upload NuGet package + if: matrix.create_nuget_package + uses: actions/upload-artifact@v7 + with: + name: NuGetPackages + path: | + artifacts/*.nupkg + artifacts/*.snupkg + if-no-files-found: error + + publish: + name: Publish NuGet package + needs: build + if: >- + (github.event_name == 'push' && github.ref == 'refs/heads/master') || + (github.event_name == 'workflow_dispatch' && inputs.force_nuget_publish) + runs-on: windows-latest + permissions: + contents: read + id-token: write + + steps: + - name: Download NuGet package + uses: actions/download-artifact@v7 + with: + name: NuGetPackages + path: artifacts + + - name: Setup .NET + uses: actions/setup-dotnet@v6 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: NuGet login + uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2 + id: login + with: + user: ${{ secrets.NUGET_USER }} + + - name: Push to NuGet.org + shell: pwsh + env: + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} + run: dotnet nuget push artifacts\*.nupkg --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml deleted file mode 100644 index c803dd1..0000000 --- a/.github/workflows/nuget.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: NuGet - -on: - workflow_run: - workflows: ["Build and test"] - types: - - completed - branches: - - master - workflow_dispatch: - -jobs: - pack: - if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} - runs-on: windows-latest - permissions: - contents: read - id-token: write - - steps: - - uses: actions/checkout@v7 - - - name: Setup .NET - uses: actions/setup-dotnet@v6 - with: - dotnet-version: '8.0.x' - - - name: Restore - run: dotnet restore src/NLog.MailKit.sln - - - name: Build - run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore - - - name: Determine version suffix - id: version - shell: pwsh - run: | - $ref = "${{ github.ref }}" - if ($ref -eq "refs/heads/master") { - echo "suffix=" >> $env:GITHUB_OUTPUT - } else { - # For a PR: use head_ref (actual branch name), otherwise the ref name - $branchName = "${{ github.head_ref }}" - if ([string]::IsNullOrEmpty($branchName)) { - $branchName = "${{ github.ref_name }}" - } - - # Sanitize: non-alphanumeric -> '-', multiple '-' -> one, trim '-' - $clean = $branchName -replace '[^a-zA-Z0-9]', '-' ` - -replace '-+', '-' ` - -replace '^-|-$', '' - # Truncate to max 40 characters and remove trailing '-' - $short = if ($clean.Length -gt 0) { $clean.Substring(0, [Math]::Min(40, $clean.Length)).TrimEnd('-') } else { "" } - - # PR number prefix - $prNumber = "${{ github.event.pull_request.number }}" - $prPrefix = if ($prNumber) { "pr${prNumber}-" } else { "" } - - # Build number - $build = "${{ github.run_number }}" - - $suffix = "${prPrefix}${short}.${build}" - echo "suffix=$suffix" >> $env:GITHUB_OUTPUT - } - - - name: Pack - shell: pwsh - run: | - $versionSuffix = "${{ steps.version.outputs.suffix }}" - if ($versionSuffix) { - dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts --version-suffix "$versionSuffix" - } else { - dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts - } - - - name: Upload nuget package - uses: actions/upload-artifact@v7 - with: - name: nupkg - path: artifacts/*pkg - - - name: NuGet login - if: github.ref == 'refs/heads/master' - uses: NuGet/login@v1 - id: login - with: - user: ${{ secrets.NUGET_USER }} - - - name: Push to NuGet.org - if: github.ref == 'refs/heads/master' - shell: pwsh - run: dotnet nuget push artifacts\*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/README.md b/README.md index ad62fb5..f140f63 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # NLog.MailKit [![NuGet](https://img.shields.io/nuget/v/NLog.MailKit.svg)](https://www.nuget.org/packages/NLog.MailKit) -[![Build and test](https://github.com/NLog/NLog.MailKit/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/NLog/NLog.MailKit/actions/workflows/build-and-test.yml) +[![Build and test](https://github.com/NLog/NLog.MailKit/actions/workflows/ci.yml/badge.svg)](https://github.com/NLog/NLog.MailKit/actions/workflows/ci.yml) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=nlog.mailkit&metric=bugs)](https://sonarcloud.io/summary/new_code?id=nlog.mailkit) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=nlog.mailkit&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=nlog.mailkit) [![](https://sonarcloud.io/api/project_badges/measure?project=nlog.mailkit&metric=code_smells)](https://sonarcloud.io/project/issues?id=nlog.mailkit&resolved=false&types=CODE_SMELL) @@ -66,7 +66,7 @@ BSD. License of MailKit is MIT ### Builds -Builds and NuGet publishing is running on GitHub actions. See [build-and-test.yml](/.github/workflows/build-and-test.yml) and [nuget.yml](/.github/workflows/nuget.yml) +Builds and NuGet publishing is running on GitHub actions. See [ci.yml](/.github/workflows/ci.yml) SonarQube analysis is running on Azure Devops: [![SonarQube Cloud Build Status](https://dev.azure.com/NLogLogging/NLog/_apis/build/status/NLog.MailKit?branchName=master)](https://dev.azure.com/NLogLogging/NLog/_build/latest?definitionId=25&branchName=master)