Upgrade to .NET 8 #500
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build job | |
runs-on: ubuntu-latest | |
outputs: | |
Version: ${{ steps.gitversion.outputs.SemVer }} | |
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup GitVersion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
versionSpec: 5.x | |
- name: Determine Version | |
id: gitversion | |
uses: gittools/actions/gitversion/[email protected] | |
- name: Display GitVersion outputs | |
run: | | |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}" | |
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 8.0.x | |
- name: Variable Substitution appsettings file for tests | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: 'src/DotNetCensus.Tests/appsettings.json' | |
env: | |
AppSettings.GitHubClientId: "${{ secrets.GitHubClientId }}" | |
AppSettings.GitHubClientSecret: "${{ secrets.GitHubClientSecret }}" | |
- name: .NET test | |
run: dotnet test src/DotNetCensus.Tests/DotNetCensus.Tests.csproj -c Debug -e:CollectCoverage=true -e:CoverletOutput=${{ github.workspace }}/TestResults/ -e:CoverletOutputFormat=lcov # using -e parameter to set an environment variable until the /p parameter is fixed: https://github.com/coverlet-coverage/coverlet/issues/1391 | |
- name: Coveralls | |
uses: coverallsapp/github-action@master | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
path-to-lcov: ${{ github.workspace }}/TestResults/coverage.info | |
- name: .NET pack tool to NuGet package | |
run: dotnet pack src/DotNetCensus/DotNetCensus.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}' | |
- name: Upload package back to GitHub | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nugetToolPackage | |
path: src/DotNetCensus/nupkg | |
- name: .NET pack core projecty to NuGet package | |
run: dotnet pack src/DotNetCensus.Core/DotNetCensus.Core.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}' | |
- name: Upload package back to GitHub | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nugetCorePackage | |
path: src/DotNetCensus.Core/nupkg | |
sonarCloud: | |
name: Run SonarCloud analysis | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Run Sonarcloud test | |
uses: samsmithnz/[email protected] | |
with: | |
projects: 'src/DotNetCensus/DotNetCensus.csproj,src/DotNetCensus.Core/DotNetCensus.Core.csproj,src/DotNetCensus.Tests/DotNetCensus.Tests.csproj' | |
dotnet-version: '8.0.x' | |
sonarcloud-organization: 'samsmithnz-github' | |
sonarcloud-project: 'samsmithnz_DotNetCensus' | |
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}' | |
release: | |
name: Release job | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- sonarCloud | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: nugetToolPackage | |
path: nugetToolPackage | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: nugetCorePackage | |
path: nugetCorePackage | |
- name: Display GitVersion outputs | |
run: | | |
echo "Version: ${{ needs.build.outputs.Version }}" | |
echo "CommitsSinceVersionSource: ${{ needs.build.outputs.CommitsSinceVersionSource }}" | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only create a release if there has been a commit/version change | |
with: | |
tag: "v${{ needs.build.outputs.Version }}" | |
name: "v${{ needs.build.outputs.Version }}" | |
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
- name: Publish nuget tool package to nuget.org | |
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only publish a NuGet package if there has been a commit/version change | |
run: dotnet nuget push nugetToolPackage\*.nupkg --api-key "${{ secrets.NUGETTOOLTOKEN }}" --source "https://api.nuget.org/v3/index.json" | |
shell: pwsh | |
- name: Publish nuget core package to nuget.org | |
if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only publish a NuGet package if there has been a commit/version change | |
run: dotnet nuget push nugetCorePackage\*.nupkg --api-key "${{ secrets.NUGETCORETOKEN }}" --source "https://api.nuget.org/v3/index.json" | |
shell: pwsh |