Skip to content

Add optional vcpkg bootstrapping for dependencies #194

Add optional vcpkg bootstrapping for dependencies

Add optional vcpkg bootstrapping for dependencies #194

Workflow file for this run

name: CMake
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
strategy:
matrix:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
build: [Release]
os: [ubuntu-latest, windows-latest]
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache vcpkg and packages
uses: actions/cache@v4
with:
path: |
external/vcpkg
build/vcpkg_installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
- name: Prep existing vcpkg installation
shell: bash
run: |
set -euo pipefail
BASELINE=$(jq -r '.["builtin-baseline"]' vcpkg.json)
echo "Detected vcpkg baseline: $BASELINE"
if [ -d "$GITHUB_WORKSPACE/external/vcpkg/.git" ]; then
echo "Using cached vcpkg at external/vcpkg"
VCPKG_DIR="$GITHUB_WORKSPACE/external/vcpkg"
elif [ -n "${VCPKG_ROOT:-}" ] && [ -d "$VCPKG_ROOT/.git" ]; then
echo "Using preinstalled vcpkg at $VCPKG_ROOT"
VCPKG_DIR="$VCPKG_ROOT"
else
echo "Performing minimal vcpkg clone..."
git clone --filter=blob:none --no-checkout https://github.com/microsoft/vcpkg.git external/vcpkg
VCPKG_DIR="$GITHUB_WORKSPACE/external/vcpkg"
fi
cd "$VCPKG_DIR"
if ! git cat-file -e "$BASELINE"^{commit} 2>/dev/null; then
echo "Fetching baseline commit $BASELINE..."
git fetch origin "$BASELINE" --depth=1 || git fetch --unshallow
fi
git checkout "$BASELINE"
if [ ! -f ./vcpkg ] && [ ! -f ./vcpkg.exe ]; then
if [[ "$RUNNER_OS" == "Windows" ]]; then
./bootstrap-vcpkg.bat
else
./bootstrap-vcpkg.sh
fi
fi
echo "vcpkg is now at commit: $(git rev-parse HEAD)"
echo "VCPKG_DIR=$VCPKG_DIR" >> "$GITHUB_ENV"
- name: Configure CMake (Windows)
if: ${{ (matrix.os == 'windows-latest') }}
shell: bash
run: |
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
# on Windows, we need to point CMake to the vcpkg-toolchain-file
cmake -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=${{matrix.build}} \
-DCMAKE_TOOLCHAIN_FILE="${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET=x64-windows-static \
-DCZICHECK_BUILD_TESTS=ON
- name: Configure CMake (Linux)
if: ${{ (matrix.os == 'ubuntu-latest') }}
shell: bash
run: |
cmake -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=${{matrix.build}} \
-DCMAKE_TOOLCHAIN_FILE="${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake" \
-DCZICHECK_BUILD_TESTS=ON
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build}}
- name: CTest
# Run tests
run: |
cd "${{github.workspace}}/build"
ctest -C ${{matrix.build}} --verbose
- name: Prepare licenses
if: matrix.build == 'Release'
shell: bash
run: |
cp -R ./THIRD_PARTY_LICENSES.txt ./build/CZICheck/
- name: Package
if: ${{ (matrix.os == 'ubuntu-latest') }}
shell: bash
run: |
mkdir release
name="CZICheck-linux-x64-$(git describe --always)"
mkdir "release/${name}"
cd ./build/CZICheck
cp "CZICheck" "./../../release/${name}/"
cp "THIRD_PARTY_LICENSES.txt" "./../../release/${name}/"
cd ../..
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=release/${name}" >> "$GITHUB_ENV"
- name: Package
if: ${{ (matrix.os == 'windows-latest') }}
shell: bash
run: |
mkdir release
name="CZICheck-windows-x64-$(git describe --always)"
mkdir "release/${name}"
cp ./build/CZICheck/${{ matrix.build }}/*.exe "release/${name}/"
cp ./build/CZICheck/THIRD_PARTY_LICENSES.txt "release/${name}/"
echo "artifactName=${name}" >> "$GITHUB_ENV"
echo "artifactPath=release/${name}" >> "$GITHUB_ENV"
- name: Upload artifacts
if: matrix.build == 'Release'
uses: actions/upload-artifact@v4
with:
path: ${{ env.artifactPath }}/
name: ${{ env.artifactName }}