Skip to content

Commit

Permalink
Add pre-release workflow and generate changelog in release build
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Oct 2, 2022
1 parent dca8447 commit a03b536
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 24 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/pre_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: pre-release

on: workflow_dispatch

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Get the version
id: get_version
uses: mavrosxristoforos/get-xml-info@1.0
with:
xml-file: './Directory.Build.props'
xpath: '//Version'
- name: Create short version
id: shortversion
run: |
$version = "${{ steps.get_version.outputs.info }}".Substring(0, "${{ steps.get_version.outputs.info }}".LastIndexOf("."))
Write-Host "::set-output name=shortversion::$version"
shell: pwsh
- uses: actions/checkout@v2
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release .\Serilog.Enrichers.Sensitive.sln
- name: Test
run: dotnet test --no-build --verbosity normal -c Release
- name: Create NuGet package for Serilog.Enrichers.Sensitive
run: dotnet pack ./src/Serilog.Enrichers.Sensitive/Serilog.Enrichers.Sensitive.csproj -c Release --no-build --no-restore -o ./packaging
- name: Get changelog
id: get_changelog
run: |
./get-changelog.ps1 -currentVersion "${{ steps.get_version.outputs.info }}"
shell: pwsh
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.info }}
release_name: ${{ steps.get_version.outputs.info }}
draft: false
prerelease: true
body_path: ./version-changelog.md
- name: Upload enricher NuGet package
id: upload-nuget-enricher
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./packaging/Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg
asset_name: Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg
asset_content_type: application/octet-stream
- name: Publish enricher package to public NuGet repository
run: dotnet nuget push -k ${{ secrets.NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json ./packaging/Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg --skip-duplicate --no-symbols
45 changes: 27 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,53 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/releases\//}
shell: bash
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: mavrosxristoforos/get-xml-info@1.0
with:
dotnet-version: |
3.1.x
6.0.x
xml-file: './Directory.Build.props'
xpath: '//Version'
- name: Create short version
id: shortversion
run: |
$version = "${{ steps.get_version.outputs.info }}".Substring(0, "${{ steps.get_version.outputs.info }}".LastIndexOf("."))
Write-Host "::set-output name=shortversion::$version"
shell: pwsh
- uses: actions/checkout@v2
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release .\Serilog.Enrichers.Sensitive.sln
- name: Test
run: dotnet test --no-build --verbosity normal -c Release
- name: Create NuGet package
run: dotnet pack ./src/Serilog.Enrichers.Sensitive/Serilog.Enrichers.Sensitive.csproj -c Release --no-build --no-restore
- name: Create NuGet package for Serilog.Enrichers.Sensitive
run: dotnet pack ./src/Serilog.Enrichers.Sensitive/Serilog.Enrichers.Sensitive.csproj -c Release --no-build --no-restore -o ./packaging
- name: Get changelog
id: get_changelog
run: |
./get-changelog.ps1 -currentVersion "${{ steps.get_version.outputs.info }}"
shell: pwsh
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}
tag_name: ${{ steps.get_version.outputs.info }}
release_name: ${{ steps.get_version.outputs.info }}
draft: false
prerelease: false
- name: Upload NuGet package
id: upload-release-asset
body_path: ./version-changelog.md
- name: Upload enricher NuGet package
id: upload-nuget-enricher
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./packaging/Serilog.Enrichers.Sensitive.${{ steps.get_version.outputs.VERSION }}.nupkg
asset_name: Serilog.Enrichers.Sensitive.${{ steps.get_version.outputs.VERSION }}.nupkg
asset_path: ./packaging/Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg
asset_name: Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg
asset_content_type: application/octet-stream
- name: Publish package to public NuGet repository
run: dotnet nuget push -k ${{ secrets.NUGET_TOKEN }} ./packaging/Serilog.Enrichers.Sensitive.${{ steps.get_version.outputs.VERSION }}.nupkg --skip-duplicate --no-symbols true
- name: Publish enricher package to public NuGet repository
run: dotnet nuget push -k ${{ secrets.NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json ./packaging/Serilog.Enrichers.Sensitive.${{ steps.shortversion.outputs.shortversion }}.nupkg --skip-duplicate --no-symbols
File renamed without changes.
25 changes: 25 additions & 0 deletions get-changelog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
param([string]$currentVersion = $(throw "currentVersion is required"))

$lines = get-content Changelog.md

$started = $false
$output = @()

for($index = 0; $index -lt $lines.Length; $index++)
{
$line = $lines[$index].Trim()
if($line -eq "## $currentVersion")
{
$started = $true
}
elseif($started -and $line.StartsWith("## "))
{
break
}
elseif($started)
{
$output += $line
}
}

$output > version-changelog.md

0 comments on commit a03b536

Please sign in to comment.