Skip to content

Commit

Permalink
ci: update obs-plugintemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzniewski committed Dec 29, 2022
1 parent ae4d716 commit 68ae946
Show file tree
Hide file tree
Showing 25 changed files with 1,123 additions and 1,626 deletions.
22 changes: 12 additions & 10 deletions .cmake-format.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"additional_commands": {
"find_qt": {
"flags": [],
"kwargs": {
"VERSION": "+",
"COMPONENTS": "+",
"COMPONENTS_WIN": "+",
"COMPONENTS_MACOS": "+",
"COMPONENTS_LINUX": "+"
}
"additional_commands": {
"find_qt": {
"flags": [],
"kwargs": {
"COMPONENTS": "+",
"COMPONENTS_WIN": "+",
"COMPONENTS_MACOS": "+",
"COMPONENTS_LINUX": "+"
}
}
},
"format": {
"line_width": 100
}
}
149 changes: 104 additions & 45 deletions .github/scripts/.build.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ setopt NO_PUSHD_IGNORE_DUPS
setopt FUNCTION_ARGZERO

## Enable for script debugging
#setopt WARN_CREATE_GLOBAL
#setopt WARN_NESTED_VAR
#setopt XTRACE
# setopt WARN_CREATE_GLOBAL
# setopt WARN_NESTED_VAR
# setopt XTRACE

autoload -Uz is-at-least && if ! is-at-least 5.2; then
print -u2 -PR "%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue."
Expand All @@ -36,20 +36,37 @@ build() {
local target="${host_os}-${CPUTYPE}"
local project_root=${SCRIPT_HOME:A:h:h}
local buildspec_file="${project_root}/buildspec.json"

trap '_trap_error' ZERR

fpath=("${SCRIPT_HOME}/utils.zsh" ${fpath})
autoload -Uz log_info log_error log_output set_loglevel check_${host_os} setup_${host_os} setup_obs setup_ccache

if [[ ! -r ${buildspec_file} ]] {
log_error \
'No buildspec.json found. Please create a build specification for your project.' \
'A buildspec.json.template file is provided in the repository to get you started.'
return 2
}

typeset -g -a skips=()
local -i _verbosity=1
local -r _version='0.0.1'
local -r _version='1.0.0'
local -r -a _valid_targets=(
macos-x86_64
macos-arm64
macos-universal
linux-x86_64
linux-aarch64
)
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
if [[ ${host_os} == 'macos' ]] {
local -r -a _valid_generators=(Xcode Ninja 'Unix Makefiles')
local generator="${${CI:+Ninja}:-Xcode}"
} else {
local -r -a _valid_generators=(Ninja 'Unix Makefiles')
local generator='Ninja'
}
local -r _usage="
Usage: %B${functrace[1]%:*}%b <option> [<options>]
Expand All @@ -60,11 +77,18 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
%B-t | --target%b Specify target - default: %B%F{green}${host_os}-${CPUTYPE}%f%b
%B-c | --config%b Build configuration - default: %B%F{green}RelWithDebInfo%f%b
%B-s | --codesign%b Enable codesigning (macOS only)
%B--generator%b Specify build system to generate - default: %B%F{green}Ninja%f%b
Available generators:
- Ninja
- Unix Makefiles
- Xcode (macOS only)
%F{yellow} Output options%f
-----------------------------------------------------------------------------
%B-q | --quiet%b Quiet (error output only)
%B-v | --verbose%b Verbose (more detailed output)
%B--skip-[all|build|deps|unpack]%b Skip all|building OBS|checking for dependencies|unpacking dependencies
%B--debug%b Debug (very detailed and added output)
%F{yellow} General options%f
-----------------------------------------------------------------------------
Expand All @@ -74,7 +98,7 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
local -a args
while (( # )) {
case ${1} {
-t|--target|-c|--config)
-t|--target|-c|--config|--generator)
if (( # == 1 )) || [[ ${2:0:1} == '-' ]] {
log_error "Missing value for option %B${1}%b"
log_output ${_usage}
Expand Down Expand Up @@ -112,6 +136,22 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
-h|--help) log_output ${_usage}; exit 0 ;;
-V|--version) print -Pr "${_version}"; exit 0 ;;
--debug) _verbosity=3; shift ;;
--generator)
if (( ! ${_valid_generators[(Ie)${2}]} )) {
log_error "Invalid value %B${2}%b for option %B${1}%b"
log_output ${_usage}
exit 2
}
generator=${2}
shift 2
;;
--skip-*)
local _skip="${${(s:-:)1}[-1]}"
local _check=(all deps unpack build)
(( ${_check[(Ie)${_skip}]} )) || log_warning "Invalid skip mode %B${_skip}%b supplied"
typeset -g -a skips=(${skips} ${_skip})
shift
;;
*) log_error "Unknown option: %B${1}%b"; log_output ${_usage}; exit 2 ;;
}
}
Expand All @@ -120,68 +160,87 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
set_loglevel ${_verbosity}

check_${host_os}
setup_ccache

typeset -g QT_VERSION
typeset -g DEPLOYMENT_TARGET
typeset -g OBS_DEPS_VERSION
setup_${host_os}

local product_name
local product_version
read -r product_name product_version <<< \
"$(jq -r '. | {name, version} | join(" ")' ${project_root}/buildspec.json)"
"$(jq -r '. | {name, version} | join(" ")' ${buildspec_file})"
case ${host_os} {
macos-*)
macos)
sed -i '' \
"s/project(\(.*\) VERSION \(.*\))/project(${product_name} VERSION ${product_version})/" \
"${project_root}"/CMakeLists.txt
"${project_root}/CMakeLists.txt"
;;
linux-*)
linux)
sed -i'' \
"s/project(\(.*\) VERSION \(.*\))/project(${product_name} VERSION ${product_version})/"\
"${project_root}"/CMakeLists.txt
"${project_root}/CMakeLists.txt"
;;
}
setup_ccache
setup_obs
pushd ${project_root}
log_info "Configuring ${product_name}..."
if (( ! (${skips[(Ie)all]} + ${skips[(Ie)build]}) )) {
log_info "Configuring ${product_name}..."
local _plugin_deps="${project_root:h}/obs-build-dependencies/plugin-deps-${OBS_DEPS_VERSION}-qt${QT_VERSION}-${target##*-}"
local -a cmake_args=(
-DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-RelWithDebInfo}
-DQT_VERSION=${QT_VERSION}
-DCMAKE_PREFIX_PATH="${_plugin_deps}"
)
if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
if (( _loglevel > 2 )) cmake_args+=(--debug-output)
local num_procs
case ${target} {
macos-*)
autoload -Uz read_codesign
if (( ${+CODESIGN} )) {
read_codesign
}
local -a cmake_args=(
-DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-RelWithDebInfo}
-DCMAKE_PREFIX_PATH="${project_root:h}/obs-build-dependencies/obs-plugin-deps"
)
cmake_args+=(
-DCMAKE_FRAMEWORK_PATH="${_plugin_deps}/Frameworks"
-DCMAKE_OSX_ARCHITECTURES=${${target##*-}//universal/x86_64;arm64}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET:-10.15}
-DOBS_CODESIGN_LINKER=ON
-DOBS_BUNDLE_CODESIGN_IDENTITY="${CODESIGN_IDENT:--}"
)
num_procs=$(( $(sysctl -n hw.ncpu) + 1 ))
;;
linux-*)
if (( ${+CI} )) {
cmake_args+=(-DCMAKE_INSTALL_PREFIX=/usr -DLINUX_PORTABLE=OFF)
}
num_procs=$(( $(nproc) + 1 ))
;;
}
if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
case ${target} {
macos-*)
autoload -Uz read_codesign
if (( ${+CODESIGN} )) {
read_codesign
}
cmake_args+=(
-DCMAKE_OSX_ARCHITECTURES=${${target##*-}//universal/x86_64;arm64}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-10.15}
-DOBS_BUNDLE_CODESIGN_IDENTITY="${CODESIGN_IDENT:--}"
-DCMAKE_FRAMEWORK_PATH="${project_root:h}/obs-build-dependencies/obs-plugin-deps/Frameworks"
)
;;
linux-*)
if (( ${+CI} )) {
cmake_args+=(-DCMAKE_INSTALL_PREFIX=/usr)
}
;;
}
log_debug "Attempting to configure ${product_name} with CMake arguments: ${cmake_args}"
cmake -S . -B build_${target##*-} -G ${generator} ${cmake_args}
cmake -S . -B build_${target} -G Ninja ${cmake_args}
log_info "Building ${product_name}..."
local -a cmake_args=()
if (( _loglevel > 1 )) cmake_args+=(--verbose)
if [[ ${generator} == 'Unix Makefiles' ]] cmake_args+=(--parallel ${num_procs})
cmake --build build_${target##*-} --config ${BUILD_CONFIG:-RelWithDebInfo} ${cmake_args}
}
log_info "Installing ${product_name}..."
local -a cmake_args=()
if (( _loglevel > 1 )) cmake_args+=(--verbose)
log_info "Building ${product_name}"
cmake --build build_${target} --config ${BUILD_CONFIG:-RelWithDebInfo} ${cmake_args}
log_info "Install ${product_name}"
cmake --install build_${target} --config ${BUILD_CONFIG:-RelWithDebInfo} --prefix "${project_root}"/release ${cmake_args}
cmake --install build_${target##*-} --config ${BUILD_CONFIG:-RelWithDebInfo} --prefix "${project_root}/release" ${cmake_args}
popd
}
Expand Down
44 changes: 20 additions & 24 deletions .github/scripts/.package.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ setopt NO_PUSHD_IGNORE_DUPS
setopt FUNCTION_ARGZERO

## Enable for script debugging
#setopt WARN_CREATE_GLOBAL
#setopt WARN_NESTED_VAR
#setopt XTRACE
# setopt WARN_CREATE_GLOBAL
# setopt WARN_NESTED_VAR
# setopt XTRACE

autoload -Uz is-at-least && if ! is-at-least 5.2; then
print -u2 -PR "%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue."
Expand Down Expand Up @@ -42,12 +42,13 @@ package() {
autoload -Uz set_loglevel log_info log_error log_output check_${host_os}

local -i _verbosity=1
local -r _version='0.0.1'
local -r _version='1.0.0'
local -r -a _valid_targets=(
macos-x86_64
macos-arm64
macos-universal
linux-x86_64
linux-aarch64
)
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
local -r _usage="
Expand All @@ -66,6 +67,7 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
-----------------------------------------------------------------------------
%B-q | --quiet%b Quiet (error output only)
%B-v | --verbose%b Verbose (more detailed output)
%B--debug%b Debug (very detailed and added output)
%F{yellow} General options%f
-----------------------------------------------------------------------------
Expand Down Expand Up @@ -107,8 +109,8 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
BUILD_CONFIG=${2}
shift 2
;;
-s|--codesign) CODESIGN=1; shift ;;
-n|--notarize) NOTARIZE=1; shift ;;
-s|--codesign) typeset -g CODESIGN=1; shift ;;
-n|--notarize) typeset -g NOTARIZE=1; typeset -g CODESIGN=1; shift ;;
-q|--quiet) (( _verbosity -= 1 )) || true; shift ;;
-v|--verbose) (( _verbosity += 1 )); shift ;;
-h|--help) log_output ${_usage}; exit 0 ;;
Expand All @@ -123,11 +125,13 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]

check_${host_os}

local product_name
local product_version
read -r product_name product_version <<< \
"$(jq -r '. | {name, version} | join(" ")' ${project_root}/buildspec.json)"
if [[ ${host_os} == 'macos' ]] {
autoload -Uz check_packages check_xcnotary read_codesign read_codesign_installer read_codesign_pass
autoload -Uz check_packages read_codesign read_codesign_installer read_codesign_pass
local output_name="${product_name}-${product_version}-${host_os}-${target##*-}.pkg"
Expand All @@ -136,7 +140,7 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
return 2
}
if [[ ! -f ${project_root}/build_${target}/installer-macos.generated.pkgproj ]] {
if [[ ! -f ${project_root}/build_${target##*-}/installer-macos.generated.pkgproj ]] {
log_error 'Packages project file not found. Run the build script or the CMake build and install procedures first.'
return 2
}
Expand All @@ -147,7 +151,7 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
pushd ${project_root}
packagesbuild \
--build-folder ${project_root}/release \
${project_root}/build_${target}/installer-macos.generated.pkgproj
${project_root}/build_${target##*-}/installer-macos.generated.pkgproj
if (( ${+CODESIGN} )) {
read_codesign_installer
Expand All @@ -163,33 +167,25 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
}
if (( ${+CODESIGN} && ${+NOTARIZE} )) {
check_xcnotary
local _error=0
if [[ -f "${project_root}/release/${output_name}" ]] {
xcnotary precheck "${project_root}/release/${output_name}" || _error=1
} else {
if [[ ! -f "${project_root}/release/${output_name}" ]] {
log_error "No package for notarization found."
return 2
}
if (( ! _error )) {
read_codesign_installer
read_codesign_pass
read_codesign_installer
read_codesign_pass
xcnotary notarize "${project_root}/release/${output_name}" \
--developer-account "${CODESIGN_IDENT_USER}" \
--developer-password-keychain-item "OBS-Codesign-Password" \
--provider "${CODESIGN_IDENT_SHORT}"
}
xcrun notarytool submit "${project_root}/release/${output_name}" \
--keychain-profile "OBS-Codesign-Password" --wait
xcrun stapler staple "${project_root}/release/${output_name}"
}
popd
} elif [[ ${host_os} == 'linux' ]] {
local -a cmake_args=()
if (( _loglevel > 1 )) cmake_args+=(--verbose)
pushd ${project_root}
cmake --build build_${target} --config ${BUILD_CONFIG:-RelWithDebInfo} -t package ${cmake_args}
cmake --build build_${target##*-} --config ${BUILD_CONFIG:-RelWithDebInfo} -t package ${cmake_args}
popd
}
}
Expand Down
Loading

0 comments on commit 68ae946

Please sign in to comment.