From b56c7db3ec0658497dd4763bb64dfce73d61f54f Mon Sep 17 00:00:00 2001
From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com>
Date: Sun, 11 May 2025 01:29:55 +0300
Subject: [PATCH] Create MacOS app bundle via a project target (#1376)
---
.github/workflows/main.yml | 26 +++---
.../DiscordChatExporter.Gui.csproj | 4 +
.../Publish-MacOSBundle.ps1 | 85 +++++++++++++++++++
bundle-macos-app.ps1 | 71 ----------------
4 files changed, 99 insertions(+), 87 deletions(-)
create mode 100644 DiscordChatExporter.Gui/Publish-MacOSBundle.ps1
delete mode 100644 bundle-macos-app.ps1
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index cb5e2054..4aff7efe 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -133,21 +133,12 @@ jobs:
dotnet publish ${{ matrix.app }}
-p:Version=${{ github.ref_type == 'tag' && github.ref_name || format('999.9.9-ci-{0}', github.sha) }}
-p:CSharpier_Bypass=true
+ -p:PublishMacOSBundle=${{ startsWith(matrix.rid, 'osx-') }}
--output ${{ matrix.app }}/bin/publish/
--configuration Release
--runtime ${{ matrix.rid }}
--self-contained
- - name: Generate macOS .app bundle resources
- if: ${{ startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui' }}
- shell: pwsh
- run: >
- ./bundle-macos-app.ps1
- -BundleName "${{ matrix.asset }}"
- -PublishDir "${{ matrix.app }}/bin/publish/"
- -Version "${{ github.ref_type == 'tag' && github.ref_name || '999.9.9'}}"
- -GitHubSha "${{ github.sha }}"
-
- name: Upload artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
@@ -220,12 +211,15 @@ jobs:
path: ${{ matrix.app }}/
- name: Set permissions
- if: ${{ !startsWith(matrix.rid, 'win-') && !(startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui') }}
- run: chmod +x ${{ matrix.app }}/${{ matrix.asset }}
-
- - name: Set permissions for macOS .app bundle
- if: ${{ startsWith(matrix.rid, 'osx-') && matrix.app == 'DiscordChatExporter.Gui' }}
- run: chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }}
+ if: ${{ !startsWith(matrix.rid, 'win-') }}
+ run: |
+ if [ -f ${{ matrix.app }}/${{ matrix.asset }} ]; then
+ chmod +x ${{ matrix.app }}/${{ matrix.asset }}
+ fi
+
+ if [ -f ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }} ]; then
+ chmod +x ${{ matrix.app }}/${{ matrix.asset }}.app/Contents/MacOS/${{ matrix.asset }}
+ fi
- name: Create package
# Change into the artifacts directory to avoid including the directory itself in the zip archive
diff --git a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj
index fbb92fff..d5e06e6d 100644
--- a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj
+++ b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj
@@ -34,4 +34,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/DiscordChatExporter.Gui/Publish-MacOSBundle.ps1 b/DiscordChatExporter.Gui/Publish-MacOSBundle.ps1
new file mode 100644
index 00000000..93ab032d
--- /dev/null
+++ b/DiscordChatExporter.Gui/Publish-MacOSBundle.ps1
@@ -0,0 +1,85 @@
+param(
+ [Parameter(Mandatory=$true)]
+ [string]$PublishDirPath,
+
+ [Parameter(Mandatory=$true)]
+ [string]$IconsFilePath,
+
+ [Parameter(Mandatory=$true)]
+ [string]$FullVersion,
+
+ [Parameter(Mandatory=$true)]
+ [string]$ShortVersion
+)
+
+# Setup paths
+$tempDirPath = Join-Path $PublishDirPath "../publish-macos-app-temp"
+$bundleName = "DiscordChatExporter.app"
+$bundleDirPath = Join-Path $tempDirPath $bundleName
+$contentsDirPath = Join-Path $bundleDirPath "Contents"
+$macosDirPath = Join-Path $contentsDirPath "MacOS"
+$resourcesDirPath = Join-Path $contentsDirPath "Resources"
+
+try {
+ # Initialize the bundle's directory structure
+ New-Item -Path $bundleDirPath -ItemType Directory -Force
+ New-Item -Path $contentsDirPath -ItemType Directory -Force
+ New-Item -Path $macosDirPath -ItemType Directory -Force
+ New-Item -Path $resourcesDirPath -ItemType Directory -Force
+
+ # Copy icons into the .app's Resources folder
+ Copy-Item -Path $IconsFilePath -Destination (Join-Path $resourcesDirPath "AppIcon.icns") -Force
+
+ # Generate the Info.plist metadata file with the app information
+ $plistContent = @"
+
+
+
+
+ CFBundleDisplayName
+ DiscordChatExporter
+ CFBundleName
+ DiscordChatExporter
+ CFBundleExecutable
+ DiscordChatExporter
+ NSHumanReadableCopyright
+ © Oleksii Holub
+ CFBundleIdentifier
+ me.Tyrrrz.DiscordChatExporter
+ CFBundleSpokenName
+ Discord Chat Exporter
+ CFBundleIconFile
+ AppIcon
+ CFBundleIconName
+ AppIcon
+ CFBundleVersion
+ $FullVersion
+ CFBundleShortVersionString
+ $ShortVersion
+ NSHighResolutionCapable
+
+ CFBundlePackageType
+ APPL
+
+
+"@
+
+ Set-Content -Path (Join-Path $contentsDirPath "Info.plist") -Value $plistContent
+
+ # Delete the previous bundle if it exists
+ if (Test-Path (Join-Path $PublishDirPath $bundleName)) {
+ Remove-Item -Path (Join-Path $PublishDirPath $bundleName) -Recurse -Force
+ }
+
+ # Move all files from the publish directory into the MacOS directory
+ Get-ChildItem -Path $PublishDirPath | ForEach-Object {
+ Move-Item -Path $_.FullName -Destination $macosDirPath -Force
+ }
+
+ # Move the final bundle into the publish directory for upload
+ Move-Item -Path $bundleDirPath -Destination $PublishDirPath -Force
+}
+finally {
+ # Clean up the temporary directory
+ Remove-Item -Path $tempDirPath -Recurse -Force
+}
\ No newline at end of file
diff --git a/bundle-macos-app.ps1 b/bundle-macos-app.ps1
deleted file mode 100644
index 343cdfd4..00000000
--- a/bundle-macos-app.ps1
+++ /dev/null
@@ -1,71 +0,0 @@
-param(
- [Parameter(Mandatory=$true)]
- [string]$BundleName,
-
- [Parameter(Mandatory=$true)]
- [string]$PublishDir,
-
- [Parameter(Mandatory=$true)]
- [string]$Version,
-
- [Parameter(Mandatory=$true)]
- [string]$GitHubSha
-)
-
-# Setup paths
-$appName = "$BundleName.app"
-$appDir = Join-Path "bundle-macos-app-staging" $appName
-$contentsDir = Join-Path $appDir "Contents"
-$macosDir = Join-Path $contentsDir "MacOS"
-$resourcesDir = Join-Path $contentsDir "Resources"
-
-# Create the macOS .app bundle directory structure
-New-Item -ItemType Directory -Path $macosDir -Force
-New-Item -ItemType Directory -Path $resourcesDir -Force
-
-# Copy icon into the .app's Resources folder
-Copy-Item -Path "favicon.icns" -Destination (Join-Path $resourcesDir "AppIcon.icns") -Force
-
-# Generate Info.plist metadata file with app information
-$plistContent = @"
-
-
-
-
- CFBundleDisplayName
- $BundleName
- CFBundleName
- $BundleName
- CFBundleExecutable
- $BundleName
- NSHumanReadableCopyright
- © Oleksii Holub
- CFBundleIdentifier
- me.Tyrrrz.$BundleName
- CFBundleSpokenName
- Discord Chat Exporter
- CFBundleIconFile
- AppIcon
- CFBundleIconName
- AppIcon
- CFBundleVersion
- $GitHubSha
- CFBundleShortVersionString
- $Version
- NSHighResolutionCapable
-
- CFBundlePackageType
- APPL
-
-
-"@
-
-Set-Content -Path (Join-Path $contentsDir "Info.plist") -Value $plistContent
-
-# Move all files from the publish directory into the MacOS directory
-Get-ChildItem -Path $PublishDir | ForEach-Object {
- Move-Item -Path $_.FullName -Destination $macosDir -Force
-}
-
-# Move the final .app bundle into the publish directory for upload
-Move-Item -Path $appDir -Destination $PublishDir -Force
\ No newline at end of file