-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
tools: added support for notarytool for osx notarization #48701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95ccc14
tools: limit MacOS notarization with gon to Xcode version < 13.0
UlisesGascon 7cc24d8
tools: added basic support for notarytool
UlisesGascon dc63135
fix: typo
UlisesGascon 43446db
chore: linting
UlisesGascon a25c08f
chore: linting
UlisesGascon 6ef370b
chore: linting
UlisesGascon 3b7c993
fix: update script credentials
UlisesGascon ec27e52
fix: update script xcode version evaluation
UlisesGascon 9a6e60c
fix: simplification and linting errors
UlisesGascon 0e96609
fix: typo in command name
UlisesGascon 94ca883
fix: add notarization team id
UlisesGascon 1e82540
fix: arguments order
UlisesGascon 4cb6407
fix: environmental variables management
UlisesGascon 639dcb3
Update tools/osx-notarize.sh
UlisesGascon 076dbcb
doc: add TODOs for OSX Notarization next steps
UlisesGascon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
#!/bin/sh | ||
|
||
# Uses gon, from https://github.com/mitchellh/gon, to notarize a generated node-<version>.pkg file | ||
# with Apple for installation on macOS Catalina and later as validated by Gatekeeper. | ||
# Notarize a generated node-<version>.pkg file as an Apple requirement for installation on macOS Catalina and later, as validated by Gatekeeper. | ||
# Uses gon (Xcode version < 13.0) or notarytool (Xcode >= 13.0). | ||
|
||
set -e | ||
|
||
gon_version="0.2.2" | ||
gon_exe="${HOME}/.gon/gon_${gon_version}" | ||
version() { | ||
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' || echo "0" | ||
} | ||
|
||
xcode_version=$(xcodebuild -version | awk '/Xcode/ {print $2}') | ||
xcode_version_result=$(version "$xcode_version") | ||
xcode_version_threshold=$(version "13.0") | ||
pkgid="$1" | ||
|
||
[ -z "$pkgid" ] && \ | ||
echo "Usage: $0 <pkgid>" \ | ||
if [ -z "$pkgid" ]; then | ||
echo "Usage: $0 <pkgid>" | ||
exit 1 | ||
fi | ||
|
||
# shellcheck disable=SC2154 | ||
[ -z "$NOTARIZATION_ID" ] && \ | ||
echo "No NOTARIZATION_ID environment var. Skipping notarization." \ | ||
if [ -z "$NOTARIZATION_ID" ]; then | ||
echo "No NOTARIZATION_ID environment variable. Skipping notarization." | ||
exit 0 | ||
fi | ||
|
||
set -x | ||
|
||
mkdir -p "${HOME}/.gon/" | ||
if [ -z "$NOTARIZATION_PASSWORD" ]; then | ||
echo "No NOTARIZATION_PASSWORD environment variable. Skipping notarization." | ||
exit 0 | ||
fi | ||
|
||
if [ ! -f "${gon_exe}" ]; then | ||
curl -sL "https://github.com/mitchellh/gon/releases/download/v${gon_version}/gon_${gon_version}_macos.zip" -o "${gon_exe}.zip" | ||
(cd "${HOME}/.gon/" && rm -f gon && unzip "${gon_exe}.zip" && mv gon "${gon_exe}") | ||
if [ -z "$NOTARIZATION_TEAM_ID" ]; then | ||
echo "No NOTARIZATION_TEAM_ID environment variable. Skipping notarization." | ||
exit 0 | ||
fi | ||
|
||
sed -e "s/{{appleid}}/${NOTARIZATION_ID}/" -e "s/{{pkgid}}/${pkgid}/" tools/osx-gon-config.json.tmpl \ | ||
> gon-config.json | ||
# TODO(@ulisesGascon): remove support for gon | ||
# when https://github.com/nodejs/build/issues/3385#issuecomment-1729281269 is ready | ||
if [ "$xcode_version_result" -lt "$xcode_version_threshold" ]; then | ||
echo "Notarization process is done with gon." | ||
set -x | ||
|
||
gon_version="0.2.2" | ||
gon_exe="${HOME}/.gon/gon_${gon_version}" | ||
|
||
"${gon_exe}" -log-level=info gon-config.json | ||
mkdir -p "${HOME}/.gon/" | ||
|
||
if [ ! -f "${gon_exe}" ]; then | ||
curl -sL "https://github.com/mitchellh/gon/releases/download/v${gon_version}/gon_${gon_version}_macos.zip" -o "${gon_exe}.zip" | ||
(cd "${HOME}/.gon/" && rm -f gon && unzip "${gon_exe}.zip" && mv gon "${gon_exe}") | ||
fi | ||
|
||
sed -e "s/{{appleid}}/${NOTARIZATION_ID}/" -e "s/{{pkgid}}/${pkgid}/" tools/osx-gon-config.json.tmpl \ | ||
> gon-config.json | ||
|
||
"${gon_exe}" -log-level=info gon-config.json | ||
|
||
else | ||
echo "Notarization process is done with Notarytool." | ||
|
||
if ! command -v xcrun notarytool > /dev/null | ||
then | ||
echo "Notarytool is not present in the system. Notarization has failed." | ||
exit 1 | ||
fi | ||
|
||
# Submit the package for notarization | ||
# TODO(@ulisesGascon): refactor to use --keychain-profile | ||
# when https://github.com/nodejs/build/issues/3385#issuecomment-1729281269 is ready | ||
notarization_output=$( | ||
xcrun notarytool submit \ | ||
--apple-id "$NOTARIZATION_ID" \ | ||
--password "$NOTARIZATION_PASSWORD" \ | ||
--team-id "$NOTARIZATION_TEAM_ID" \ | ||
--wait \ | ||
"node-$pkgid.pkg" 2>&1 | ||
) | ||
|
||
if [ $? -eq 0 ]; then | ||
# Extract the operation ID from the output | ||
operation_id=$(echo "$notarization_output" | awk '/RequestUUID/ {print $NF}') | ||
echo "Notarization submitted. Operation ID: $operation_id" | ||
exit 0 | ||
else | ||
echo "Notarization failed. Error: $notarization_output" | ||
exit 1 | ||
fi | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.