Skip to content

Update wpf-release.yml #6

Update wpf-release.yml

Update wpf-release.yml #6

Workflow file for this run

name: Sidekick WPF Release
on:
push:
tags: [v*]
jobs:
release:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Git
run: |
git config --global url."https://user:${{ secrets.GITHUB_TOKEN }}@github".insteadOf https://github
git config --global user.name github-actions
git config --global user.email [email protected]
- name: Run release script
shell: pwsh
run: |
# From https://janjones.me/posts/clickonce-installer-build-publish-github/.
$applicationName = "Sidekick.Wpf" # 👈 Replace with your application project name.
$projectDirectory = "src/Sidekick.Wpf" # 👈 Replace with your project directory (where .csproj resides).
$deployRepository = "https://github.com/Sidekick-Poe/Sidekick-Release.git" # 👈 Replace with the deployment repository.
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
Write-Output "Working directory: $pwd"
# Find MSBuild.
$msBuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
-latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe `
-prerelease | select-object -first 1
Write-Output "MSBuild: $((Get-Command $msBuildPath).Path)"
# Load current Git tag.
$tag = $(git describe --tags)
Write-Output "Tag: $tag"
# Parse tag into a three-number version.
$version = $tag.Split('-')[0].TrimStart('v')
if ($version.Split('.').Count <= 3) {
$version = "$version.0"
}
Write-Output "Version: $version"
# Clean output directory.
$publishDirectory = "$projectDirectory/bin/publish"
if (Test-Path $publishDirectory) {
Remove-Item -Path $publishDirectory -Recurse
}
Write-Output "Publish directory: $publishDirectory"
# Publish the application.
Push-Location $projectDirectory
try {
Write-Output "Restoring:"
dotnet restore -r win-x64
Write-Output "Publishing:"
$msBuildVerbosityArg = "/v:m"
if ($env:CI) {
$msBuildVerbosityArg = ""
}
& $msBuildPath /target:publish /p:PublishProfile=ClickOnceProfile `
/p:ApplicationVersion=$version /p:Configuration=Release `
/p:PublishDir=bin/publish /p:PublishUrl=bin/publish `
$msBuildVerbosityArg
# Measure publish size.
$publishSize = (Get-ChildItem -Path "bin/publish/Application Files" -Recurse |
Measure-Object -Property Length -Sum).Sum / 1Mb
Write-Output ("Published size: {0:N2} MB" -f $publishSize)
}
finally {
Pop-Location
}
# Clone `gh-pages` branch.
$ghPagesDir = "gh-pages"
if (-Not (Test-Path $ghPagesDir)) {
git clone $deployRepository -b gh-pages `
--depth 1 --single-branch $ghPagesDir
}
Push-Location $ghPagesDir
try {
# Remove previous application files.
Write-Output "Removing previous files..."
if (Test-Path "Application Files") {
Remove-Item -Path "Application Files" -Recurse
}
if (Test-Path "$applicationName.application") {
Remove-Item -Path "$applicationName.application"
}
# Copy new application files.
Write-Output "Copying new files..."
Copy-Item -Path "../$publishDirectory/Application Files","../$publishDirectory/$applicationName.application" `
-Destination . -Recurse
# Stage and commit.
Write-Output "Staging..."
git add -A
Write-Output "Committing..."
git commit -m "Update to v$version"
# Push.
git push
} finally {
Pop-Location
}