Skip to content

Commit

Permalink
Release script debugged
Browse files Browse the repository at this point in the history
  • Loading branch information
dmenne committed Mar 31, 2023
1 parent e1e916a commit e0ce430
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions FS2020Control.sln
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
png\FS2020Excel.png = png\FS2020Excel.png
png\FS2020SQLite.png = png\FS2020SQLite.png
README.md = README.md
release.ps1 = release.ps1
EndProjectSection
EndProject
Global
Expand Down
5 changes: 5 additions & 0 deletions FS2020Control/FS2020Control.csproj
Expand Up @@ -18,6 +18,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>fs2020.png</PackageIcon>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -30,6 +31,10 @@
<NoWarn>NU1701</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Remove="release.ps1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.100.3" />
<PackageReference Include="itext7" Version="7.2.5" />
Expand Down
104 changes: 104 additions & 0 deletions release.ps1
@@ -0,0 +1,104 @@
# Copied from https://janjones.me/posts/clickonce-installer-build-publish-github/.

[CmdletBinding(PositionalBinding = $false)]
param (
[switch]$OnlyBuild = $false
)

$appName = "FS2020Control"
$projDir = "./FS2020Control"

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"

function Get-ScriptDirectory {
Split-Path -Parent $PSCommandPath
}

Set-Location -Path $PSScriptRoot

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)
# Tag must be a valid version of the form 1.0.0.0
Write-Output "Tag: $tag"
$version = $tag

# Clean output directory.
$publishDir = "bin/publish"
$outDir = "$projDir/$publishDir"
if (Test-Path $outDir) {
Remove-Item -Path $outDir -Recurse
}

# Publish the application.
Push-Location $projDir
try {
Write-Output "Restoring:"
dotnet restore -r win-x86
Write-Output "Publishing:"
$msBuildVerbosityArg = "/v:m"
if ($env:CI) {
$msBuildVerbosityArg = ""
}
$buildCmd = """$msBuildPath"" /target:publish /p:PublishProfile=ClickOnceProfile " +
"/p:ApplicationVersion=$version /p:Configuration=Release " +
"/p:PublishDir=$publishDir /p:PublishUrl=$publishDir $msBuildVerbosityArg"

Invoke-Expression "& $buildCmd"
# Measure publish size.
$publishSize = (Get-ChildItem -Path "$publishDir/Application Files" -Recurse |
Measure-Object -Property Length -Sum).Sum / 1Mb
Write-Output ("Published size: {0:N2} MB" -f $publishSize)
}
finally {
Pop-Location
}

if ($OnlyBuild) {
Write-Output "Build finished."
exit
}

# Clone `gh-pages` branch.
$ghPagesDir = "gh-pages"
if (-Not (Test-Path $ghPagesDir)) {
git clone $(git config --get remote.origin.url) -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 "$appName.application") {
Remove-Item -Path "$appName.application"
}

# Copy new application files.
Write-Output "Copying new files..."
Copy-Item -Path "../$outDir/Application Files", "../$outDir/$appName.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
}

0 comments on commit e0ce430

Please sign in to comment.