Skip to content

Merge branch 'main' of https://github.com/fkitsantas/Reina.Cryptography #51

Merge branch 'main' of https://github.com/fkitsantas/Reina.Cryptography

Merge branch 'main' of https://github.com/fkitsantas/Reina.Cryptography #51

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