name: CLI native builds and npm packages on: push: branches: ["**"] tags-ignore: ["cli-v*"] pull_request: workflow_dispatch: workflow_call: permissions: contents: read jobs: build: strategy: fail-fast: false matrix: include: - runner: macos-15 target: darwin-arm64 plat: macosx arch: arm64 - runner: macos-15-intel target: darwin-x64 plat: macosx arch: x86_64 - runner: ubuntu-22.04 target: linux-x64 plat: linux arch: x86_64 - runner: ubuntu-22.04-arm target: linux-arm64 plat: linux arch: arm64 - runner: windows-2022 target: win32-x64 plat: windows arch: x64 runs-on: ${{ matrix.runner }} timeout-minutes: 120 env: XMAKE_VERSION: "3.1.1" steps: - uses: actions/checkout@v5 with: submodules: recursive - uses: actions/setup-node@v6 with: node-version: 22 package-manager-cache: false # A runner label can receive compiler/SDK updates without changing its name. - name: Set cache environment id: runner-image shell: bash run: | printf 'version=%s\n' "${ImageVersion:?Missing GitHub runner image version}" >> "$GITHUB_OUTPUT" # Keep installed packages separate from the project's build/config state. printf 'XMAKE_PKG_INSTALLDIR=%s/crossdesk-cli-packages\n' "$RUNNER_TEMP" >> "$GITHUB_ENV" - uses: xmake-io/github-action-setup-xmake@v1 with: xmake-version: ${{ env.XMAKE_VERSION }} actions-cache-folder: ${{ runner.temp }}/crossdesk-cli-xmake-toolchain actions-cache-key: cli-${{ matrix.runner }}-${{ matrix.target }}-image${{ steps.runner-image.outputs.version }}-xmake${{ env.XMAKE_VERSION }} - name: Configure MSVC (x64) if: runner.os == 'Windows' shell: pwsh run: | $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' $vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath if ($LASTEXITCODE -ne 0 -or -not $vsPath) { throw 'Visual Studio C++ build tools were not found' } $previousEnv = @{} Get-ChildItem Env: | ForEach-Object { $previousEnv[$_.Name] = $_.Value } & (Join-Path $vsPath 'Common7\Tools\Launch-VsDevShell.ps1') -Arch amd64 -HostArch amd64 -SkipAutomaticLocation Get-Command cl.exe -ErrorAction Stop | Out-Null # Persist the compiler, SDK and PATH settings for subsequent steps. Get-ChildItem Env: | Where-Object { $previousEnv[$_.Name] -cne $_.Value } | ForEach-Object { "$($_.Name)=$($_.Value)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append } - name: Linux build tools if: runner.os == 'Linux' shell: bash run: | missing=() for package in build-essential pkg-config autoconf automake libtool nasm yasm zlib1g-dev python3-pip; do if [[ "$(dpkg-query -W -f='${Status}' "$package" 2>/dev/null || true)" != "install ok installed" ]]; then missing+=("$package") fi done if (( ${#missing[@]} )); then sudo apt-get update sudo apt-get install -y --no-install-recommends "${missing[@]}" fi - name: Prepare pinned dependency run: sh apps/cli/scripts/prepare-deps.sh - name: Read native dependency configuration id: dependency-config shell: bash run: xmake lua .github/scripts/cli-dependency-cache.lua "${{ matrix.plat }}" "${{ matrix.arch }}" "$RUNNER_TEMP/crossdesk-cli-config.lua" - name: Set native dependency cache key id: dependency-key shell: bash env: CACHE_PREFIX: cli-deps-v2-${{ matrix.runner }}-${{ matrix.target }}-image${{ steps.runner-image.outputs.version }}-xmake${{ env.XMAKE_VERSION }}-${{ steps.dependency-config.outputs.configuration }}-${{ hashFiles('deps/thirdparty/openssl/**', 'deps/submodules/minirtc/thirdparty/**') }} DEPENDENCY_HASH: ${{ steps.dependency-config.outputs.dependencies }} run: | printf 'prefix=%s-\n' "$CACHE_PREFIX" >> "$GITHUB_OUTPUT" printf 'key=%s-%s\n' "$CACHE_PREFIX" "$DEPENDENCY_HASH" >> "$GITHUB_OUTPUT" # Reuse installed packages across dependency declaration changes within the # same toolchain, build settings and local recipes/patches. - name: Restore native dependencies id: native-cache uses: actions/cache/restore@v5 with: path: ${{ env.XMAKE_PKG_INSTALLDIR }} key: ${{ steps.dependency-key.outputs.key }} restore-keys: ${{ steps.dependency-key.outputs.prefix }} - name: Configure native dependencies shell: bash run: xmake f -y --import="$RUNNER_TEMP/crossdesk-cli-config.lua" # xmake f installs required packages. Save before compiling or packaging the CLI, # so failures in those later steps do not discard successfully installed dependencies. - name: Save native dependencies if: steps.native-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v5 with: path: ${{ env.XMAKE_PKG_INSTALLDIR }} key: ${{ steps.native-cache.outputs.cache-primary-key }} - name: Build run: xmake build crossdesk-cli - name: Sign macOS CLI if: runner.os == 'macOS' run: codesign --force --sign - build/macosx/${{ matrix.arch }}/release/crossdesk-cli - name: Report native environment run: xmake run crossdesk-cli doctor --json - name: Package native program and npm entry run: npm --prefix apps/cli run pack:npm - uses: actions/upload-artifact@v6 with: name: npm-${{ matrix.target }} path: build/npm/*.tgz if-no-files-found: error