@@ -55,88 +55,80 @@ jobs:
5555 run : .\DllExport -action Restore -sln-file DmdExtensions.sln
5656
5757 - name : Update version info
58+ id : set_version
5859 shell : pwsh
5960 run : |
6061 function replaceNumericVersion($name, $fileContent) {
61- $RegularExpression = [regex] "^[^/]*\[assembly:\s*$name\(\""(\d+)\.(\d+)\.(\d+)(\.(\d+))?\""\)"
62- foreach($content in $fileContent)
63- {
64- $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
65- if ($match.Success) {
66- $major=$match.groups[1].value -as [int]
67- $minor=$match.groups[2].value -as [int]
68- $patch=$match.groups[3].value -as [int]
69- $revision=$match.groups[4].value -as [int]
70- return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$major.$minor.$patch.$env:GITHUB_RUN_NUMBER"")"
71- }
62+ $RegularExpression = [regex] "^[^/]*\[assembly:\s*$name\(\""(\d+)\.(\d+)\.(\d+)(\.(\d+))?\""\)"
63+ foreach($content in $fileContent) {
64+ $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
65+ if ($match.Success) {
66+ $major=$match.groups[1].value -as [int]
67+ $minor=$match.groups[2].value -as [int]
68+ $patch=$match.groups[3].value -as [int]
69+ return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$major.$minor.$patch.$env:GITHUB_RUN_NUMBER"")]"
7270 }
71+ }
7372 }
7473
7574 function replaceFullVersion($name, $fileContent) {
76- $RegularExpression = [regex] "[^/]*\[assembly:\s*$name\(\""(\d)\.(\d)\.(\d)(-([\w\W]+))?\""\)"
77- foreach($content in $fileContent)
78- {
79- $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
80- if ($match.Success) {
81- $major=$match.groups[1].value -as [int]
82- $minor=$match.groups[2].value -as [int]
83- $patch=$match.groups[3].value -as [int]
84- $tag=$match.groups[5].value
85-
86- $branch = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
87-
88- if ($branch -eq "master" -or $branch -eq "main") {
89- if ($tag) { $version = "$major.$minor.$patch-$tag-r$env:GITHUB_RUN_NUMBER" }
90- else { $version = "$major.$minor.$patch-r$env:GITHUB_RUN_NUMBER" }
91- } else {
92- $version = "$major.$minor.$patch-$($branch.ToUpper())-r$env:GITHUB_RUN_NUMBER"
93- }
94-
95- Write-Host "Changing version to $version"
96- "version=$version" >> $env:GITHUB_OUTPUT
97-
98- return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$version"")"
99- }
75+ $RegularExpression = [regex] "[^/]*\[assembly:\s*$name\(\""(\d)\.(\d)\.(\d)(-([\w\W]+))?\""\)"
76+ foreach($content in $fileContent) {
77+ $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
78+ if ($match.Success) {
79+ $major=$match.groups[1].value -as [int]
80+ $minor=$match.groups[2].value -as [int]
81+ $patch=$match.groups[3].value -as [int]
82+ $tag=$match.groups[5].value
83+
84+ $branch = if ($env:GITHUB_HEAD_REF) { $env:GITHUB_HEAD_REF } else { $env:GITHUB_REF_NAME }
85+
86+ if ($branch -eq "master" -or $branch -eq "main") {
87+ if ($tag) { $version = "$major.$minor.$patch-$tag-r$env:GITHUB_RUN_NUMBER" }
88+ else { $version = "$major.$minor.$patch-r$env:GITHUB_RUN_NUMBER" }
89+ } else {
90+ $version = "$major.$minor.$patch-$($branch.ToUpper())-r$env:GITHUB_RUN_NUMBER"
91+ }
92+
93+ "version=$version" >> $env:GITHUB_OUTPUT
94+ return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$version"")]"
10095 }
96+ }
10197 }
10298
10399 function replaceAny($name, $replaceWith, $fileContent) {
104- $RegularExpression = [regex] "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)"
105- foreach($content in $fileContent)
106- {
107- $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
108- if ($match.Success) {
109- return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$replaceWith"")"
110- }
100+ $RegularExpression = [regex] "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)"
101+ foreach($content in $fileContent) {
102+ $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
103+ if ($match.Success) {
104+ return $fileContent -replace "^[^/]*\[assembly:\s*$name\(\""[^""]*\""\)", "[assembly: $name(""$replaceWith"")]"
111105 }
106+ }
112107 }
113108
114109 $assemblyFile = "VersionAssemblyInfo.cs"
115110 $fileContent = Get-Content $assemblyFile
116111 $fileContent = replaceNumericVersion 'AssemblyVersion' $fileContent
117112 $fileContent = replaceNumericVersion 'AssemblyFileVersion' $fileContent
118113 $fileContent = replaceFullVersion 'AssemblyInformationalVersion' $fileContent
119-
120114 if (-not $env:GITHUB_REF.StartsWith("refs/tags/")) {
121- $fileContent = replaceAny 'AssemblyConfiguration' $env:GITHUB_SHA.Substring(0, 7) $fileContent
115+ $fileContent = replaceAny 'AssemblyConfiguration' $env:GITHUB_SHA.Substring(0, 7) $fileContent
122116 }
123-
124117 $fileContent | Set-Content "$assemblyFile"
125- Write-Host "Patching $assemblyFile"
126118
127119 - name : Build
128120 run : msbuild -t:rebuild /p:Platform=${{ matrix.platform }} /p:Configuration=${{ matrix.configuration }} DmdExtensions.sln
129121
130122 - name : Build installer
131123 run : msbuild /p:Platform=${{ matrix.platform }} /p:Configuration=${{ matrix.configuration }} /p:SolutionDir="$env:GITHUB_WORKSPACE\" .\Installer\Installer.wixproj
132124
133- - name : Generate zip bundle
125+ - name : Package . zip with versioned filename
134126 shell : pwsh
135127 run : |
136- $version = if ($env:GITHUB_REF.StartsWith("refs/tags/")) { $env:GITHUB_REF_NAME } else { $env:GITHUB_SHA.Substring(0, 7) }
137- $outDir = "$env:GITHUB_WORKSPACE\Installer\Builds"
128+ $version = "${{ steps.set_version.outputs.version }}"
129+ $outDir = "$env:GITHUB_WORKSPACE\Installer\Builds"
138130 New-Item -ItemType Directory -Force -Path $outDir | Out-Null
139- $zipArchive = Join-Path $outDir "dmdext-$version-${{ matrix.platform }}.zip"
131+ $zipArchive = Join-Path $outDir "dmdext-v $version-${{ matrix.platform }}.zip"
140132
141133 Compress-Archive -Path "$env:GITHUB_WORKSPACE\Console\bin\${{ matrix.platform }}\${{ matrix.configuration }}\dmdext.exe" -DestinationPath $zipArchive -Force
142134 Compress-Archive -Path "$env:GITHUB_WORKSPACE\Console\bin\${{ matrix.platform }}\${{ matrix.configuration }}\dmdext.log.config" -Update -DestinationPath $zipArchive
@@ -146,64 +138,45 @@ jobs:
146138 Compress-Archive -Path "$env:GITHUB_WORKSPACE\PinMameDevice\bin\${{ matrix.platform }}\${{ matrix.configuration }}\DmdDevice$dllSuffix.dll" -Update -DestinationPath $zipArchive
147139 Compress-Archive -Path "$env:GITHUB_WORKSPACE\PinMameDevice\bin\${{ matrix.platform }}\${{ matrix.configuration }}\DmdDevice.log.config" -Update -DestinationPath $zipArchive
148140
149- # Include default ini template as a folder inside the zip
150- Copy-Item -Path "$env:GITHUB_WORKSPACE\PinMameDevice\DmdDevice.ini" -Destination (New-Item -Type Directory -Force "$env:GITHUB_WORKSPACE\ini-template") | Out-Null
151- Compress-Archive -Path "$env:GITHUB_WORKSPACE\ini-template\*" -Update -DestinationPath $zipArchive
152- Remove-Item "$env:GITHUB_WORKSPACE\ini-template" -Recurse -Force
141+ # add ini template as folder (no nested zip)
142+ $iniTemp = "$env:GITHUB_WORKSPACE\ini-template"
143+ New-Item -Type Directory -Force $iniTemp | Out-Null
144+ Copy-Item -Path "$env:GITHUB_WORKSPACE\PinMameDevice\DmdDevice.ini" -Destination $iniTemp
145+ Compress-Archive -Path "$iniTemp\*" -Update -DestinationPath $zipArchive
146+ Remove-Item $iniTemp -Recurse -Force
153147
154- # Include ' data' folder contents as 'dmdext' directory inside the zip
148+ # include data folder contents as 'dmdext' directory
155149 Rename-Item "$env:GITHUB_WORKSPACE\PinMameDevice\data" "$env:GITHUB_WORKSPACE\PinMameDevice\dmdext"
156150 Compress-Archive -Path "$env:GITHUB_WORKSPACE\PinMameDevice\dmdext\*" -Update -DestinationPath $zipArchive
157151 Rename-Item "$env:GITHUB_WORKSPACE\PinMameDevice\dmdext" "$env:GITHUB_WORKSPACE\PinMameDevice\data"
158152
159- # Upload the already-zipped bundle
160- - name : Upload ZIP artifacts
153+ - name : Rename MSI to versioned filename
154+ shell : pwsh
155+ run : |
156+ $version = "${{ steps.set_version.outputs.version }}"
157+ $outDir = "$env:GITHUB_WORKSPACE\Installer\Builds"
158+ $msi = Get-ChildItem -Path $outDir -Filter *.msi | Select-Object -First 1
159+ if (-not $msi) { throw "MSI not found in $outDir" }
160+ $target = Join-Path $outDir "dmdext-v$version-${{ matrix.platform }}.msi"
161+ Remove-Item $target -Force -ErrorAction SilentlyContinue
162+ Rename-Item -Path $msi.FullName -NewName (Split-Path $target -Leaf)
163+
164+ # Upload the already-zipped bundle WITHOUT re-compressing
165+ - name : Upload ZIP artifact
161166 uses : actions/upload-artifact@v4
162167 with :
163- name : dmdext-${{ matrix.platform }}- zip
164- path : ${{ github.workspace }}\Installer\Builds\* .zip
168+ name : dmdext-v ${{ steps.set_version.outputs.version }}-${{ matrix.platform }}. zip
169+ path : ${{ github.workspace }}\Installer\Builds\dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }} .zip
165170 compression-level : 0
166171 retention-days : 90
167172 if-no-files-found : error
168173
169- # Upload the MSI as-is (not placed inside the zip )
170- - name : Upload installer artifacts
174+ # Upload the MSI as-is (not zipped )
175+ - name : Upload MSI artifact
171176 uses : actions/upload-artifact@v4
172177 with :
173- name : dmdext-${{ matrix.platform }}- msi
174- path : ${{ github.workspace }}\Installer\Builds\* .msi
178+ name : dmdext-v ${{ steps.set_version.outputs.version }}-${{ matrix.platform }}. msi
179+ path : ${{ github.workspace }}\Installer\Builds\dmdext-v${{ steps.set_version.outputs.version }}-${{ matrix.platform }} .msi
175180 compression-level : 0
176181 retention-days : 90
177182 if-no-files-found : error
178-
179- create-release :
180- needs : [build-windows]
181- runs-on : ubuntu-latest
182- if : github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
183- steps :
184- # Download both matrix artifacts by pattern and merge into the workspace
185- - name : Download ZIP artifacts
186- uses : actions/download-artifact@v4
187- with :
188- pattern : dmdext-*-zip
189- merge-multiple : true
190-
191- - name : Download MSI artifacts
192- uses : actions/download-artifact@v4
193- with :
194- pattern : dmdext-*-msi
195- merge-multiple : true
196-
197- - name : List files
198- run : ls -alR
199-
200- - name : Create Release
201- uses : ncipollo/release-action@v1
202- with :
203- token : " ${{ secrets.GITHUB_TOKEN }}"
204- generateReleaseNotes : true
205- prerelease : ${{ !startsWith(github.ref, 'refs/tags/') }}
206- allowUpdates : true
207- artifacts : " dmdext*"
208- tag : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', github.sha) }}
209- name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'Latest' }}
0 commit comments