Skip to content

Commit

Permalink
Generate windows installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Nov 12, 2024
1 parent 9e15e95 commit be74e22
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/installer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Windows Installer

on:
workflow_dispatch:
inputs:
version:
description: "Version to install (e.g. 22.0.0 or 22.0.0-rc.1)"
required: true

jobs:
build:
runs-on: ubuntu-latest
if:
${{ github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: stellar-cli-${{ inputs.version }}-x86_64-pc-windows-msvc.tar.gz
path: stellar-cli.tar.gz

- name: Uncompress Artifact
run: tar xvf stellar-cli.tar.gz

- name: Install Dependencies
run: apt-get update && apt-get -y install nsis

- name: Set up environment
run: |
echo VERSION="${{ inputs.version }}" >> GITHUB_ENV
echo STELLAR_CLI_BINARY="stellar.exe" >> GITHUB_ENV
echo STELLAR_CLI_INSTALLER="stellar-cli-${{ inputs.version }}-x86_64-pc-windows-msvc.exe" >> GITHUB_ENV
- name: Build Installer
run: |
makensis installer.nsi
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.STELLAR_CLI_INSTALLER }}
path: ${{ env.STELLAR_CLI_INSTALLER }}
63 changes: 63 additions & 0 deletions installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
OutFile "$%OUTPUT_FILE%"
InstallDir "$PROGRAMFILES\Stellar CLI"
RequestExecutionLevel admin

; Define WM_SETTINGCHANGE since NSIS doesn’t natively recognize it
!define WM_SETTINGCHANGE 0x1A

Section "Install"
SetOutPath "$INSTDIR"
File "$%STELLAR_CLI_BINARY%"
WriteUninstaller "$INSTDIR\Uninstall.exe"

; Create a shortcut in the Start Menu
CreateDirectory "$SMPROGRAMS\Stellar CLI"
CreateShortCut "$SMPROGRAMS\Stellar CLI\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0

; Add an entry to the Windows "Programs and Features" list
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayName" "Stellar CLI"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayIcon" "$INSTDIR\stellar.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayVersion" "$%VERSION%"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "Publisher" "Stellar"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "InstallLocation" "$INSTDIR"

; Add install directory to the PATH
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $1 "$0;$INSTDIR"
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$1"

; Notify Windows that the PATH has changed
System::Call 'user32::SendMessageA(i 0xFFFF, i ${WM_SETTINGCHANGE}, i 0, i 0)'
SectionEnd

Section "Uninstall"
Delete "$INSTDIR\stellar.exe"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"

; Remove the Start Menu shortcut
Delete "$SMPROGRAMS\Stellar CLI\Uninstall.lnk"
RMDir "$SMPROGRAMS\Stellar CLI"

; Remove the entry from "Programs and Features"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI"

; Restore PATH without the installation directory
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $1 "$0" ; Store the original PATH in $1

; Remove install directory from PATH (manual string removal)
StrLen $2 "$INSTDIR"
loop:
StrCpy $3 "$1" "$2"
StrCmp $3 "$INSTDIR" 0 +3
StrCpy $1 "$1" "" $2
goto loop

; Write the modified PATH back to registry
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$1"

; Notify Windows that the PATH has changed
System::Call 'user32::SendMessageA(i 0xFFFF, i ${WM_SETTINGCHANGE}, i 0, i 0)'
SectionEnd

0 comments on commit be74e22

Please sign in to comment.