Skip to content

Update release.yml

Update release.yml #1

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build-and-release:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get tag name and version
id: tag
run: |
$tagName = $env:GITHUB_REF -replace 'refs/tags/', ''
$version = $tagName -replace '^v', ''
if ($version -notmatch '^\d+\.\d+(\.\d+)?(\.\d+)?$') {
$version = "$version.0.0"
}
if (($version.Split('.').Count) -eq 2) {
$version = "$version.0.0"
} elseif (($version.Split('.').Count) -eq 3) {
$version = "$version.0"
}
echo "tag_name=$tagName" >> $env:GITHUB_OUTPUT
echo "release_name=$tagName" >> $env:GITHUB_OUTPUT
echo "version=$version" >> $env:GITHUB_OUTPUT
echo "Version will be set to: $version"
shell: pwsh
- name: Update version in app.manifest
run: |
$manifestPath = "SourceServerManager/app.manifest"
$version = "${{ steps.tag.outputs.version }}"
$content = Get-Content $manifestPath -Raw
$content = $content -replace 'version="[\d\.]+"', "version=`"$version`""
Set-Content $manifestPath -Value $content -NoNewline
echo "Updated app.manifest version to: $version"
shell: pwsh
- name: Update version in project file
run: |
$projectPath = "SourceServerManager/SourceServerManager.csproj"
$version = "${{ steps.tag.outputs.version }}"
[xml]$project = Get-Content $projectPath
# Find or create the first PropertyGroup
$propertyGroup = $project.Project.PropertyGroup[0]
if ($null -eq $propertyGroup) {
$propertyGroup = $project.CreateElement("PropertyGroup")
$project.Project.AppendChild($propertyGroup) | Out-Null
}
# Add or update version properties
$versionProperties = @('Version', 'AssemblyVersion', 'FileVersion', 'AssemblyFileVersion')
foreach ($prop in $versionProperties) {
$existingProp = $propertyGroup.SelectSingleNode($prop)
if ($null -eq $existingProp) {
$newProp = $project.CreateElement($prop)
$newProp.InnerText = $version
$propertyGroup.AppendChild($newProp) | Out-Null
} else {
$existingProp.InnerText = $version
}
}
$project.Save($projectPath)
echo "Updated project file version to: $version"
shell: pwsh
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore SourceServerManager/SourceServerManager.csproj
- name: Build application
run: dotnet build SourceServerManager/SourceServerManager.csproj --configuration Release --no-restore
- name: Publish application
run: dotnet publish SourceServerManager/SourceServerManager.csproj --configuration Release --framework net8.0 --runtime win-x64 --self-contained true --output SourceServerManager/bin/Release/net8.0/publish
- name: Setup NSIS
uses: joncloud/makensis-action@v4
- name: Build installer
run: |
cd SourceServerManager/Installer
makensis Installer.nsi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.tag_name }}
release_name: ${{ steps.tag.outputs.release_name }}
draft: false
prerelease: false
body: |
Release ${{ steps.tag.outputs.tag_name }}
## Download
Download the installer below to install Source Server Manager on your Windows system.
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: SourceServerManager/Installer/SourceServerManager.Installer.exe
asset_name: SourceServerManager-${{ steps.tag.outputs.tag_name }}-Setup.exe
asset_content_type: application/octet-stream