-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Add macOS pkg installer to deployment (#7554) #7555
Changes from 14 commits
f1c3534
53c83fd
775476d
630ab13
b1a6ce3
aeb0ac7
eb23e07
f9d6b1d
80830d7
d2d599d
6e58a2a
18f41db
3830c33
9454d5e
85f424b
74392ff
1990952
27262ff
f66367d
4db8779
279d53a
bdc40a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes"?> | ||
<installer-gui-script minSpecVersion="1"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For documentation on this file, see Apple Distribution Definition reference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, i think we can change the minSpecVersion to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be clear, I'm mostly adding reference comments because completely unfamiliar with the spec and I use comments like sticky notes for myself 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry. didn't know that. |
||
<title>GitHub CLI</title> | ||
<license file="LICENSE" mime-type="text/plain"/> | ||
<options hostArchitectures="arm64,x86_64" customize="never" require-scripts="false" allow-external-scripts="false"/> | ||
<domains enable_localSystem="true"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should GitHub CLI be system-wide, per-user, or can be anywhere? GitHub Desktop zips up the application and on start up will ask the user if they want to move it from Downloads (in my case) to Applications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @williammartin : would appreciate your 2 cents here as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd be inclined to say I would anticipate the vast majority of users:
So I think I would suggest we sidestep that mess and install into What do you think? |
||
|
||
<choices-outline> | ||
<line choice="gh-cli"/> | ||
</choices-outline> | ||
<choice id="gh-cli" title="GitHub CLI (universal)"> | ||
<pkg-ref id="com.github.cli.pkg"/> | ||
</choice> | ||
|
||
<pkg-ref id="com.github.cli.pkg" auth="root">#com.github.cli.pkg</pkg-ref> | ||
</installer-gui-script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/bin/zsh | ||
set -e | ||
|
||
print_help() { | ||
cat <<EOF | ||
To build a universal pkg for macOS: | ||
script/pkgmacos <tag-name> | ||
|
||
To build and sign set APPLE_DEVELOPER_INSTALLER_ID environment variable before. | ||
For example, if you have a signing identity with the identifier | ||
"Developer ID Installer: Your Name (ABC123DEF)" set it in the variable. | ||
EOF | ||
} | ||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulober : Is this something you've written wholesale or is this based on any existing OSS package script we should reference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote this but i looked up some of your style in the other build files (like the print_help) while learning your code-base. I did mention the developer environment variable after i found out how the build stuff for macOS targets work to make it easier for others to use this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the insight, just to be clear this was pure curiosity! I am always learning by looking at variations on the same approach, like listening to covers of a specific song to appreciate nuances. |
||
|
||
if [ $# -eq 0 ]; then | ||
print_help >&2 | ||
exit 1 | ||
fi | ||
|
||
tag_name="" | ||
|
||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
-h | --help ) | ||
print_help | ||
exit 0 | ||
;; | ||
-* ) | ||
printf "unrecognized flag: %s\n" "$1" >&2 | ||
exit 1 | ||
;; | ||
* ) | ||
tag_name="$1" | ||
shift 1 | ||
;; | ||
esac | ||
done | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any conditions we should short circuit running this script?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really required but it's better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think that's sufficient for this build script or should i also write a safe fail for Linux? |
||
|
||
# check os requirements: is running macOS 12+ and pkgbuild + productbuild are available | ||
os_version=$(sw_vers -productVersion) | ||
major_version=${os_version%%.*} | ||
|
||
if (( major_version < 12 )); then | ||
echo "This script requires macOS 12 or later. You are running macOS ${os_version}." >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! command -v pkgbuild &> /dev/null; then | ||
echo "pkgbuild could not be found. Please install Xcode Command Line Tools." >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! command -v productbuild &> /dev/null; then | ||
echo "productbuild could not be found. Please install Xcode Command Line Tools." >&2 | ||
exit 1 | ||
fi | ||
# end of os requirements check | ||
|
||
# gh-binary paths | ||
bin_path="/bin/gh" | ||
arm64_bin="dist/macos_darwin_arm64$bin_path" | ||
amd64_bin="dist/macos_darwin_amd64_v1$bin_path" | ||
# payload paths | ||
payload_root="pkg_payload" | ||
payload_local_bin="${payload_root}/usr/local/bin" | ||
payload_zsh_site_functions="${payload_root}/usr/local/share/zsh/site-functions" | ||
payload_man1="${payload_root}/usr/local/share/man/man1" | ||
|
||
merge_binaries() { | ||
lipo -create -output "${payload_local_bin}/gh" "$arm64_bin" "$amd64_bin" | ||
} | ||
|
||
build_pkg() { | ||
# setup payload | ||
mkdir -p "${payload_local_bin}" | ||
mkdir -p "${payload_man1}" | ||
mkdir -p "${payload_zsh_site_functions}" | ||
|
||
# copy man pages | ||
for file in ./share/man/man1/gh*.1; do | ||
cp "$file" "${payload_man1}" | ||
done | ||
# Include only Zsh completions, | ||
# the recommended/only option on macOS since Catalina for default shell. | ||
cp "./share/zsh/site-functions/_gh" "${payload_zsh_site_functions}" | ||
|
||
# merge binaries | ||
merge_binaries | ||
|
||
# build pkg | ||
pkgbuild \ | ||
--root "$payload_root" \ | ||
--identifier "com.github.cli" \ | ||
--version "$tag_name" \ | ||
--install-location "/" \ | ||
"dist/com.github.cli.pkg" | ||
|
||
# setup resources | ||
mkdir "build/macOS/resources" | ||
cp "LICENSE" "build/macOS/resources" | ||
|
||
# build distribution | ||
if [ -n "$APPLE_DEVELOPER_INSTALLER_ID" ]; then | ||
# build and sign production package with license | ||
productbuild \ | ||
--distribution "./build/macOS/distribution.xml" \ | ||
--resources "./build/macOS/resources" \ | ||
--package-path "./dist" \ | ||
--timestamp \ | ||
--sign "${APPLE_DEVELOPER_INSTALLER_ID?}" \ | ||
"./dist/gh_${tag_name}_macOS_universal.pkg" | ||
else | ||
echo "skipping macOS pkg code-signing; APPLE_DEVELOPER_INSTALLER_ID not set" >&2 | ||
|
||
# build production package with license without signing | ||
productbuild \ | ||
--distribution "./build/macOS/distribution.xml" \ | ||
--resources "./build/macOS/resources" \ | ||
--package-path "./dist" \ | ||
"./dist/gh_${tag_name}_macOS_universal.pkg" | ||
fi | ||
} | ||
|
||
cleanup() { | ||
# remove temp installer so it does not get uploaded | ||
rm -f "dist/com.github.cli.pkg" | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
build_pkg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How have you been testing
script/pkgmacos
locally?I was wondering how large the new
.pkg
files were, so tried building it locally. I thought about trying to build this locally only to realize we probably want to add a new target toMakefile
as this involves multiple steps.Here's how far I've got so far before realizing I should simply ask 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning the pkg size, its about 24MB:
-rw-r--r--@ 1 paulober staff 24M May 24 14:10 gh_v2.99.8_macOS_universal.pkg
To test it locally:
make manpages make completions ./script/release --local "v2.99.8" --platform macos ./script/pkgmacos v2.99.8
And for the Makefile target. Maybe i can read into it. But as of now i know nothing about the syntax within a Makefile (only cmake).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take that back, it wasn't that difficult. You can now build a pkg using
make macospkg VERSION=v2.99.8
. (goreleaser required)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really going to help the team, thank you for saving us future time 🫶