Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
HardenedBSD-pkg .github workflows build.yaml
##
# Copyright (c) 2024 Keve Müller <kevemueller@users.github.com>
#
# SPDX-License-Identifier: BSD-2-Clause
#

# GitHub action to compile pkg on ubuntu-24.04, ubuntu-latest/22.04 (amd64) and macos-latest (aarch64)
#  * set-up prerequisites
#  * configure && make && make check && make install
#  * upload installed binaries if tests succeed as well as kyua reports and log as build artefact
#
# We run in a matrix with os/sanitize flags.

name: build

"on":
  pull_request:
    branches:
      - main
  push:

permissions:
  contents: read

jobs:
  build:
    name: build ${{ join(matrix.sanitize, '+') }} ${{ matrix.build-os }} ${{ matrix.compiler }}
    runs-on: "${{ matrix.build-os }}"
    strategy:
      fail-fast: false
      matrix:
        build-os:
          - ubuntu-24.04
          - macos-latest
        sanitize:
          - []
          - ["asan", "lsan"]
          - ["ubsan", "tsan"]
        include:
          - build-os: macos-latest
            compiler: clang-19
            pkgs:
              # - pkgconf comes preinstalled on the GitHub runner
              - libarchive
              - llvm@19
              - kyua
              - atf
            llvm-bindir: /opt/homebrew/opt/llvm@19/bin
          - build-os: ubuntu-24.04
            compiler: clang-18
            pkgs:
              - clang-18
              - libsqlite3-dev
              - libbsd-dev
              - libarchive-tools
              - libarchive-dev
              - libssl-dev
              - liblzma-dev
              - liblua5.2-dev
              - liblzo2-dev
              - libattr1-dev
              - libacl1-dev
              - libatf-dev
              - kyua
              - atf-sh
              - build-essential
              - zlib1g-dev
              - libbz2-dev
              - python3
              - pkg-config
              - m4
            llvm-bindir: /usr/lib/llvm-18/bin
        exclude:
          - build-os: macos-latest
            sanitize: ["asan", "lsan"]
    steps:
      - name: install packages (macOS)
        if: runner.os == 'macOS'
        run: |
          # on MacOS we build with
          #   * latest clang@19 from brew (system provided clang lacks sanitizers)
          #   * ld from system
          #   * libarchive from brew (system provided libarchive has no header files for development)
          #   * openssl from brew
          #

          brew update --quiet || true

          # temporarily use unstable atf to benefit from fix for std::vector
          # brew install --HEAD atf

          brew install ${{ join(matrix.pkgs, ' ') }}

          # We make sure pkg-config picks up brew's libarchive instead of pointing to system libarchive
          echo PKG_CONFIG_PATH=$(brew --prefix libarchive)/lib/pkgconfig >> "${GITHUB_ENV}"
      - name: install packages (Linux)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update --quiet || true
          sudo apt-get -yq --no-install-suggests --no-install-recommends install \
            ${{ join(matrix.pkgs, ' ') }}
      - uses: actions/checkout@v4
        with:
          path: src.pkg
      - name: setup environment
        run: |
          echo "CC=${{ matrix.llvm-bindir }}/clang" >> "${GITHUB_ENV}"
          echo "CXX=${{ matrix.llvm-bindir }}/clang++" >> "${GITHUB_ENV}"
          echo "CPP=${{ matrix.llvm-bindir }}/clang-cpp" >> "${GITHUB_ENV}"
          # this is miraculously not picked up by automake as the default
          echo "CC_FOR_BUILD=${{ matrix.llvm-bindir }}/clang" >> "${GITHUB_ENV}"
          echo "SRC_PKG=${GITHUB_WORKSPACE}/src.pkg" >> "${GITHUB_ENV}"
          echo "BUILD_PKG=${GITHUB_WORKSPACE}/build.pkg" >> "${GITHUB_ENV}"
          echo "INST_PKG=${GITHUB_WORKSPACE}/inst.pkg" >> "${GITHUB_ENV}"
          echo "NPROC=`getconf _NPROCESSORS_ONLN 2>/dev/null ||
            getconf NPROCESSORS_ONLN 2>/dev/null ||
            echo 1`" >> "${GITHUB_ENV}"

      - name: build pkg
        run: |
          CFG_OPTS=""
          for i in ${{ join(matrix.sanitize, ' ') }}; do
            CFG_OPTS="${CFG_OPTS} --with-${i}"
          done
          echo Building pkg with ${{ matrix.sanitize }} .. ${CFG_OPTS}
          echo uname -a: $(uname -a)
          echo uname -m: $(uname -m)
          echo uname -p: $(uname -p)
          kyua about | head -1
          echo NPROC="${NPROC}"
          echo CC="${CC}"
          echo CPP="${CPP}"
          echo PKG_CONFIG_PATH="${PKG_CONFIG_PATH}"
          echo SRC_PKG="${SRC_PKG}"
          echo BUILD_PKG="${BUILD_PKG}"
          echo INST_PKG="${INST_PKG}"

          mkdir -p "${BUILD_PKG}"
          cd "${BUILD_PKG}"
          ${SRC_PKG}/configure --prefix=${INST_PKG} --with-libarchive.pc \
            --with-openssl.pc ${CFG_OPTS}
          make -j${NPROC}

      - name: check pkg
        run: |
          set +e
          echo Checking pkg
          cd "${BUILD_PKG}"
          make check
          check_exit=$?

          if [ $check_exit -eq 0 ]; then
            echo "# ✅ All mandatory checks passed" >> $GITHUB_STEP_SUMMARY
            kyua report
          else
            echo "# ❌ Some checks failed" >> $GITHUB_STEP_SUMMARY
            LOCATION="file=.github/workflows/build.yaml,line=173,endLine=173"
            echo "::error ${LOCATION},title=Checks failed!::make check failed"
            kyua report --verbose
          fi

          kyua report --results-filter=xfail,broken,failed | sed 's/===>/##/' >> $GITHUB_STEP_SUMMARY
          if [ $check_exit -ne 0 ]; then
            kyua report --verbose --results-filter=xfail,broken,failed |
              sed 's/===>/##/' >> $GITHUB_STEP_SUMMARY
          fi

          kyua report-html # produces html subdirectory
          # also include plain text
          kyua report --verbose --results-filter=xfail,broken,failed > html/test-reportfailed.txt
          # also include plain JUnit
          kyua report-junit --output html/test-reportfailed.xml
          # also include the kyua log
          cp -a ~/.kyua/logs html/

          exit $check_exit

      - name: install pkg
        run: |
          cd "${BUILD_PKG}"
          make install
        # only install successful non-debug builds
        if: ${{ success() && '' == join(matrix.sanitize, '') }}

      - name: tar build & test reports
        run: |
          NAME="pkg-${{ matrix.build-os }}-${{ matrix.compiler }}"
          test -d ${INST_PKG} && tar cvf ${NAME}.tar -C ${INST_PKG} .
          tar cvf ${NAME}-report${{ join(matrix.sanitize, '_') }}.tar -C "${BUILD_PKG}/html" .
        if: ${{ always() }}

      - name: archive build artefacts
        uses: actions/upload-artifact@v4
        with:
          name: pkg-test${{ join(matrix.sanitize, '_') }}-${{ matrix.build-os }}-${{ matrix.compiler }}
          path: pkg*.tar
          compression-level: 0
          retention-days: 10
          overwrite: true
        if: ${{ always() }}