Repos / shark / ea4858962d
commit ea4858962d55dd23b1bfc469d3d50ed3c1ce1e45
Author: Nhân <hi@imnhan.com>
Date:   Sat Jul 9 23:58:41 2022 +0700

    github actions: proper mac application bundle

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index a7900fe..b339dfc 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -9,7 +9,7 @@ jobs:
 
     strategy:
       matrix:
-        os: [ubuntu-latest, macos-latest]
+        os: [ubuntu-latest, macos-10.15]
 
     runs-on: ${{ matrix.os }}
 
@@ -24,14 +24,21 @@ jobs:
       run: make deps-debian
 
     - name: Build for ${{ runner.os }}
+      env:
+          TAG: ${{ github.ref_name }}
       run: make $(echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]')
       # The `tr` stuff is to convert the string to lowercase
 
+    - name: Zip first to prevent GH Artifacts from removing the executable flag
+      run: |
+        cd dist
+        zip -vr "shark-${{ runner.os }}.zip" .
+
     - name: Upload ${{ runner.os }} build
       uses: actions/upload-artifact@v3
       with:
         name: ${{ runner.os }} shark
-        path: dist/*
+        path: dist/shark-${{ runner.os }}.zip
 
     - name: Cross-compile Windows build
       if: runner.os == 'Linux'
@@ -53,7 +60,7 @@ jobs:
         # Because we have multiple OSes in the build matrix, we need to either
         # create a new release, or upload to the release if it already exists.
         if gh release view "$TAG"; then
-          gh release upload "$TAG" dist/*
+          gh release upload "$TAG" dist/*.zip dist/*.exe
         else
           # Work around GH being daft:
           # https://github.com/actions/checkout/issues/290
@@ -63,5 +70,5 @@ jobs:
           git tag -l --format='%(contents)' "$TAG" >> RELEASE_NOTES
           echo '```' >> RELEASE_NOTES
           cat RELEASE_NOTES
-          gh release create "$TAG" dist/* -F RELEASE_NOTES
+          gh release create "$TAG" dist/*.zip dist/*.exe -F RELEASE_NOTES
         fi
diff --git a/Makefile b/Makefile
index 695faba..149aeed 100644
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,10 @@ windows:
 
 macos:
 	GOOS=darwin GOARCH=amd64 go build -tags ebitensinglethread -o dist/shark-macos
+	./scripts/make-mac-bundle.sh dist/shark-macos
 
 clean:
-	rm -f dist/*
+	rm -rf dist/*
 
 # https://ebiten.org/documents/install.html#Debian_/_Ubuntu
 deps-debian:
diff --git a/README.md b/README.md
index a6b8e68..1cf7245 100644
--- a/README.md
+++ b/README.md
@@ -33,8 +33,33 @@ # Download
 
 # Usage
 
-Simply run the provided binary for your OS. Mac & Linux users may need to first
-make the file executable with `chmod +x <file-name>`.
+## Windows & Linux
+
+Simply unzip then run the `shark-windows.exe` or `shark-linux` executable.
+
+## macOS
+
+Since I'm not participating in Apple's $99/yr [protection racket][pr], macOS
+users will need to jump through some hoops to run this program:
+
+- Double click on the downloaded zip file to get the `Shark` app bundle.
+  (skip this step if you downloaded using Safari, which automatically unzips)
+- Drag the `Shark` app bundle into your `Applications` folder.
+- Right-click on `Shark` -> `Open`. You'll see a warning pop-up saying this
+  application was created by an unverified developer (yours truly). Note: you
+  must **right-click instead of double-clicking**, because double-clicking will
+  open a different pop-up which hides the option to open the app.
+
+![](https://user-images.githubusercontent.com/1446315/178136989-247b5d70-ee37-47a6-95b2-a726103b95f3.png)
+
+- Click "Open" anyway.
+- From now on you can launch the Shark application just like any other app,
+  either from Spotlight or from the Applications folder.
+
+In the future I might pay the $99 if I end up writing more macOS apps and this
+becomes enough of a nuisance. Maybe.
+
+## Options
 
 If run from a terminal, use the `-h` argument to see available options.
 Windows users can [create a shortcut][7] to save their desired options.
@@ -90,3 +115,4 @@ # License
 
 [srht]: https://builds.sr.ht/~nhanb/shark/commits/master
 [gh]: https://github.com/nhanb/shark/actions/workflows/main.yml
+[pr]: https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution
diff --git a/icon.icns b/icon.icns
new file mode 100644
index 0000000..857c955
Binary files /dev/null and b/icon.icns differ
diff --git a/scripts/make-mac-bundle.sh b/scripts/make-mac-bundle.sh
new file mode 100755
index 0000000..93d2f5b
--- /dev/null
+++ b/scripts/make-mac-bundle.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env sh
+set -euf
+
+echo "Current version: $TAG"
+
+MAC_EXECUTABLE="$1"
+MAC_ICON=icon.icns
+MAC_BUNDLE_DIR=dist/Shark.app
+
+mkdir -p $MAC_BUNDLE_DIR/Contents/Resources
+mkdir -p $MAC_BUNDLE_DIR/Contents/MacOS
+
+cp "$MAC_ICON" $MAC_BUNDLE_DIR/Contents/Resources/Shark.icns
+cp "$MAC_EXECUTABLE" $MAC_BUNDLE_DIR/Contents/MacOS/Shark
+chmod +x $MAC_BUNDLE_DIR/Contents/MacOS/Shark
+
+cat <<EOT >> $MAC_BUNDLE_DIR/Contents/Info.plist
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><plist version="1.0">
+  <dict>
+    <key>CFBundleExecutable</key>
+    <string>Shark</string>
+    <key>CFBundleGetInfoString</key>
+    <string>Shark $TAG</string>
+    <key>CFBundleVersion</key>
+    <string>0.2</string>
+    <key>CFBundleShortVersionString</key>
+    <string>0.2</string>
+    <key>CFBundleIconFile</key>
+    <string>Shark</string>
+    <key>CFBundleIdentifier</key>
+    <string>com.imnhan.shark</string>
+    <key>LSUIElement</key>
+    <true/>
+</dict>
+</plist>
+EOT
+
+rm "$MAC_EXECUTABLE"