-
Notifications
You must be signed in to change notification settings - Fork 74
245 lines (216 loc) · 9.24 KB
/
main.yml
File metadata and controls
245 lines (216 loc) · 9.24 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: windows-2022
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Step to check if the commit message contains #GITBUILD
- name: Check Commit Message
shell: powershell
run: |
# Get the commit message
$strVal = '${{ github.event.commits[0].message }}'
# Convert commit message to a single line if multiline
$singleLineStrVal = $strVal -replace "`r`n", " " -replace "`n", " "
if ($singleLineStrVal -match '#GITBUILD') {
Write-Host 'Build commit detected. Proceeding with build...'
echo "build_trigger=true" >> $env:GITHUB_ENV
} else {
Write-Host 'No build commit. Skipping build steps...'
echo "build_trigger=false" >> $env:GITHUB_ENV
}
# Step to ensure the repository is checked out
- uses: actions/checkout@v2
# Inform if build steps are skipped
- name: Inform Skipped Build Steps
if: env.build_trigger != 'true'
shell: powershell
run: |
Write-Host "Skipping build steps because the commit message does not contain #GITBUILD."
# Install 7Zip PowerShell module
- name: Install 7Zip PowerShell Module
if: env.build_trigger == 'true'
shell: powershell
run: Install-Module 7Zip4PowerShell -Force -Verbose
# Restore NuGet packages
- name: Restore NuGet packages
if: env.build_trigger == 'true'
run: nuget restore UnityLauncherPro.sln
# Build the binary
- name: Build Binary
if: env.build_trigger == 'true'
shell: cmd
run: call .\Build.cmd
# Build the artifact
- name: Build Artifact
if: env.build_trigger == 'true'
shell: cmd
run: call .\ArtifactBuild.cmd
# Check that output exists
- name: Validate UnityLauncherPro.exe exists
if: env.build_trigger == 'true'
shell: cmd
run: |
if not exist "UnityLauncherPro\bin\Release\UnityLauncherPro.exe" (
echo ERROR: UnityLauncherPro.exe not found.
exit /b 1
)
echo Found UnityLauncherPro.exe
# 1) Compute a wrapped major.minor.build from the run number
- name: Compute installer version
if: env.build_trigger == 'true'
shell: bash
run: |
TOTAL=${{ github.run_number }}
BUILD=$(( TOTAL % 65536 ))
MINOR_TOTAL=$(( TOTAL / 65536 ))
MINOR=$(( MINOR_TOTAL % 256 ))
MAJOR=$(( MINOR_TOTAL / 256 ))
echo "INSTALLER_MAJOR=$MAJOR" >> $GITHUB_ENV
echo "INSTALLER_MINOR=$MINOR" >> $GITHUB_ENV
echo "INSTALLER_BUILD=$BUILD" >> $GITHUB_ENV
echo "INSTALLER_VER=$MAJOR.$MINOR.$BUILD" >> $GITHUB_ENV
echo "Computed installer version → $MAJOR.$MINOR.$BUILD (run #${{ github.run_number }})"
# 2) Patch your .vdproj in place (inject ProductVersion and a new GUID)
- name: Patch .vdproj ProductVersion & ProductCode
if: env.build_trigger == 'true'
shell: pwsh
run: |
$proj = 'UnityLauncherProInstaller\UnityLauncherProInstaller.vdproj'
$ver = "${{ env.INSTALLER_VER }}" # e.g. 0.0.118
$guid = [Guid]::NewGuid().ToString("B").ToUpper() # e.g. {E821A3F5-1F84-4A4B-BE9D-115D93E9E6F0}
# Read & rewrite line-by-line
$fixed = Get-Content $proj | ForEach-Object {
if ($_ -match '^(\s*)"ProductVersion"') {
# preserve indentation, then inject exactly one pair of braces
"$($Matches[1])""ProductVersion"" = ""8:$ver"""
}
elseif ($_ -match '^(\s*)"ProductCode"') {
"$($Matches[1])""ProductCode"" = ""8:$guid"""
}
else {
$_
}
}
# Overwrite the project
Set-Content -Path $proj -Value $fixed
Write-Host "→ ProductVersion patched to 8:$ver"
Write-Host "→ ProductCode patched to 8:$guid"
# 3) **DEBUG**: print out the patched .vdproj so you can inspect it
- name: Show patched .vdproj
if: env.build_trigger == 'true'
shell: pwsh
run: |
$proj = 'UnityLauncherProInstaller\UnityLauncherProInstaller.vdproj'
Write-Host "=== BEGIN .vdproj CONTENT ==="
Get-Content $proj
Write-Host "=== END .vdproj CONTENT ==="
# locate VS 2022
- name: Locate Visual Studio 2022
id: vswhere
shell: pwsh
run: |
$installPath = vswhere -latest -products * -requires Microsoft.Component.MSBuild `
-property installationPath
if (-not $installPath) { throw 'VS 2022 not found' }
Write-Host "##[set-output name=installPath]$installPath"
# download vs installer builder (v2.0.1)
- name: Download Installer-Projects VSIX
shell: pwsh
run: |
$vsixUrl = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/VisualStudioClient/vsextensions/MicrosoftVisualStudio2022InstallerProjects/2.0.1/vspackage"
Invoke-WebRequest $vsixUrl -OutFile installerprojects.vsix
# install vs installer builder
- name: Install Installer-Projects extension
shell: pwsh
run: |
$vsixInstaller = Join-Path "${{ steps.vswhere.outputs.installPath }}" 'Common7\IDE\VSIXInstaller.exe'
Write-Host "Running: $vsixInstaller installerprojects.vsix /quiet"
& $vsixInstaller installerprojects.vsix /quiet
# Build MSI installer project using Visual Studio 2022 workaround
- name: Build Installer MSI
if: env.build_trigger == 'true'
shell: cmd
run: |
echo === Running BuildInstaller.bat ===
call .\BuildInstaller.bat || echo WARNING: BuildInstaller.bat exited with %ERRORLEVEL%, continuing...
echo === Verifying MSI ===
if exist "UnityLauncherProInstaller\Release\UnityLauncherPro-Installer.msi" (
echo Success: MSI found at UnityLauncherProInstaller\Release\UnityLauncherPro-Installer.msi
exit /b 0
) else (
echo ERROR: MSI not found in UnityLauncherProInstaller\Release
exit /b 1
)
# Get the current date and time
- name: Get current date and time
id: datetime
if: env.build_trigger == 'true' # Only run if build was triggered
run: |
# Save the current date and time to an environment variable
echo "current_datetime=$(date +'%d/%m/%Y %H:%M')" >> $GITHUB_ENV
# Step to get previous tag and commits
- name: Get commits since last release
id: get_commits
if: env.build_trigger == 'true' # Only run if build was triggered
shell: bash
run: |
# Get the most recent tag
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
if [ "$PREV_TAG" = "none" ]; then
echo "No previous tag found, listing all commits"
COMMITS=$(git log --pretty=format:"* %s" --no-merges)
else
echo "Previous tag: $PREV_TAG"
# List commits since last tag
COMMITS=$(git log $PREV_TAG..HEAD --pretty=format:"* %s" --no-merges)
fi
# Save commits to the environment
echo "commits=$COMMITS" >> $GITHUB_ENV
# Create a release
- name: Create Release
id: create_release
if: env.build_trigger == 'true' # Execute only if build was triggered
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{github.run_number}}
release_name: ${{ env.current_datetime }} (${{ github.run_number }})
body: |
Automated Release by GitHub Action CI
### Commits in this release:
${{ env.commits }}
draft: false
prerelease: false
# Upload the release asset
- name: Upload Release Asset
id: upload-release-asset
if: env.build_trigger == 'true' # Execute only if build was triggered
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./UnityLauncherPro.zip
asset_name: UnityLauncherPro.zip
asset_content_type: application/zip
# Upload MSI installer to release
- name: Upload MSI Installer
if: env.build_trigger == 'true'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./UnityLauncherProInstaller/Release/UnityLauncherPro-Installer.msi
asset_name: UnityLauncherPro-Installer.msi
asset_content_type: application/x-msi