CI: Add zsh-based build framework files for macOS

This commit is contained in:
PatTheMav
2023-02-02 22:20:03 +01:00
parent c33fa8bfa2
commit 1cfa06a2aa
31 changed files with 554 additions and 100 deletions

5
.github/scripts/.Brewfile vendored Normal file
View File

@@ -0,0 +1,5 @@
brew "ccache"
brew "cmake"
brew "git"
brew "jq"
brew "xcbeautify"

22
.github/scripts/utils.zsh/check_macos vendored Normal file
View File

@@ -0,0 +1,22 @@
autoload -Uz is-at-least log_group log_info log_error log_status
local macos_version=$(sw_vers -productVersion)
log_group 'Install macOS build requirements'
log_info 'Checking macOS version...'
if ! is-at-least 11.0 ${macos_version}; then
log_error "Minimum required macOS version is 11.0, but running on macOS ${macos_version}"
return 2
else
log_status "macOS ${macos_version} is recent"
fi
log_info 'Checking for Homebrew...'
if (( ! ${+commands[brew]} )) {
log_error 'No Homebrew command found. Please install Homebrew (https://brew.sh)'
return 2
}
brew bundle --file ${SCRIPT_HOME}/.Brewfile
rehash
log_group

View File

@@ -0,0 +1,62 @@
autoload -Uz log_debug log_error log_info log_status log_group log_output
local -r _usage="Usage: %B${0}%b <source> <volume name> <output_name>
Create macOS disk image <volume name> <output_name> with contents of <source>"
if (( ! # )) {
log_error 'Called without arguments.'
log_output ${_usage}
return 2
}
local source=${1}
local volume_name=${2}
local output_name=${3}
log_group "Create macOS disk image"
local _hdiutil_flags
if (( _loglevel < 1 )) _hdiutil_flags='-quiet'
trap "hdiutil detach ${_hdiutil_flags} /Volumes/${output_name}; rm temp.dmg; log_group return 2" ERR
hdiutil create ${_hdiutil_flags} \
-volname "${volume_name}" \
-srcfolder ${source} \
-ov \
-fs APFS \
-format UDRW \
temp.dmg
hdiutil attach ${_hdiutil_flags} \
-noverify \
-readwrite \
-mountpoint /Volumes/${output_name} \
temp.dmg
log_info "Waiting 2 seconds to ensure mounted volume is available..."
sleep 2
log_status "Done"
log_info "Setting up disk volume..."
log_status "Volume icon"
SetFile -c icnC /Volumes/${output_name}/.VolumeIcon.icns
log_status "Icon positions"
osascript package.applescript ${output_name}
log_status "File permissions"
chmod -Rf go-w /Volumes/${output_name}
SetFile -a C /Volumes/${output_name}
rm -rf -- /Volumes/${output_name}/.fseventsd(N)
log_info "Converting disk image..."
hdiutil detach ${_hdiutil_flags} /Volumes/${output_name}
hdiutil convert ${_hdiutil_flags} \
-format ULMO \
-ov \
-o ${output_name}.dmg temp.dmg
rm temp.dmg
trap '' ERR
log_group
return 0

3
.github/scripts/utils.zsh/log_debug vendored Normal file
View File

@@ -0,0 +1,3 @@
if (( ! ${+_loglevel} )) typeset -g _loglevel=1
if (( _loglevel > 2 )) print -PR -e "${CI:+::debug::}%F{220}DEBUG: ${@}%f"

3
.github/scripts/utils.zsh/log_error vendored Normal file
View File

@@ -0,0 +1,3 @@
local icon=' ✖︎ '
print -u2 -PR "${CI:+::error::}%F{1} ${icon} %f ${@}"

16
.github/scripts/utils.zsh/log_group vendored Normal file
View File

@@ -0,0 +1,16 @@
autoload -Uz log_info
if (( ! ${+_log_group} )) typeset -g _log_group=0
if (( ${+CI} )) {
if (( _log_group )) {
print "::endgroup::"
typeset -g _log_group=0
}
if (( # )) {
print "::group::${@}"
typeset -g _log_group=1
}
} else {
if (( # )) log_info ${@}
}

7
.github/scripts/utils.zsh/log_info vendored Normal file
View File

@@ -0,0 +1,7 @@
if (( ! ${+_loglevel} )) typeset -g _loglevel=1
if (( _loglevel > 0 )) {
local icon=' =>'
print -PR "%F{4} ${(r:5:)icon}%f %B${@}%b"
}

7
.github/scripts/utils.zsh/log_output vendored Normal file
View File

@@ -0,0 +1,7 @@
if (( ! ${+_loglevel} )) typeset -g _loglevel=1
if (( _loglevel > 0 )) {
local icon=''
print -PR " ${(r:5:)icon} ${@}"
}

7
.github/scripts/utils.zsh/log_status vendored Normal file
View File

@@ -0,0 +1,7 @@
if (( ! ${+_loglevel} )) typeset -g _loglevel=1
if (( _loglevel > 0 )) {
local icon=' >'
print -PR "%F{2} ${(r:5:)icon}%f ${@}"
}

7
.github/scripts/utils.zsh/log_warning vendored Normal file
View File

@@ -0,0 +1,7 @@
if (( ! ${+_loglevel} )) typeset -g _loglevel=1
if (( _loglevel > 0 )) {
local icon=' =>'
print -PR "${CI:+::warning::}%F{3} ${(r:5:)icon} ${@}%f"
}

1
.github/scripts/utils.zsh/mkcd vendored Normal file
View File

@@ -0,0 +1 @@
[[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1}

View File

@@ -0,0 +1,9 @@
autoload -Uz log_info
if (( ! ${+CODESIGN_IDENT} )) {
typeset -g CODESIGN_IDENT
log_info 'Setting up Apple Developer ID for application codesigning...'
read CODESIGN_IDENT'?Apple Developer Application ID: '
}
typeset -g CODESIGN_TEAM=$(print "${CODESIGN_IDENT}" | /usr/bin/sed -En 's/.+\((.+)\)/\1/p')

View File

@@ -0,0 +1,24 @@
autoload -Uz read_codesign read_codesign_user log_info log_warning
if (( ! ${+CODESIGN_IDENT} )) {
read_codesign
}
if (( ! ${+CODESIGN_IDENT_USER} )) {
read_codesign_user
}
log_info 'Setting up password for notarization keychain...'
if (( ! ${+CODESIGN_IDENT_PASS} )) {
read -s CODESIGN_IDENT_PASS'?Apple Developer ID password: '
}
print ''
log_info 'Setting up notarization keychain...'
log_warning "
+ Your Apple ID and an app-specific password is necessary for notarization from CLI
+ This password will be stored in your macOS keychain under the identifier
'OBS-Codesign-Password' with access Apple's 'altool' only.
"
xcrun notarytool store-credentials 'OBS-Codesign-Password' --apple-id "${CODESIGN_IDENT_USER}" --team-id "${CODESIGN_TEAM}" --password "${CODESIGN_IDENT_PASS}"

View File

@@ -0,0 +1,7 @@
autoload -Uz log_info
if (( ! ${+CODESIGN_TEAM} )) {
typeset -g CODESIGN_TEAM
log_info 'Setting up Apple Developer Team ID for codesigning...'
read CODESIGN_TEAM'?Apple Developer Team ID (leave empty to use Apple Developer ID instead): '
}

View File

@@ -0,0 +1,7 @@
autoload -Uz log_info
if (( ! ${+CODESIGN_IDENT_USER} )) {
typeset -g CODESIGN_IDENT_USER
log_info 'Setting up Apple ID for notarization...'
read CODESIGN_IDENT_USER'?Apple ID: '
}

View File

@@ -0,0 +1,7 @@
if (( _loglevel > 1 )) {
xcodebuild ${@}
} else {
local -a xcbeautify_opts=()
if (( _loglevel == 0 )) xcbeautify_opts+=(--quiet)
xcodebuild ${@} 2>&1 | xcbeautify ${xcbeautify_opts}
}

17
.github/scripts/utils.zsh/set_loglevel vendored Normal file
View File

@@ -0,0 +1,17 @@
autoload -Uz log_debug log_error log_output
local -r _usage="Usage: %B${0}%b <loglevel>
Set log level, following levels are supported: 0 (quiet), 1 (normal), 2 (verbose), 3 (debug)"
if (( ! # )); then
log_error 'Called without arguments.'
log_output ${_usage}
return 2
elif (( ${1} >= 4 )); then
log_error 'Called with loglevel > 3.'
log_output ${_usage}
fi
typeset -g -i -r _loglevel=${1}
log_debug "Log level set to '${1}'"

42
.github/scripts/utils.zsh/setup_ccache vendored Normal file
View File

@@ -0,0 +1,42 @@
autoload -Uz log_debug log_warning log_error
if (( ! ${+project_root} )) {
log_error "'project_root' not set. Please set before running ${0}."
return 2
}
if (( ${+commands[ccache]} )) {
log_debug "Found ccache at ${commands[ccache]}"
typeset -gx CCACHE_CONFIGPATH="${project_root}/.ccache.conf"
ccache --set-config=run_second_cpp=true
ccache --set-config=direct_mode=true
ccache --set-config=inode_cache=true
ccache --set-config=compiler_check=content
ccache --set-config=file_clone=true
local -a sloppiness=(
include_file_mtime
include_file_ctime
file_stat_matches
system_headers
)
if [[ ${host_os} == macos ]] {
sloppiness+=(
modules
clang_index_store
)
ccache --set-config=sloppiness=${(j:,:)sloppiness}
}
if (( ${+CI} )) {
ccache --set-config=cache_dir="${GITHUB_WORKSPACE:-${HOME}}/.ccache"
ccache --set-config=max_size="${CCACHE_SIZE:-1G}"
ccache -z > /dev/null
}
} else {
log_warning "No ccache found on the system"
}