Skip to content

Commit

Permalink
Add PowerShell script to automate updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mesheets committed Feb 16, 2024
1 parent c79b8fe commit 0d09c04
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.exe
[Tt]humbs.db
[Aa]pp/PDFsam/
[Aa]pp/Readme.txt
65 changes: 65 additions & 0 deletions Update-PDFsamVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

using namespace System.IO

[DriveInfo]$portableDrive = [DriveInfo]::new("E:")
[FileInfo]$PAcInstallerGeneratorPath = [FileInfo]::new("$portableDrive\\PortableApps\\PortableApps.comInstaller\\PortableApps.comInstaller.exe")
[FileInfo]$PAcLauncherGeneratorPath = [FileInfo]::new("$portableDrive\\PortableApps\\PortableApps.comLauncher\\PortableApps.comLauncherGenerator.exe")

[string]$sourceOwnerName = "torakiki"
[string]$sourceProjectName = "PDFsam"
[string]$sourceRepo = "$sourceOwnerName/$sourceProjectName"

[DirectoryInfo]$appPackagingFolder = [DirectoryInfo]::new([Path]::Combine($PSScriptRoot, "App", $sourceProjectName))
[FileInfo]$appInfoFile = [FileInfo]::new([Path]::Combine($PSScriptRoot, "App", "AppInfo", "AppInfo.ini"))


# Import the PsIni module, installing if necessary
# To avoid the need for administrative permissions, installation is for the current user
$ErrorActionPreference = 'Stop'
try {
Import-Module PsIni
} catch {
Install-Module -Scope CurrentUser PsIni
Import-Module PsIni
}

# Determine the latest release tag and version number
[string]$latestVersionTag = gh release view --repo "$sourceRepo" --json tagName --jq ".tagName" 2> $null
[Version]$latestVersion = [Version]::new($latestVersionTag -replace 'v')
[Version]$latestVersionFull = [Version]::new($latestVersion.Major, $latestVersion.Minor, $latestVersion.Build -ge 0 ? $latestVersion.Build : 0, $latestVersion.Revision -ge 0 ? $latestVersion.Revision : 0)
[string]$releaseArtifactName = "pdfsam-$latestVersion-windows"
[string]$releaseArtifactFile = "$releaseArtifactName.zip"


# Download into a temporary folder the portable version of the latest release
[DirectoryInfo]$tempDirectory = [Directory]::CreateTempSubdirectory(".gh-")
gh release download --repo "$sourceRepo" --pattern "$releaseArtifactFile" --dir "$tempDirectory"
[FileInfo]$releaseArtifactFilePath = [Path]::Combine($tempDirectory, $releaseArtifactFile)
Expand-Archive -LiteralPath "$releaseArtifactFilePath" -DestinationPath "$tempDirectory"

# Prepare for generating the new package
if ([Directory]::Exists($appPackagingFolder))
{
[Directory]::Delete($appPackagingFolder, $true)
}
[DirectoryInfo]$extractedPortableAppPath = [Path]::Combine($tempDirectory, $releaseArtifactName, $sourceProjectName)
Move-Item -LiteralPath $extractedPortableAppPath -Destination $appPackagingFolder

# Update the AppInfo INI file
$appInfoContent = Get-IniContent $appInfoFile
$appInfoContent["Version"]["PackageVersion"] = $latestVersionFull.ToString()
$appInfoContent["Version"]["DisplayVersion"] = "$latestVersionFull Release 1"
$appInfoContent | Out-IniFile -FilePath $appInfoFile -Force -Pretty

# Run the PortableApp.com packaging
Start-Process "$PAcLauncherGeneratorPath" -ArgumentList "$PSScriptRoot" -Wait
Start-Process "$PAcInstallerGeneratorPath" -ArgumentList "$PSScriptRoot" -Wait
[FileInfo]$pafAppInstaller = [Path]::Combine(([DirectoryInfo]::new($PSScriptRoot)).Parent, $appInfoContent["Details"]["AppID"] + "_" + $appInfoContent["Version"]["DisplayVersion"].Replace(' ', '_') + ".paf.exe")

# Publish the release and check in the updated files
[string]$releaseName = "{0} {1}" -f $appInfoContent["Details"]["AppID"], $appInfoContent["Version"]["DisplayVersion"]
gh release create "$latestVersionTag" "$pafAppInstaller" --title $releaseName --notes $releaseName

# Cleanup
[Directory]::Delete($appPackagingFolder, $true)
[Directory]::Delete($tempDirectory, $true)

0 comments on commit 0d09c04

Please sign in to comment.