Skip to content

Commit b56c7db

Browse files
authored
Create MacOS app bundle via a project target (#1376)
1 parent 59d803d commit b56c7db

File tree

4 files changed

+99
-87
lines changed

4 files changed

+99
-87
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,12 @@ jobs:
133133
dotnet publish ${{ matrix.app }}
134134
-p:Version=${{ github.ref_type == 'tag' && github.ref_name || format('999.9.9-ci-{0}', github.sha) }}
135135
-p:CSharpier_Bypass=true
136+
-p:PublishMacOSBundle=${{ startsWith(matrix.rid, 'osx-') }}
136137
--output ${{ matrix.app }}/bin/publish/
137138
--configuration Release
138139
--runtime ${{ matrix.rid }}
139140
--self-contained
140141
141-
- name: Generate macOS .app bundle resources
142-
if: ${{ startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui' }}
143-
shell: pwsh
144-
run: >
145-
./bundle-macos-app.ps1
146-
-BundleName "${{ matrix.asset }}"
147-
-PublishDir "${{ matrix.app }}/bin/publish/"
148-
-Version "${{ github.ref_type == 'tag' && github.ref_name || '999.9.9'}}"
149-
-GitHubSha "${{ github.sha }}"
150-
151142
- name: Upload artifacts
152143
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
153144
with:
@@ -220,12 +211,15 @@ jobs:
220211
path: ${{ matrix.app }}/
221212

222213
- name: Set permissions
223-
if: ${{ !startsWith(matrix.rid, 'win-') && !(startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui') }}
224-
run: chmod +x ${{ matrix.app }}/${{ matrix.asset }}
225-
226-
- name: Set permissions for macOS .app bundle
227-
if: ${{ startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui' }}
228-
run: chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }}
214+
if: ${{ !startsWith(matrix.rid, 'win-') }}
215+
run: |
216+
if [ -f ${{ matrix.app }}/${{ matrix.asset }} ]; then
217+
chmod +x ${{ matrix.app }}/${{ matrix.asset }}
218+
fi
219+
220+
if [ -f ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }} ]; then
221+
chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }}
222+
fi
229223
230224
- name: Create package
231225
# Change into the artifacts directory to avoid including the directory itself in the zip archive

DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<ProjectReference Include="..\DiscordChatExporter.Core\DiscordChatExporter.Core.csproj" />
3535
</ItemGroup>
3636

37+
<Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)">
38+
<Exec Command="pwsh -ExecutionPolicy Bypass -File $(ProjectDir)/Publish-MacOSBundle.ps1 -PublishDirPath $(PublishDir) -IconsFilePath $(ProjectDir)/../favicon.icns -FullVersion $(Version) -ShortVersion $(AssemblyVersion)" LogStandardErrorAsError="true" />
39+
</Target>
40+
3741
</Project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string]$PublishDirPath,
4+
5+
[Parameter(Mandatory=$true)]
6+
[string]$IconsFilePath,
7+
8+
[Parameter(Mandatory=$true)]
9+
[string]$FullVersion,
10+
11+
[Parameter(Mandatory=$true)]
12+
[string]$ShortVersion
13+
)
14+
15+
# Setup paths
16+
$tempDirPath = Join-Path $PublishDirPath "../publish-macos-app-temp"
17+
$bundleName = "DiscordChatExporter.app"
18+
$bundleDirPath = Join-Path $tempDirPath $bundleName
19+
$contentsDirPath = Join-Path $bundleDirPath "Contents"
20+
$macosDirPath = Join-Path $contentsDirPath "MacOS"
21+
$resourcesDirPath = Join-Path $contentsDirPath "Resources"
22+
23+
try {
24+
# Initialize the bundle's directory structure
25+
New-Item -Path $bundleDirPath -ItemType Directory -Force
26+
New-Item -Path $contentsDirPath -ItemType Directory -Force
27+
New-Item -Path $macosDirPath -ItemType Directory -Force
28+
New-Item -Path $resourcesDirPath -ItemType Directory -Force
29+
30+
# Copy icons into the .app's Resources folder
31+
Copy-Item -Path $IconsFilePath -Destination (Join-Path $resourcesDirPath "AppIcon.icns") -Force
32+
33+
# Generate the Info.plist metadata file with the app information
34+
$plistContent = @"
35+
<?xml version="1.0" encoding="UTF-8"?>
36+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
37+
<plist version="1.0">
38+
<dict>
39+
<key>CFBundleDisplayName</key>
40+
<string>DiscordChatExporter</string>
41+
<key>CFBundleName</key>
42+
<string>DiscordChatExporter</string>
43+
<key>CFBundleExecutable</key>
44+
<string>DiscordChatExporter</string>
45+
<key>NSHumanReadableCopyright</key>
46+
<string>© Oleksii Holub</string>
47+
<key>CFBundleIdentifier</key>
48+
<string>me.Tyrrrz.DiscordChatExporter</string>
49+
<key>CFBundleSpokenName</key>
50+
<string>Discord Chat Exporter</string>
51+
<key>CFBundleIconFile</key>
52+
<string>AppIcon</string>
53+
<key>CFBundleIconName</key>
54+
<string>AppIcon</string>
55+
<key>CFBundleVersion</key>
56+
<string>$FullVersion</string>
57+
<key>CFBundleShortVersionString</key>
58+
<string>$ShortVersion</string>
59+
<key>NSHighResolutionCapable</key>
60+
<true />
61+
<key>CFBundlePackageType</key>
62+
<string>APPL</string>
63+
</dict>
64+
</plist>
65+
"@
66+
67+
Set-Content -Path (Join-Path $contentsDirPath "Info.plist") -Value $plistContent
68+
69+
# Delete the previous bundle if it exists
70+
if (Test-Path (Join-Path $PublishDirPath $bundleName)) {
71+
Remove-Item -Path (Join-Path $PublishDirPath $bundleName) -Recurse -Force
72+
}
73+
74+
# Move all files from the publish directory into the MacOS directory
75+
Get-ChildItem -Path $PublishDirPath | ForEach-Object {
76+
Move-Item -Path $_.FullName -Destination $macosDirPath -Force
77+
}
78+
79+
# Move the final bundle into the publish directory for upload
80+
Move-Item -Path $bundleDirPath -Destination $PublishDirPath -Force
81+
}
82+
finally {
83+
# Clean up the temporary directory
84+
Remove-Item -Path $tempDirPath -Recurse -Force
85+
}

bundle-macos-app.ps1

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)