← Engineering blog

Getting a signed macOS DMG release working with free GitHub Actions

I wanted people to try TabDance, the macOS terminal I’m building, without having to install Xcode first. GitHub Actions built the app on a free Mac runner. My Developer ID certificate imported successfully, and the identity check found it. Then packaging failed:

…: no identity found

The identity was there. One lookup could see it and the next couldn’t, which is an irritating way to learn that macOS has more than one answer to “where are my certificates?” Fixing that got me to a signed DMG, then GitHub rejected the release upload with a 403. Both failures are worth walking through if you’re setting up the same pipeline.

The runner is free for public repositories such as TabDance. Signing still requires Apple Developer Program membership, usually $99 USD a year.

Workspaces on the left

TabDance exists because I want cmux’s workspace layout with Apple Terminal’s everyday behavior. A workspace list down the left groups each project’s tabs, and I stop having to remember which window belongs to which project. I tried adding that layout to a Rio fork, but clearing, copying, pasting, and typing still felt different.

I clear with Command-K, run cat file.txt, and use Command-A to select the contents. The old build log should be gone. If I clear while editing a long command, the whole wrapped command should survive. Those details sent me to Apple Terminal’s executable to see how it works, as the first post describes.

The current app uses Swift and AppKit, with SwiftTerm handling terminal emulation and rendering. Shells keep running when I switch workspaces. Command-K preserves the command I’m editing, and a text snapshot lets me copy a selection even after the application redraws those cells.

TabDance’s workspace sidebar and tab bar beside a shell printing alpha, beta, and gamma.

Start with the app bundle

The workflow uses macos-latest, checks that the runner is arm64, runs the tests, then builds for Apple silicon:

xcodebuild -project TabDance.xcodeproj -scheme TabDance \
  -destination 'platform=macOS,arch=arm64' \
  -derivedDataPath .build/xcode -skipPackagePluginValidation \
  ARCHS=arm64 ONLY_ACTIVE_ARCH=YES test

./build-app.sh ARCHS=arm64 ONLY_ACTIVE_ARCH=NO

The Xcode project is checked in, and Swift Package Manager fetches the pinned SwiftTerm dependency. Its build-information plugin normally needs interactive approval, which -skipPackagePluginValidation skips for CI. The build script leaves the Release bundle at dist/TabDance.app.

That gets us an app with an ad-hoc signature. The signature can pass an integrity check, but it doesn’t identify an Apple-registered developer. To distribute this build outside the App Store, we sign it again with a Developer ID Application certificate.

The certificate was there

The runner needs both the certificate and its private key. Export them together from Keychain Access as a password-protected .p12 archive, then add two repository secrets under Settings → Secrets and variables → Actions:

Required secrets for Developer ID signing
SecretValue
MACOS_DEVELOPER_ID_P12The base64-encoded certificate and private-key archive.
MACOS_DEVELOPER_ID_P12_PASSWORDThe password used to export it.

On a Mac, base64 -i DeveloperID.p12 | pbcopy puts the encoded archive on the clipboard, ready to paste into the secret. The workflow decodes it to a temporary file and creates a temporary keychain with its own random password. Once those paths and passwords are set, the import looks like this:

security create-keychain -p "$keychain_password" "$keychain_path"
security unlock-keychain -p "$keychain_password" "$keychain_path"
security import "$certificate_path" -k "$keychain_path" \
  -P "$MACOS_DEVELOPER_ID_P12_PASSWORD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s \
  -k "$keychain_password" "$keychain_path"

The last command lets Apple’s signing tools use the private key without opening a GUI prompt. Unlocking the keychain alone isn’t enough, and a CI runner isn’t going to click Allow for you.

All of that succeeded in the failed run. An identity check aimed directly at the temporary keychain found the Developer ID identity. Packaging still reported no identity found.

The fix was to add the temporary keychain to the runner’s user keychain search list. This excerpt omits the parsing code that saves the original list:

# This check queries the temporary keychain directly.
security find-identity -v -p codesigning "$keychain_path"

# Add it to the saved user search list before signing.
keychain_search_list+=("$keychain_path")
security list-keychains -d user -s "${keychain_search_list[@]}"

We already passed --keychain to codesign, which made this especially annoying. The explanation is in man codesign: that option selects where to find the signing identity, but assembling the certificate chain still consults the user’s keychain search list. We’d supplied the location for only one of the two lookups.

Adding the keychain to that list got signing past the failure. The workflow requires exactly one valid Developer ID Application identity and passes its SHA-1 hash to the packaging script, so certificate names can’t make the selection ambiguous.

Under if: always(), cleanup restores the original search list and deletes the temporary keychain. That needed a follow-up fix for unset variables and an empty original list. With set -u, cleanup can fail on the very variables that setup never got around to assigning.

Sign the app, then the disk image

Once the app is signed, packaging is pleasantly ordinary. Put it beside a symlink to /Applications, and Finder gives people the familiar drag-to-Applications destination. These are the packaging steps, leaving out verification and optional notarization for now:

codesign --force --options runtime --timestamp \
  --sign "$MACOS_SIGNING_IDENTITY" \
  --keychain "$MACOS_SIGNING_KEYCHAIN" dist/TabDance.app

staging="$RUNNER_TEMP/tabdance-dmg"
mkdir -p "$staging"
ditto dist/TabDance.app "$staging/TabDance.app"
ln -s /Applications "$staging/Applications"
hdiutil create -volname TabDance -srcfolder "$staging" \
  -ov -format UDZO dist/TabDance-macos-arm64.dmg

codesign --force --timestamp --sign "$MACOS_SIGNING_IDENTITY" \
  --keychain "$MACOS_SIGNING_KEYCHAIN" \
  dist/TabDance-macos-arm64.dmg

--options runtime enables the app’s hardened runtime; --timestamp requests a secure timestamp. UDZO makes a compressed, read-only image. The full script clears old staging output first and verifies both signatures after signing.

Pull requests can build ad-hoc signed artifacts without importing the certificate. A published build needs the signing secrets, and the publish job checks that packaging reported Developer ID signed before accepting its artifact.

The DMG still wasn’t on Releases

A successful actions/upload-artifact step puts the DMG under the workflow run, where this workflow keeps it for seven days. Someone browsing Releases still won’t find the app. The source ZIP and tarball GitHub adds automatically contain source, which is precisely what I wanted to stop asking people to compile.

A second job downloads the Mac build’s DMG and publishes it from Ubuntu. It gets contents: write, sets GH_TOKEN to ${{ github.token }}, and identifies the repository with GH_REPO. Then the GitHub CLI creates a release with the DMG and checksum:

TAG_NAME="${COMMIT_SHA:0:8}"
sha256sum TabDance-macos-arm64.dmg > SHA256SUMS
gh release create "$TAG_NAME" \
  TabDance-macos-arm64.dmg SHA256SUMS \
  --title "$TAG_NAME" --target "$COMMIT_SHA" --generate-notes

The short SHA names the built commit, and --target puts the new tag on that commit. Reruns use gh release upload --clobber to update an existing release. About TabDance displays the same short SHA, so it’s possible to match an installed binary to its source.

Even with the job log showing Contents: write, one upload returned 403. While that older build ran, a newer workflow fix had landed on main. This fits a release API restriction: if the target commit changes workflow files relative to the current default branch, creating the release also requires Workflows write permission. The built-in GITHUB_TOKEN can’t get that permission. More retries with the same token weren’t going to help.

To publish arbitrary older commits, you need a GitHub App or token authorized for that case. The successful run used the built-in token and created release 47710798. This time the signed DMG and checksum were attached where a person looking for the app would expect them.

Release 47710798 reports Developer ID signed and Notarized: false, with the DMG and SHA256SUMS attached alongside GitHub’s source archives.

Signed, with notarization still to do

The screenshot also says Notarized: false, and that’s unfinished work. Signing identifies the developer and protects the signed contents. Notarization sends the software to Apple for automated checks, and stapling attaches the resulting ticket so Gatekeeper can find it offline.

Our script has an optional notarization path using an App Store Connect API key: a .p8 file, key ID, and issuer ID. Those authorize the submission; they’re separate from the .p12 used to sign. The script notarizes and staples the app before copying it into the DMG, then submits and staples the signed DMG too:

xcrun notarytool submit "$dmg" \
  --key "$notary_key" --key-id "$APPLE_NOTARY_KEY_ID" \
  --issuer "$APPLE_NOTARY_ISSUER_ID" --wait --timeout 30m
xcrun stapler staple "$dmg"
xcrun stapler validate "$dmg"

The linked release didn’t run that path, so its Developer ID signature alone won’t promise a warning-free first launch.

On an Apple silicon Mac running macOS 13 or later, download TabDance-macos-arm64.dmg from the release and drag the app to Applications. If macOS blocks it, Apple documents Open Anyway under System Settings → Privacy & Security. The README covers building from source, including for Intel Macs.