Skip to content

Commit fcefa3a

Browse files
committed
Add GitHub Workflow to build installer and create release
- Old build workflow is changed to only build for one platform using the Debug configuration, to make sure it builds. This is still useful to know for PRs and commits in general. - Pushes to 'testing' branch will be built for all 3 platforms. - Create UpdateVersion.ps1 script to simplify upgrading versions. It updates all the files needed to set the new version number. This is called by the new create-release.yaml GitHub action. - create-release creates a release draft, then builds all 5 builds (including Installer and Browser). If everything succeeds, it will make the release public and merge into the main branch, which means appcast will point to the new version as well.
1 parent bba9019 commit fcefa3a

6 files changed

Lines changed: 346 additions & 54 deletions

File tree

.github/scripts/UpdateVersion.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
param(
2+
[string]$version
3+
)
4+
5+
$setup_link = "https://github.com/Ellendar/Z2Randomizer/releases/download/$version/Z2Randomizer-$version-Windows-Installer.msi"
6+
$pub_date = Get-Date -Format "dddd, dd MMMM yyyy"
7+
8+
$file = "appcast.xml"
9+
$content = Get-Content $file
10+
if ($content -like "*<title>Version $version</title>*") {
11+
Write-Host "Version $version already exists in appcast.xml"
12+
} else {
13+
$firstMatch = $content | Select-String -Pattern '^\s*<item>' | Select-Object -First 1
14+
$index = $firstMatch.LineNumber - 1
15+
$before = $content[0..($index - 1)]
16+
$after = $content[$index..($content.Length - 1)]
17+
$app_cast_item = @"
18+
<item>
19+
<title>Version $version</title>
20+
<description>
21+
<![CDATA[
22+
See the <a href="https://github.com/Ellendar/Z2Randomizer/blob/main/PatchNotes.md">changelog</a> for details about new features.
23+
]]>
24+
</description>
25+
<pubDate>$pub_date</pubDate>
26+
<enclosure url="$setup_link" sparkle:version="$version" />
27+
</item>
28+
"@
29+
Set-Content $file ($before + $app_cast_item + $after)
30+
}
31+
git add $file
32+
33+
$file = "Directory.Build.targets"
34+
(Get-Content $file) |
35+
ForEach-Object {
36+
$_ -replace '<Version>.*?</Version>', "<Version>$version</Version>"
37+
} | Set-Content $file
38+
git add $file
39+
40+
$file = "README.md"
41+
(Get-Content $file) |
42+
ForEach-Object {
43+
$_ -replace '\[Download\]\([^)]*\)', "[Download]($setup_link)"
44+
} | Set-Content $file
45+
git add $file
46+
47+
$file = "Setup1/Setup1.vdproj"
48+
(Get-Content $file) |
49+
ForEach-Object {
50+
$_ -replace '"ProductVersion"\s*=\s*"8:.*?"', "`"ProductVersion`" = `"8:$version`""
51+
} | Set-Content $file
52+
git add $file
53+
54+
# Only commit if some change was actually staged (to prevent setting error level)
55+
if (git diff --cached --name-only) {
56+
git commit -m "$version Release"
57+
}

.github/workflows/build-debug.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build Z2Randomizer Debug
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- testing
7+
pull_request:
8+
9+
env:
10+
# I'm not a fan of the telemetry as-is, but this also suppresses some lines in the build log.
11+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
12+
# This removes even more spurious lines.
13+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
14+
15+
jobs:
16+
build:
17+
strategy:
18+
matrix:
19+
platform: [
20+
#{ os: windows-latest, arch: x64 },
21+
#{ os: macos-14, arch: arm64 },
22+
{ os: ubuntu-latest, arch: x64 }, # the fastest one (just to make sure it builds)
23+
]
24+
dotnet-version: [ '8.0.x' ]
25+
26+
runs-on: ${{ matrix.platform.os }}
27+
steps:
28+
- name: Checkout codebase
29+
uses: actions/checkout@v6
30+
with:
31+
submodules: recursive
32+
33+
- name: Setup dotnet ${{ matrix.dotnet-version }}
34+
uses: actions/setup-dotnet@v5
35+
with:
36+
dotnet-version: ${{ matrix.dotnet-version }}
37+
38+
- name: Build Desktop Debug
39+
run: dotnet publish -c Debug -o CrossPlatformUI.Desktop/bin/publish CrossPlatformUI.Desktop/CrossPlatformUI.Desktop.csproj
40+
41+
- name: Upload Regular Build To Artifacts
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: Z2Randomizer-${{ matrix.platform.os }}-${{ matrix.platform.arch }}-Debug
45+
# don't compress hard since it's not a real release
46+
compression-level: 6
47+
path: |
48+
CrossPlatformUI.Desktop/bin/publish
49+
!**/*.pdb
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build Z2Randomizer Latest
2+
3+
on:
4+
push:
5+
branches:
6+
- testing
7+
8+
env:
9+
# I'm not a fan of the telemetry as-is, but this also suppresses some lines in the build log.
10+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
11+
# This removes even more spurious lines.
12+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
13+
14+
jobs:
15+
build:
16+
strategy:
17+
matrix:
18+
platform: [
19+
{ os: windows-latest, arch: x64 },
20+
{ os: macos-14, arch: arm64 },
21+
{ os: ubuntu-latest, arch: x64 },
22+
]
23+
dotnet-version: [ '8.0.x' ]
24+
25+
runs-on: ${{ matrix.platform.os }}
26+
steps:
27+
- name: Checkout codebase
28+
uses: actions/checkout@v6
29+
with:
30+
submodules: recursive
31+
32+
- name: Setup dotnet ${{ matrix.dotnet-version }}
33+
uses: actions/setup-dotnet@v5
34+
with:
35+
dotnet-version: ${{ matrix.dotnet-version }}
36+
37+
- name: Build Desktop
38+
run: dotnet publish -c Release -o CrossPlatformUI.Desktop/bin/publish CrossPlatformUI.Desktop/CrossPlatformUI.Desktop.csproj
39+
40+
- name: Upload Regular Build To Artifacts
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: Z2Randomizer-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
44+
compression-level: 9
45+
path: |
46+
CrossPlatformUI.Desktop/bin/publish
47+
!**/*.pdb

.github/workflows/build.yaml

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to release from'
8+
default: main
9+
required: true
10+
type: string
11+
version:
12+
description: 'Version [Format: x.x.x]'
13+
required: true
14+
type: string
15+
16+
env:
17+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
18+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
19+
20+
jobs:
21+
create_version_tag:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout codebase
25+
uses: actions/checkout@v6
26+
with:
27+
ref: ${{ inputs.branch }}
28+
fetch-depth: 0 # required to push tags
29+
30+
- name: Setup git user
31+
run: |
32+
git config user.name "github-actions"
33+
git config user.email "github-actions@users.noreply.github.com"
34+
35+
- name: Create and push tag
36+
shell: pwsh
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: |
40+
$tag = '${{ inputs.version }}'
41+
$tagExists = git tag --list $tag
42+
if ($tagExists) {
43+
git checkout $tag
44+
}
45+
.github/scripts/UpdateVersion.ps1 ${{ inputs.version }}
46+
if ($tagExists) {
47+
$hasChanges = git diff --cached --name-only
48+
if ($hasChanges) {
49+
Write-Error "Tag '$tag' already exists and it is not identical"
50+
exit 1
51+
}
52+
} else {
53+
git tag $tag
54+
git push origin $tag
55+
}
56+
57+
58+
create_draft_release:
59+
runs-on: ubuntu-latest
60+
outputs:
61+
tag: ${{ inputs.version }}
62+
steps:
63+
- name: Create draft release
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
tag_name: ${{ inputs.version }}
67+
draft: true
68+
generate_release_notes: true
69+
files: ""
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
73+
74+
build:
75+
needs:
76+
- create_version_tag
77+
- create_draft_release
78+
strategy:
79+
matrix:
80+
platform: [
81+
{ name: Windows-Portable, os: windows-latest, arch: x64, type: portable },
82+
{ name: Windows-Installer, os: windows-latest, arch: x64, type: installer },
83+
{ name: Ubuntu, os: ubuntu-latest, arch: x64 },
84+
{ name: macOS, os: macos-14, arch: arm64 },
85+
{ name: Browser, os: ubuntu-latest, arch: wasm, type: browser },
86+
]
87+
dotnet-version: [ '8.0.x' ]
88+
89+
runs-on: ${{ matrix.platform.os }}
90+
steps:
91+
- name: Checkout codebase
92+
uses: actions/checkout@v6
93+
with:
94+
ref: ${{ inputs.version }}
95+
submodules: recursive
96+
97+
- name: Setup dotnet ${{ matrix.dotnet-version }}
98+
uses: actions/setup-dotnet@v5
99+
with:
100+
dotnet-version: ${{ matrix.dotnet-version }}
101+
102+
- name: Build Desktop
103+
if: ${{ matrix.platform.type != 'browser' }}
104+
run: dotnet publish -c Release -o CrossPlatformUI.Desktop/bin/publish CrossPlatformUI.Desktop/CrossPlatformUI.Desktop.csproj
105+
106+
- name: Create portable_mode.txt
107+
if: ${{ matrix.platform.type == 'portable' }}
108+
run: echo "The presence of this file enables portable mode" > CrossPlatformUI.Desktop/bin/publish/portable_mode.txt
109+
110+
- name: Package regular build (Windows)
111+
if: ${{ matrix.platform.os == 'windows-latest' && (matrix.platform.type == 'portable' || matrix.platform.type == null) }}
112+
run: |
113+
7z a -tzip -mx=9 Z2Randomizer-${{ inputs.version }}-${{ matrix.platform.name }}-${{ matrix.platform.arch }}.zip CrossPlatformUI.Desktop\bin\publish\ /xr!*.pdb
114+
115+
- name: Package regular build (Non-Windows)
116+
if: ${{ matrix.platform.os != 'windows-latest' && (matrix.platform.type == 'portable' || matrix.platform.type == null) }}
117+
run: |
118+
7z a -tzip -mx=9 Z2Randomizer-${{ inputs.version }}-${{ matrix.platform.name }}-${{ matrix.platform.arch }}.zip CrossPlatformUI.Desktop/bin/publish/ -xr!*.pdb
119+
120+
- name: Build Installer
121+
if: ${{ matrix.platform.type == 'installer' }}
122+
shell: pwsh
123+
run: |
124+
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.com" Z2Randomizer.sln /build 'Release|x64' /project Z2RandomizerSetup
125+
cd Setup1/Release
126+
ren Setup.msi Z2Randomizer_${{ inputs.version }}-${{ matrix.platform.name }}.msi
127+
128+
- name: Build Browser
129+
if: ${{ matrix.platform.type == 'browser' }}
130+
run: |
131+
cd CrossPlatformUI.Browser
132+
dotnet workload restore
133+
cd ..
134+
dotnet publish -c Release CrossPlatformUI.Browser/CrossPlatformUI.Browser.csproj
135+
136+
- name: Upload regular build to GitHub release
137+
if: ${{ matrix.platform.type == 'portable' || matrix.platform.type == null }}
138+
uses: softprops/action-gh-release@v2
139+
with:
140+
tag_name: ${{ inputs.version }}
141+
files: Z2Randomizer-${{ inputs.version }}-${{ matrix.platform.name }}-${{ matrix.platform.arch }}.zip
142+
env:
143+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144+
145+
- name: Upload Installer to GitHub release
146+
if: ${{ matrix.platform.type == 'installer' }}
147+
uses: softprops/action-gh-release@v2
148+
with:
149+
tag_name: ${{ inputs.version }}
150+
files: Setup1/Release/*.msi
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
154+
- name: Upload Browser build to artifacts
155+
if: ${{ matrix.platform.type == 'browser' }}
156+
uses: actions/upload-artifact@v4
157+
with:
158+
name: Z2Randomizer-${{ inputs.version }}-${{ matrix.platform.name }}
159+
path: |
160+
CrossPlatformUI.Browser/bin/Release/net8.0-browser/browser-wasm/AppBundle/
161+
!**/*.pdb
162+
163+
164+
publish_release:
165+
needs: build
166+
runs-on: ubuntu-latest
167+
steps:
168+
- name: Publish release
169+
uses: softprops/action-gh-release@v2
170+
with:
171+
tag_name: ${{ inputs.version }}
172+
draft: false
173+
env:
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175+
176+
177+
merge_release:
178+
needs: publish_release
179+
runs-on: ubuntu-latest
180+
steps:
181+
- name: Checkout codebase
182+
uses: actions/checkout@v6
183+
with:
184+
ref: ${{ inputs.version }}
185+
fetch-depth: 0 # required to merge tag into main
186+
187+
- name: Push release to main branch
188+
run: |
189+
git push origin ${{ inputs.version }}:${{ inputs.branch }}

0 commit comments

Comments
 (0)