Skip to content

Commit

Permalink
Sign and notarize mac app during ci build
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrw committed Oct 19, 2023
1 parent a9821b5 commit 0d2b7fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
34 changes: 32 additions & 2 deletions .github/workflows/dist_mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install certificates. Write dist_config.json.
env:
DIST_CONFIG: ${{ secrets.PROD_MACOS_DIST_CONFIG }}
CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }}
CERTIFICATE_PWD: ${{ secrets.PROD_MACOS_CERTIFICATE_PWD }}
CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }}
KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }}
NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }}
NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }}
NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
NOTARIZATION_PROFILE: ${{ secrets.PROD_MACOS_NOTARIZATION_PROFILE }}
run: |
# Adapted from https://federicoterzi.com/blog/automatic-code-signing-and-notarization-for-macos-apps-using-github-actions/
# Turn our base64-encoded certificate back to a regular .p12 file
echo $CERTIFICATE | base64 --decode > certificate.p12
echo $DIST_CONFIG | base64 --decode > dist_config.json
# We need to create a new keychain, otherwise using the certificate will prompt
# with a UI dialog asking for the certificate password, which we can't
# use in a headless CI environment
security create-keychain -p "$KEYCHAIN_PWD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$KEYCHAIN_PWD" build.keychain
security import certificate.p12 -k build.keychain -P "$CERTIFICATE_PWD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PWD" build.keychain
echo "Create keychain profile"
xcrun notarytool store-credentials "$NOTARIZATION_PROFILE" --apple-id "$NOTARIZATION_APPLE_ID" --team-id "$NOTARIZATION_TEAM_ID" --password "$NOTARIZATION_PWD"
- name: Install build deps
run: brew install nim scons yasm
- name: Install nim
Expand All @@ -24,8 +56,6 @@ jobs:
run: nimble setup
- name: Save SHAs of submodules
run: 'git submodule status > .submodules.tmp'
- name: Prep dist config
run: cp dist_config.example.json dist_config.json
- name: prereq cache
id: prereq-cache
uses: actions/cache@v3
Expand Down
19 changes: 14 additions & 5 deletions enu.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ task gen, "Generate build_helpers":
discard gen()

proc code_sign(id, path: string) =
exec &"codesign -s '{id}' -v --timestamp --options runtime {path}"
exec &"codesign --force -s '{id}' --options runtime {path} -v"

task dist_prereqs, "Build godot debug and release versions, and download fonts":
p "Buiding distribution prereqs..."
Expand Down Expand Up @@ -293,6 +293,10 @@ task dist_package, "Build distribution binaries":

if config["sign"].get_bool:
let id = config["id"].get_str
if "keychain" in config:
let keychain = config["keychain"].get_str
let password = config["keychain-password"].get_str
exec &"security unlock-keychain -p \"{password}\" {keychain}"
code_sign(id, "dist/Enu.app/Contents/Frameworks/enu.dylib")
code_sign(id, "dist/Enu.app")

Expand All @@ -303,11 +307,16 @@ task dist_package, "Build distribution binaries":
exec &"mv {package_name} dist"

if config["notarize"].get_bool:
let
username = config["notarize-username"].get_str
password = config["notarize-password"].get_str
if "notarize-profile" in config:
let profile = config["notarize-profile"].get_str
exec &"xcrun notarytool submit \"dist/{package_name}\" --keychain-profile \"{profile}\" --wait"

exec &"xcrun altool --notarize-app --primary-bundle-id 'ca.dsrw.enu' --username '{username}' --password '{password}' --file dist/{package_name}"
else:
let
username = config["notarize-username"].get_str
password = config["notarize-password"].get_str

exec &"xcrun altool --notarize-app --primary-bundle-id 'com.getenu.enu' --username '{username}' --password '{password}' --file dist/{package_name}"

elif host_os == "linux":
gen_binding_and_copy_stdlib("server")
Expand Down

0 comments on commit 0d2b7fc

Please sign in to comment.