From bbb9c7ad0c8b378a1d13ef5e7325472310d794c0 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Fri, 8 Sep 2023 23:29:57 +0200 Subject: [PATCH] CI: Separate dependency build from plugin build * Goal is to enable caching of dependency builds to speed up CI build times significantly * Should ease transition to new plugin build template version --- .github/actions/build-dependencies/action.yml | 78 +++++ .github/actions/build-plugin/action.yml | 2 +- .github/scripts/.build-deps.zsh | 288 ++++++++++++++++++ .github/scripts/.build.zsh | 107 +------ .github/scripts/Build-Deps-Windows.ps1 | 172 +++++++++++ .github/scripts/Build-Windows.ps1 | 114 +------ .github/scripts/build-deps-linux.sh | 13 + .github/scripts/build-deps-linux.zsh | 1 + .github/scripts/build-deps-macos.zsh | 1 + .github/workflows/main.yml | 15 +- 10 files changed, 587 insertions(+), 204 deletions(-) create mode 100644 .github/actions/build-dependencies/action.yml create mode 100755 .github/scripts/.build-deps.zsh create mode 100644 .github/scripts/Build-Deps-Windows.ps1 create mode 100755 .github/scripts/build-deps-linux.sh create mode 120000 .github/scripts/build-deps-linux.zsh create mode 120000 .github/scripts/build-deps-macos.zsh diff --git a/.github/actions/build-dependencies/action.yml b/.github/actions/build-dependencies/action.yml new file mode 100644 index 000000000..9f2a6c837 --- /dev/null +++ b/.github/actions/build-dependencies/action.yml @@ -0,0 +1,78 @@ +name: 'Setup plugin build dependencies' +description: 'Builds the plugin build dependencies' +inputs: + target: + description: 'Build target for dependencies' + required: true + config: + description: 'Build configuration' + required: false + default: 'Release' + visualStudio: + description: 'Visual Studio version (Windows only)' + required: false + default: 'Visual Studio 16 2019' + workingDirectory: + description: 'Working directory for packaging' + required: false + default: ${{ github.workspace }} +runs: + using: 'composite' + steps: + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.13 + with: + cmake-version: '3.24.x' + - name: Run macOS Build + if: ${{ runner.os == 'macOS' }} + shell: zsh {0} + run: | + build_args=( + -c ${{ inputs.config }} + -t macos-${{ inputs.target }} + ) + + if (( ${+CI} && ${+RUNNER_DEBUG} )) build_args+=(--debug) + + ${{ inputs.workingDirectory }}/.github/scripts/build-deps-macos.zsh -o ${{ env.DEP_DIR }} ${build_args} + + - name: Run Linux Build + if: ${{ runner.os == 'Linux' }} + shell: bash + run: | + build_args=( + -c ${{ inputs.config }} + -t linux-${{ inputs.target }} + ) + + if [[ -n "${CI}" && -n "${RUNNER_DEBUG}" ]]; then + build_args+=(--debug) + fi + + ${{ inputs.workingDirectory }}/.github/scripts/build-deps-linux.sh -o ${{ env.DEP_DIR }} "${build_args[@]}" + + - name: Restore cached dependencies + id: restore-cache + uses: actions/cache@v3 + with: + path: ${{ env.DEP_DIR }} + key: ${{ env.DEP_DIR }}-${{ runner.os }} + + - name: Run Windows Build + if: ${{ runner.os == 'Windows' && steps.restore-cache.outputs.cache-hit != 'true' }} + shell: pwsh + run: | + $BuildArgs = @{ + Target = '${{ inputs.target }}' + Configuration = '${{ inputs.config }}' + CMakeGenerator = '${{ inputs.visualStudio }}' + } + + if ( ( Test-Path env:CI ) -and ( Test-Path env:RUNNER_DEBUG ) ) { + $BuildArgs += @{ + Debug = $true + } + } + + ${{ inputs.workingDirectory }}/.github/scripts/Build-Deps-Windows.ps1 -OutDirName ${{ env.DEP_DIR }} @BuildArgs + diff --git a/.github/actions/build-plugin/action.yml b/.github/actions/build-plugin/action.yml index 9d4643a5b..d44ea9f9f 100644 --- a/.github/actions/build-plugin/action.yml +++ b/.github/actions/build-plugin/action.yml @@ -86,4 +86,4 @@ runs: } } - ${{ inputs.workingDirectory }}/.github/scripts/Build-Windows.ps1 @BuildArgs + ${{ inputs.workingDirectory }}/.github/scripts/Build-Windows.ps1 -ADVSSDepName ${{ env.DEP_DIR }} @BuildArgs diff --git a/.github/scripts/.build-deps.zsh b/.github/scripts/.build-deps.zsh new file mode 100755 index 000000000..ad9bb2ca5 --- /dev/null +++ b/.github/scripts/.build-deps.zsh @@ -0,0 +1,288 @@ +#!/usr/bin/env zsh + +builtin emulate -L zsh +setopt EXTENDED_GLOB +setopt PUSHD_SILENT +setopt ERR_EXIT +setopt ERR_RETURN +setopt NO_UNSET +setopt PIPE_FAIL +setopt NO_AUTO_PUSHD +setopt NO_PUSHD_IGNORE_DUPS +setopt FUNCTION_ARGZERO + +## Enable for script debugging +# 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." + exit 1 +fi + +_trap_error() { + print -u2 -PR '%F{1} ✖︎ script execution error%f' + print -PR -e " + Callstack: + ${(j:\n :)funcfiletrace} + " + exit 2 +} + +build() { + if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h} + local host_os=${${(s:-:)ZSH_ARGZERO:t:r}[3]} + 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='1.0.0' + local -r -a _valid_targets=( + macos-x86_64 + macos-arm64 + macos-universal + linux-x86_64 + ) + 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