Published:

Jarle Aase

Build suddenly failed on Github Actions for MacOS

bookmark 1 min read

I have started to add some of my projects to Github Actions in stead of building everything locally with Jenkins. Github Actions is free for Open Source projects, and it's a convenient way for me to check that everything works on Linux, Windows and MacOS.

To guard against problems with newer versions of boost libraries or compilers I have configured Github Actions to rebuild my projects every month even if I don't update anything.

May first, all my projects failed building on MacOS. The problem seems to be that they have upgraded their runners from X64 to ARM64 hardware. I use an action, aminya/setup-cpp@v1 to install the the C++ compiler, CMake and Ninja before the build. It seems like it's broken for the runners Github Actions use for MacOS now.

The solution was do remove the compiler name from the matrix for MacOS, and add a new step where I simply use homebrew to install a recent llvm compiler.

This is the new workflow for one of the projects:

name: CI
on:
  push:
  pull_request:
  schedule:
    - cron: '0 0 1 * *' # This line schedules the workflow to run at 00:00 on the first day of every month
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            compiler: gcc
          - os: ubuntu-latest
            compiler: clang
          - os: windows-latest
            compiler: msvc
          - os: macos-latest
            compiler:

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          submodules: true

      - name: Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/vcpkg
            ./build/vcpkg_installed
            ${{ env.HOME }}/.cache/vcpkg/archives
            ${{ env.XDG_CACHE_HOME }}/vcpkg/archives
            ${{ env.LOCALAPPDATA }}\vcpkg\archives
            ${{ env.APPDATA }}\vcpkg\archives
          key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
          restore-keys: |
            ${{ runner.os }}-${{ env.BUILD_TYPE }}-

      - name: Setup Cpp
        uses: aminya/setup-cpp@v1
        with:
          compiler: ${{ matrix.compiler }}
          vcvarsall: ${{ contains(matrix.os, 'windows') }}
          cmake: true
          ninja: true
          vcpkg: true
          cppcheck: false

      - name: Install compiler for Macos
        if: startsWith(matrix.os, 'macos')
        run: |
          brew install llvm

      - name: Prepare the PATH
        run: |
            if [[ "${{ runner.os }}" == "Windows" ]]; then
                echo "$env:USERPROFILE\vcpkg" >> $GITHUB_PATH
                echo "$env:USERPROFILE\ninja" >> $GITHUB_PATH
            else
                echo "$HOME/vcpkg" >> $GITHUB_PATH
                echo "$HOME/ninja" >> $GITHUB_PATH
            fi
        shell: bash

      - name: Install dependencies
        run: |
          vcpkg install

      - name: Build project
        shell: bash
        run: |
          if [ -d build ]; then
            echo "Build dir exists"
            ls -la build
          else
            mkdir build
          fi
          pushd build
          cmake .. -DCMAKE_BUILD_TYPE=Release -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
          cmake --build .
          popd

      - name: Run Unit Tests
        run: |
          pushd build
          ctest -C Release
          popd
        shell: bash

This has a new step, Install compiler for Macos that works.