Skip to content

Commit

Permalink
Merge pull request #560 from ckadluba/package-validation-release-auto…
Browse files Browse the repository at this point in the history
…mation

Package validation release automation
  • Loading branch information
ckadluba authored Sep 9, 2024
2 parents ea15c53 + 69d9538 commit 66b3117
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 40 deletions.
58 changes: 37 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,56 @@ name: Release

on:
push:
branches: [ dev, main ]
branches:
- main
- dev

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build-and-release:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Read version from csproj
id: extract_version
if: github.ref == 'refs/heads/main'
run: |
VERSION=$(grep '<VersionPrefix>' src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj | sed 's/.*<VersionPrefix>\(.*\)<\/VersionPrefix>.*/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "Tag v$VERSION already exists"
exit 1
fi
- name: Run build
run: ./Build.ps1 -SkipTests
shell: pwsh

- name: Read version from csproj
- name: Get last commit message
id: last_commit
if: success() && github.ref == 'refs/heads/main'
run: |
$selectResult = Select-String -Path ".\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj" -Pattern '<VersionPrefix>(.+)</VersionPrefix>'
$versionMatch = $selectResult.Matches[0].Groups[1].Value
echo ("VERSION=" + $versionMatch) >> $env:GITHUB_ENV
echo "Found version $versionMatch"
- name: Create GitHub release
if: ${{ github.ref_name == 'main' }}
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
automatic_release_tag: "v${{ env.VERSION }}"
title: "v${{ env.VERSION }}"
files: |
artifacts/*.nupkg
artifacts/*.snupkg
git log -1 --pretty=%B > last_commit_message.txt
# Create GitHub release only on main branch (latest release)
- name: Create Release
if: github.ref == 'refs/heads/main' && success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ env.VERSION }} \
--title "v${{ env.VERSION }}" \
--notes "$(cat last_commit_message.txt)" \
artifacts/*.nupkg artifacts/*.snupkg
- name: Publish to nuget.org
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: nuget push artifacts\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{ env.NUGET_API_KEY }}
run: |
nuget push artifacts/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
nuget push artifacts/*.snupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
38 changes: 19 additions & 19 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,55 @@ param (

echo "build: Build started"

Push-Location $PSScriptRoot
Push-Location "$PSScriptRoot"

if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
if (Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore --no-cache

$branch = @{ $true = $env:GITHUB_REF_NAME; $false = $(git symbolic-ref --short -q HEAD) }[$env:GITHUB_REF_NAME -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:GITHUB_RUN_NUMBER, 10); $false = "local" }[$env:GITHUB_RUN_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -ne "dev" -and $revision -ne "local"]
$branch = @{ $true = $env:GITHUB_REF_NAME; $false = $(git symbolic-ref --short -q HEAD) }[$env:GITHUB_REF_NAME -ne $NULL]
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:GITHUB_RUN_NUMBER, 10); $false = "local" }[$env:GITHUB_RUN_NUMBER -ne $NULL]
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10, $branch.Length)))-$revision" }[$branch -ne "dev" -and $revision -ne "local"]

echo "build: Version suffix is $suffix"

foreach ($src in ls src/*) {
Push-Location $src
foreach ($src in Get-ChildItem "$PSScriptRoot/src" -Directory) {
Push-Location $src.FullName

echo "build: Packaging project in $src"
echo "build: Packaging project in $($src.FullName)"

if ($suffix) {
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release -o ..\..\artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }
if ($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

if ($SkipTests -eq $false) {
foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test
foreach ($test in Get-ChildItem "$PSScriptRoot/test" -Filter "*.PerformanceTests" -Directory) {
Push-Location $test.FullName

echo "build: Building performance test project in $test"
echo "build: Building performance test project in $($test.FullName)"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
if ($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
Push-Location $test
foreach ($test in Get-ChildItem "$PSScriptRoot/test" -Filter "*.Tests" -Directory) {
Push-Location $test.FullName

echo "build: Testing project in $test"
echo "build: Testing project in $($test.FullName)"

& dotnet test -c Release --collect "XPlat Code Coverage"
if($LASTEXITCODE -ne 0) { exit 3 }
if ($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 7.0.0
* Fixed issue #543: Update to Serilog v4, remove reference to Serilog.Sinks.PeriodicBatching (thanks to @cancakar35)
* Full automatic release and run on ubuntu-latest agent
* Added developer documentation
* Enabled .NET package validation

# 6.7.1
* Fixed issue #552 by downgrading SqlClient dependency to 5.1.6 which is LTS and fixed the vulnerabilities referenced in issue #544
Expand Down
23 changes: 23 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Creating Releases

## Creating a Pre-release (-dev suffix)

Whenever the `dev` branch is updated (after merging a pull request), the `Release` action is triggered. This action builds a nuget package with a prerelease identifier of the format `-dev-nnnnn` appended to the version number. This package is automatically published on nuget.org.

## Creating a latest Release

### Normal Update (no major version change) {#normal-update}

1. On the `dev` branch, update CHANGES.md and `VersionPrefix` in Serilog.Sinks.MSSqlServer.csproj.

1. Create a PR to merge the `dev` branch into `main`. The `Release` action will be triggered. This action builds a nuget package and publishes it on nuget.org. Additionally a release is created in the GitHub repo. The release summary will be taken from the description of the PR, so best thing is to put something similar to the version summary in CHANGES.md in there.

1. After the release is done, increase the patch version number in `VersionPrefix` in Serilog.Sinks.MSSqlServer.csproj on the `dev` branch. This ensures that the next dev release will have a higher version number than the latest release.

### Major Release (major version change)

1. On the `dev` branch, update CHANGES.md and increase the major version in `VersionPrefix` in Serilog.Sinks.MSSqlServer.csproj. Also set `EnablePackageValidation` to false because on an intial release of a new major version you don't have a baseline version yet on nuget.org to compare with.

1. Create a PR to merge the `dev` branch into `main`. The `Release` action will be triggered. This works the same as described above under [Normal Update]({#normal-update).

1. After the release is done make some changes in Serilog.Sinks.MSSqlServer.csproj on the `dev` branch. Set `EnablePackageValidation` back to true and `PackageValidationBaselineVersion` to the version of the new major release you just created (e.g. 7.0.0). Then also increase the patch version number in `VersionPrefix` (e.g. 7.0.1).
1 change: 1 addition & 0 deletions serilog-sinks-mssqlserver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
Build.ps1 = Build.ps1
CHANGES.md = CHANGES.md
DEVELOPMENT.md = DEVELOPMENT.md
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
.github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<Description>A Serilog sink that writes events to Microsoft SQL Server and Azure SQL</Description>
<VersionPrefix>7.0.0</VersionPrefix>
<EnablePackageValidation>false</EnablePackageValidation>
<PackageValidationBaselineVersion>7.0.0</PackageValidationBaselineVersion>
<Authors>Michiel van Oudheusden;Christian Kadluba;Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;net462;net472;net6.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down

0 comments on commit 66b3117

Please sign in to comment.