-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (115 loc) · 4.4 KB
/
build-and-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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Build and Release
on:
push:
branches:
- main
paths-ignore:
- '.github/workflows/**'
- 'Resources/**'
- 'README.md'
jobs:
build-and-release:
runs-on: windows-latest
permissions:
contents: write
packages: write
steps:
# Checks-out the repository
- name: Check out code
uses: actions/checkout@v3
# Get the last commit message
- name: Get the last commit message
id: commit_message
run: |
$commitMessage = git log -1 --pretty=%B
echo "::set-output name=message::$commitMessage"
# Calculate version number
- name: Calculate version
id: version
run: |
# Ensure csproj file exists
if (!(Test-Path "Reina.Cryptography.csproj")) {
Write-Error "Reina.Cryptography.csproj file not found"
exit 1
}
# Fetch current version prefix from csproj
[xml]$csproj = Get-Content "Reina.Cryptography.csproj"
$currentVersion = $csproj.Project.PropertyGroup.VersionPrefix
if ([string]::IsNullOrEmpty($currentVersion)) {
Write-Error "VersionPrefix not found in Reina.Cryptography.csproj"
exit 1
}
$versionParts = $currentVersion.Split('.')
$major = [int]$versionParts[0]
$minor = [int]$versionParts[1]
$build = [int]$versionParts[2]
# Calculate new version
$commitCount = git rev-list --count HEAD
$build = ($build + $commitCount) % 10
if ($build -eq 0 -and $commitCount -ne 0) {
$minor += 1
if ($minor -eq 10) {
$major += 1
$minor = 0
}
}
$newVersion = "$major.$minor.$build"
echo "New version: $newVersion"
echo "::set-output name=version::$newVersion"
# Update .csproj file
- name: Update project version
run: |
$csprojPath = "Reina.Cryptography.csproj"
[xml]$csproj = Get-Content $csprojPath
# Check if VersionPrefix exists and update it
if ($csproj.Project.PropertyGroup.VersionPrefix) {
$csproj.Project.PropertyGroup.VersionPrefix = "${{ steps.version.outputs.version }}"
} else {
Write-Error "<VersionPrefix> not found in $csprojPath"
exit 1
}
$csproj.Save($csprojPath)
git config user.name "github-actions"
git config user.email "[email protected]"
git add $csprojPath
git commit -m "Update version to ${{ steps.version.outputs.version }}"
git push
# Install dependencies and build for both target frameworks
- name: Build Project for .NET Framework 4.8.1 and .NET 7
run: |
dotnet restore Reina.Cryptography.csproj
dotnet build Reina.Cryptography.csproj --configuration Release
# List build output for debugging purposes
- name: List build output
run: |
dir .\bin\Release\
# Create a release
- name: Create Release
id: create_release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: ${{ steps.version.outputs.version }}
prerelease: false
title: "Reina.Cryptography v${{ steps.version.outputs.version }}"
body: ${{ steps.commit_message.outputs.message }}
# Upload .dll for .NET Framework 4.8.1 as an asset to the release
- name: Upload .NET Framework 4.8.1 DLL
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/Release/net481/Reina.Cryptography.net481.dll
asset_name: Reina.Cryptography.net481.dll
asset_content_type: application/octet-stream
# Upload .dll for .NET 7 as an asset to the release
- name: Upload .NET 7 DLL
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/Release/net7.0/Reina.Cryptography.net7.0.dll
asset_name: Reina.Cryptography.net7.0.dll
asset_content_type: application/octet-stream