Skip to content

Commit

Permalink
github actions: proper mac application bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanb committed Jul 10, 2022
1 parent 35e03a9 commit ea48589
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-10.15]

runs-on: ${{ matrix.os }}

Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,33 @@ macOS builds. Such is life.

# 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.
Expand Down Expand Up @@ -90,3 +115,4 @@ this program. If not, see <https://www.gnu.org/licenses/>.

[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
Binary file added icon.icns
Binary file not shown.
38 changes: 38 additions & 0 deletions scripts/make-mac-bundle.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit ea48589

Please sign in to comment.