Skip to content

Better way of packaging/deploying #29

Better way of packaging/deploying

Better way of packaging/deploying #29

Workflow file for this run

name: Build library
on:
push:
branches:
- main
- feature/*
paths:
- 'src/SvR.ContentPrep/**'
- '.github/workflows/build-library.yml'
tags:
- v*
pull_request:
branches:
- main
paths:
- 'src/SvR.ContentPrep/**'
- 'tests/**'
- '.github/workflows/build-library.yml'
workflow_dispatch:
jobs:
test:
name: 🛠️ Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
checks: write
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4
- name: 👨‍🔧 Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: 🔍 Enable problem matchers
run: echo "::add-matcher::.github/matchers/dotnet.json"
- name: 🦸‍♂️ Restore steriods
uses: actions/cache@v4
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: 🎒 Load packages
run: dotnet restore
- name: 🛠️ Build code
run: |
dotnet build --configuration Release --no-restore ./src/SvR.ContentPrep/SvR.ContentPrep.csproj
- name: ✔️ Testing code
run: dotnet test --configuration Release -v minimal --no-restore --logger GitHubActions '/p:CollectCoverage=true;CoverletOutputFormat="json,lcov,cobertura";MergeWith=${{github.workspace}}/coverage.json;CoverletOutput=${{github.workspace}}/coverage' -- RunConfiguration.CollectSourceInformation=true
- name: 📝 Code Coverage report
env:
REPORTGENERATOR_LICENSE: ${{ secrets.REPORTGENERATOR_LICENSE }}
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.3.10
reportgenerator -reports:${{github.workspace}}/coverage.cobertura.xml -targetdir:${{github.workspace}}/report -reporttypes:MarkdownSummaryGithub -filefilters:-*.g.cs "-classfilters:-WixSharp.*;-WingetIntune.Os.*;-WingetIntune.Internal.MsStore.*" -verbosity:Warning
sed -i 's/# Summary/## 📝 Code Coverage/g' ${{github.workspace}}/report/SummaryGithub.md
sed -i 's/## Coverage/### 📝 Code Coverage details/g' ${{github.workspace}}/report/SummaryGithub.md
cat ${{github.workspace}}/report/*.md >> $GITHUB_STEP_SUMMARY
lint:
name: 📝 Lint code
runs-on: ubuntu-latest
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4
- name: 👨‍🔧 Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: 📃 Check code formatting
if: always()
run: dotnet format --verify-no-changes
publish:
name: 📦 Publish nuget library
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [test, lint]
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4
- name: 👨‍🔧 Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
# - name: 🛠️ Compute version with GitVersion
# run: |
# dotnet tool install --global GitVersion.Tool --version 5.*
# echo "## 📦 Calculated version" >> $GITHUB_STEP_SUMMARY
# echo "" >> $GITHUB_STEP_SUMMARY
# dotnet-gitversion /updateprojectfiles /output buildserver /nofetch
# dotnet-gitversion /nofetch /output json /showvariable NuGetVersionV2 >> $GITHUB_STEP_SUMMARY
- name: 🔍 Enable problem matchers
run: echo "::add-matcher::.github/matchers/dotnet.json"
- name: 🦸‍♂️ Restore steriods
uses: actions/cache@v4
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: 🎒 Load packages
run: dotnet restore
- name: 🛠️ Build code
run: dotnet build ./src/SvR.ContentPrep/SvR.ContentPrep.csproj --configuration Release --no-restore -p:Version=$("${{ github.ref_name }}".Substring(1))
- name: 📦 Pack library
run: dotnet pack ./src/SvR.ContentPrep/SvR.ContentPrep.csproj --configuration Release --no-build -p:Version=$("${{ github.ref_name }}".Substring(1))
- name: ✈️ Publish SvR.ContentPrep to nuget.org
run: dotnet nuget push ./src/SvR.ContentPrep/bin/Release/SvRooij.ContentPrep.*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}