-
Notifications
You must be signed in to change notification settings - Fork 50
197 lines (169 loc) · 6.98 KB
/
Copy pathwindows-installer.yml
File metadata and controls
197 lines (169 loc) · 6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Build Windows Installer
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version number for the installer'
required: false
default: '4.0'
jobs:
build-windows-installer:
# Skip pre-release tags (those containing a hyphen, e.g. v4.1.0-rc.1)
if: ${{ !contains(github.ref_name, '-') || github.event_name == 'workflow_dispatch' }}
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MSYS
update: true
install: >-
base-devel
gcc
make
cmake
pkg-config
python
python-pip
python-setuptools
git
sqlite3
- name: Cache MSYS2 packages
uses: actions/cache@v4
with:
path: D:\a\_temp\msys64\var\cache\pacman\pkg
key: msys2-packages-${{ runner.os }}-${{ hashFiles('.github/workflows/windows-installer.yml') }}
restore-keys: |
msys2-packages-${{ runner.os }}-
- name: Install OpenPLC Runtime using install.sh
shell: msys2 {0}
run: |
echo "=========================================="
echo "Installing OpenPLC Runtime via install.sh"
echo "=========================================="
# Run the install script which handles all dependencies and build
./install.sh
echo "Installation complete!"
- name: Prepare installer payload
shell: pwsh
run: |
Write-Host "Preparing installer payload..."
# Create payload directory structure
New-Item -ItemType Directory -Force -Path "windows\payload\msys64"
New-Item -ItemType Directory -Force -Path "windows\payload\openplc-runtime"
# Copy MSYS2 installation
Write-Host "Copying MSYS2 installation (this may take a while)..."
$msys2Path = "D:\a\_temp\msys64"
if (Test-Path $msys2Path) {
Copy-Item -Path "$msys2Path\*" -Destination "windows\payload\msys64" -Recurse -Force
} else {
Write-Host "MSYS2 path not found at $msys2Path, trying C:\msys64..."
Copy-Item -Path "C:\msys64\*" -Destination "windows\payload\msys64" -Recurse -Force
}
# Copy OpenPLC Runtime (excluding unnecessary files)
Write-Host "Copying OpenPLC Runtime..."
$excludeDirs = @('.git', '.github', '.mypy_cache', '.ruff_cache', '.vscode', 'tests', '__pycache__')
Get-ChildItem -Path "." -Exclude $excludeDirs | Where-Object {
$_.Name -ne "windows" -and $_.Name -ne ".git"
} | ForEach-Object {
if ($_.PSIsContainer) {
Copy-Item -Path $_.FullName -Destination "windows\payload\openplc-runtime\$($_.Name)" -Recurse -Force
} else {
Copy-Item -Path $_.FullName -Destination "windows\payload\openplc-runtime\" -Force
}
}
# Clean up to reduce size
Write-Host "Cleaning up payload to reduce size..."
# Remove pacman cache
$pacmanCache = "windows\payload\msys64\var\cache\pacman\pkg"
if (Test-Path $pacmanCache) {
Remove-Item -Path "$pacmanCache\*" -Force -Recurse -ErrorAction SilentlyContinue
}
# Remove unnecessary MSYS2 directories
$msys2Cleanup = @(
"windows\payload\msys64\var\log",
"windows\payload\msys64\tmp"
)
foreach ($dir in $msys2Cleanup) {
if (Test-Path $dir) {
Remove-Item -Path "$dir\*" -Force -Recurse -ErrorAction SilentlyContinue
}
}
# Calculate payload size
$payloadSize = (Get-ChildItem -Path "windows\payload" -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
Write-Host "Payload size: $([math]::Round($payloadSize, 2)) MB"
- name: Install Inno Setup
shell: pwsh
run: |
Write-Host "Installing Inno Setup..."
choco install innosetup -y --no-progress
# Add Inno Setup to PATH
$env:PATH = "C:\Program Files (x86)\Inno Setup 6;$env:PATH"
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "Process")
- name: Create placeholder icon
shell: pwsh
run: |
# Create a simple placeholder icon if one doesn't exist
# In production, you should include a proper icon file
if (-not (Test-Path "windows\icon.ico")) {
Write-Host "Creating placeholder icon..."
# Download a generic icon or create one
# For now, we'll modify the setup.iss to not require an icon
}
- name: Build installer with Inno Setup
shell: pwsh
run: |
Write-Host "Building installer..."
# NOTE: $version here only labels the installer (filename +
# Add/Remove Programs AppVersion). The version the RUNTIME
# advertises (discovery scan, /api/version) comes from the
# repo-root VERSION file baked into the payload, NOT from the
# tag. That file must be bumped by hand for every release -- see
# webserver/version.py. (A CI-only injection here would not help
# manual `git clone && ./install.sh` installs, which are common.)
#
# Set version from input or tag
$version = "${{ github.event.inputs.version }}"
if ([string]::IsNullOrEmpty($version)) {
$version = "${{ github.ref_name }}".TrimStart('v')
if ([string]::IsNullOrEmpty($version) -or $version -eq "${{ github.ref_name }}") {
$version = "4.0"
}
}
Write-Host "Building version: $version"
# Create output directory
New-Item -ItemType Directory -Force -Path "windows\output"
# Run Inno Setup compiler
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" `
/DMyAppVersion="$version" `
/O"windows\output" `
/F"OpenPLC_Runtime_$($version)_Setup" `
"windows\setup.iss"
if ($LASTEXITCODE -ne 0) {
Write-Error "Inno Setup compilation failed with exit code $LASTEXITCODE"
exit 1
}
Write-Host "Installer built successfully!"
Get-ChildItem "windows\output"
- name: Upload installer artifact
uses: actions/upload-artifact@v4
with:
name: windows-installer
path: windows/output/*.exe
retention-days: 30
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: windows/output/*.exe
draft: false
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}