-
Notifications
You must be signed in to change notification settings - Fork 148
80 lines (66 loc) · 2.88 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Release
on:
push:
branches: [ dev, main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build-and-release:
runs-on: windows-latest # Build on Windows to ensure .NET Framework targets
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read version from csproj
if: github.ref == 'refs/heads/main'
run: |
# Extract the version from the .csproj file using PowerShell XML parsing
[xml]$csproj = Get-Content 'src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj'
$version = $csproj.Project.PropertyGroup.VersionPrefix
echo "VERSION=$version" >> $env:GITHUB_ENV
# Check if the tag already exists in git
$tagExists = git tag -l "v$version"
if ($tagExists) {
Write-Host "Tag v$version already exists"
exit 1
}
shell: pwsh
- name: Run build
run: ./Build.ps1 -SkipTests
shell: pwsh
- name: Get last commit message
id: last_commit
if: success() && github.ref == 'refs/heads/main'
run: |
git log -1 --pretty=%B > last_commit_message.txt
shell: pwsh
- name: Create Release
if: github.ref == 'refs/heads/main' && success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Der Basisname der Dateien basierend auf der Versionsnummer
$baseFileName = "Serilog.Sinks.MSSqlServer.${{ env.VERSION }}"
# Suche die exakten Dateipfade für .nupkg und .snupkg
$nupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.nupkg" | Select-Object -First 1
$snupkgFile = Get-ChildItem -Path "artifacts/$baseFileName*.snupkg" | Select-Object -First 1
# Überprüfe, ob beide Dateien gefunden wurden
if (-not $nupkgFile) { Write-Error "nupkg file not found" ; exit 1 }
if (-not $snupkgFile) { Write-Error "snupkg file not found" ; exit 1 }
# Ersetze Backslashes durch Forward Slashes für GitHub CLI-Kompatibilität
$nupkgFilePath = $nupkgFile.FullName -replace '\\', '/'
$snupkgFilePath = $snupkgFile.FullName -replace '\\', '/'
# Ausgabe der Dateipfade zu Debugging-Zwecken
Write-Host "Uploading files: $nupkgFilePath, $snupkgFilePath"
# Erstelle das Release mit den genauen Dateipfaden
gh release create v${{ env.VERSION }} `
--title "v${{ env.VERSION }}" `
--notes "$(Get-Content last_commit_message.txt)" `
$nupkgFilePath $snupkgFilePath
shell: pwsh
- 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 ${{ secrets.NUGET_API_KEY }}
shell: pwsh