Skip to content

Commit 66b3117

Browse files
authored
Merge pull request #560 from ckadluba/package-validation-release-automation
Package validation release automation
2 parents ea15c53 + 69d9538 commit 66b3117

File tree

6 files changed

+85
-40
lines changed

6 files changed

+85
-40
lines changed

.github/workflows/release.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,56 @@ name: Release
22

33
on:
44
push:
5-
branches: [ dev, main ]
5+
branches:
6+
- main
7+
- dev
68

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

1012
jobs:
1113
build-and-release:
12-
runs-on: windows-latest
14+
runs-on: ubuntu-latest
1315
steps:
14-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Read version from csproj
21+
id: extract_version
22+
if: github.ref == 'refs/heads/main'
23+
run: |
24+
VERSION=$(grep '<VersionPrefix>' src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj | sed 's/.*<VersionPrefix>\(.*\)<\/VersionPrefix>.*/\1/')
25+
echo "VERSION=$VERSION" >> $GITHUB_ENV
26+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
27+
echo "Tag v$VERSION already exists"
28+
exit 1
29+
fi
1530
1631
- name: Run build
1732
run: ./Build.ps1 -SkipTests
33+
shell: pwsh
1834

19-
- name: Read version from csproj
35+
- name: Get last commit message
36+
id: last_commit
37+
if: success() && github.ref == 'refs/heads/main'
2038
run: |
21-
$selectResult = Select-String -Path ".\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj" -Pattern '<VersionPrefix>(.+)</VersionPrefix>'
22-
$versionMatch = $selectResult.Matches[0].Groups[1].Value
23-
echo ("VERSION=" + $versionMatch) >> $env:GITHUB_ENV
24-
echo "Found version $versionMatch"
25-
26-
- name: Create GitHub release
27-
if: ${{ github.ref_name == 'main' }}
28-
uses: "marvinpinto/action-automatic-releases@latest"
29-
with:
30-
repo_token: "${{ secrets.GITHUB_TOKEN }}"
31-
prerelease: false
32-
automatic_release_tag: "v${{ env.VERSION }}"
33-
title: "v${{ env.VERSION }}"
34-
files: |
35-
artifacts/*.nupkg
36-
artifacts/*.snupkg
39+
git log -1 --pretty=%B > last_commit_message.txt
40+
41+
# Create GitHub release only on main branch (latest release)
42+
- name: Create Release
43+
if: github.ref == 'refs/heads/main' && success()
44+
env:
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
gh release create v${{ env.VERSION }} \
48+
--title "v${{ env.VERSION }}" \
49+
--notes "$(cat last_commit_message.txt)" \
50+
artifacts/*.nupkg artifacts/*.snupkg
3751
3852
- name: Publish to nuget.org
3953
env:
4054
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
41-
run: nuget push artifacts\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{ env.NUGET_API_KEY }}
55+
run: |
56+
nuget push artifacts/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
57+
nuget push artifacts/*.snupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}

Build.ps1

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,55 @@ param (
77

88
echo "build: Build started"
99

10-
Push-Location $PSScriptRoot
10+
Push-Location "$PSScriptRoot"
1111

12-
if(Test-Path .\artifacts) {
13-
echo "build: Cleaning .\artifacts"
14-
Remove-Item .\artifacts -Force -Recurse
12+
if (Test-Path .\artifacts) {
13+
echo "build: Cleaning .\artifacts"
14+
Remove-Item .\artifacts -Force -Recurse
1515
}
1616

1717
& dotnet restore --no-cache
1818

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

2323
echo "build: Version suffix is $suffix"
2424

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

28-
echo "build: Packaging project in $src"
28+
echo "build: Packaging project in $($src.FullName)"
2929

3030
if ($suffix) {
3131
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
3232
} else {
3333
& dotnet pack -c Release -o ..\..\artifacts
3434
}
35-
if($LASTEXITCODE -ne 0) { exit 1 }
35+
if ($LASTEXITCODE -ne 0) { exit 1 }
3636

3737
Pop-Location
3838
}
3939

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

44-
echo "build: Building performance test project in $test"
44+
echo "build: Building performance test project in $($test.FullName)"
4545

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

4949
Pop-Location
5050
}
5151

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

55-
echo "build: Testing project in $test"
55+
echo "build: Testing project in $($test.FullName)"
5656

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

6060
Pop-Location
6161
}

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 7.0.0
22
* Fixed issue #543: Update to Serilog v4, remove reference to Serilog.Sinks.PeriodicBatching (thanks to @cancakar35)
3+
* Full automatic release and run on ubuntu-latest agent
4+
* Added developer documentation
5+
* Enabled .NET package validation
36

47
# 6.7.1
58
* Fixed issue #552 by downgrading SqlClient dependency to 5.1.6 which is LTS and fixed the vulnerabilities referenced in issue #544

DEVELOPMENT.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Creating Releases
2+
3+
## Creating a Pre-release (-dev suffix)
4+
5+
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.
6+
7+
## Creating a latest Release
8+
9+
### Normal Update (no major version change) {#normal-update}
10+
11+
1. On the `dev` branch, update CHANGES.md and `VersionPrefix` in Serilog.Sinks.MSSqlServer.csproj.
12+
13+
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.
14+
15+
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.
16+
17+
### Major Release (major version change)
18+
19+
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.
20+
21+
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).
22+
23+
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).

serilog-sinks-mssqlserver.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2424
.editorconfig = .editorconfig
2525
Build.ps1 = Build.ps1
2626
CHANGES.md = CHANGES.md
27+
DEVELOPMENT.md = DEVELOPMENT.md
2728
Directory.Build.props = Directory.Build.props
2829
Directory.Packages.props = Directory.Packages.props
2930
.github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<Description>A Serilog sink that writes events to Microsoft SQL Server and Azure SQL</Description>
55
<VersionPrefix>7.0.0</VersionPrefix>
6+
<EnablePackageValidation>false</EnablePackageValidation>
7+
<PackageValidationBaselineVersion>7.0.0</PackageValidationBaselineVersion>
68
<Authors>Michiel van Oudheusden;Christian Kadluba;Serilog Contributors</Authors>
79
<TargetFrameworks>netstandard2.0;net462;net472;net6.0</TargetFrameworks>
810
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

0 commit comments

Comments
 (0)