<commit_before>name: GitHub CI

on:
  push:
    branches: [master, ci, coverity_scan]
  pull_request:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    name: build(${{ matrix.msystem || matrix.docker_image || matrix.os }},
      ${{ matrix.cc }}${{ matrix.api && ', ' }}${{ matrix.api }})
    strategy:
      fail-fast: false
      matrix:
        include:
          # Enable distcheck for one build
          - os: ubuntu-latest
            cc: gcc
            do_distc: yes
          # Run Coverity on a clang build; Coverity's gcc causes issues
          - os: ubuntu-latest
            cc: clang
            do_coverity: yes
          # Add a tcc build
          - os: ubuntu-latest
            cc: tcc
            ld: tcc
          # Add docker-build on Alpine
          - os: ubuntu-latest
            cc: gcc
            docker_image: alpine:latest
            shell: '/usr/bin/docker exec dockerciimage sh -e {0}'
            art_reg_skip: 'font_nonunicode'
          # Add docker-build with minimum version of dependencies
          - os: ubuntu-latest
            cc: gcc
            docker_image: oldlibs
            docker_pullprefix: 'ghcr.io/theoneric/libass-containers/'
            shell: '/usr/bin/docker exec dockerciimage sh -e {0}'
            # Crash Tests detect (false?) leaks in Fontconfig, and
            # various regression test fail, assumed due to older deps
            skip_tests: yes
          # MacOS build
          - os: macos-latest
            cc: clang
          # Add a Windows build (MinGW-gcc via MSYS2) with no extras
          - os: windows-2019
            msystem: MINGW32
            cc: gcc
            api: desktop
            shell: 'msys2 {0}'
            package_prefix: mingw-w64-i686
          # Add a best-effort build for UWP apps for Microsoft Store
          - os: windows-2019
            msystem: UCRT64
            cc: gcc
            api: app
            extra_cflags: -DWINAPI_FAMILY=WINAPI_FAMILY_APP -specs=/tmp/windowsapp.specs
            shell: 'msys2 {0}'
            package_prefix: mingw-w64-ucrt-x86_64
            # FIXME: UBSAN triggers on regression/karaoke/357-k-and-kf-desynced.ass
            skip_tests: yes

    defaults:
      run:
        shell: ${{ matrix.shell || 'bash' }}

    env:
      ART_SAMPLES: ext_art-samples

    steps:
      - name: checkout code
        uses: actions/checkout@v3

      - name: download test samples
        uses: actions/checkout@v3
        with:
          repository: libass/libass-tests
          path: ${{ env.ART_SAMPLES }}

      - name: Start Docker
        if: matrix.docker_image
        shell: bash
        run: |
          # Note: Many containers default to the root user
          docker pull "${{ matrix.docker_pullprefix }}${{ matrix.docker_image }}"
          docker create --name dockerciimage \
            -v "/home/runner/work:/home/runner/work" --workdir "$PWD"  \
            --entrypoint "tail" \
            "${{ matrix.docker_pullprefix }}${{ matrix.docker_image }}" \
            "-f" "/dev/null"
          docker start dockerciimage

      - name: Setup MSys2
        uses: msys2/setup-msys2@v2
        if: matrix.msystem
        with:
          msystem: ${{ matrix.msystem }}
          update: false

      - name: install deps
        run: |
          case "${{ matrix.docker_image || matrix.os }}" in
            macos-*)
              #brew update
              # fontconfig, freetype, autoconf and libtool are preinstalled
              # and `brew install` fails if a non-uptodate version is already installed
              #brew upgrade fontconfig freetype autoconf libtool
              brew install automake fribidi harfbuzz nasm
              ;;
            windows-*)
              pre="${{ matrix.package_prefix }}"
              pacman --noconfirm -S \
                      automake autoconf libtool nasm make \
                      $pre-pkg-config $pre-gcc \
                      $pre-fribidi $pre-freetype $pre-harfbuzz $pre-fontconfig \
                      $pre-libpng
              ;;
            alpine:*)
              apk add nasm ${{ matrix.cc }} musl-dev \
                      make automake autoconf libtool pkgconf \
                      fontconfig-dev freetype-dev fribidi-dev harfbuzz-dev \
                      libpng-dev
              ;;
            oldlibs)
              : # Everything is preinstalled
              ;;
            *)
              sudo apt-get update #&& sudo apt-get upgrade
              ubver="$(apt-cache search libubsan | awk '/^libubsan[0-9]* / {print substr($1, 9)}' | sort -rn | head -n1)"
              asver="$(apt-cache search libasan | awk '/^libasan[0-9]* / {print substr($1, 8)}' | sort -rn | head -n1)"
              sudo apt-get install -y --no-install-recommends \
                   autoconf automake make libtool \
                   libfontconfig1-dev libfreetype6-dev libfribidi-dev \
                   libharfbuzz-dev nasm ${{ matrix.cc }} \
                   libpng-dev libubsan"$ubver" libasan"$asver"
              ;;
          esac

      - name: Determine Sanitizer Flags
        id: sanitizer
        run: |
          aflags="-fsanitize=address"
          uflags="-fsanitize=undefined -fsanitize=float-cast-overflow"
          if [ "${{ startsWith(matrix.cc, 'clang') }}" = "true" ] ; then
            # Clang's UBSAN exits with code zero even if issues were found
            # This options will instead force an SIGILL, but remove a report being printed
            # see https://reviews.llvm.org/D35085
            uflags="$uflags -fsanitize-undefined-trap-on-error"
          fi

          # UBSAN: Alpine and MSys2 doesn't ship the UBSAN library,
          #        but when SIGILL'ing the lib is not needed
          # ASAN:  Not supported with musl and in Windows
          case "${{ matrix.docker_image || matrix.os }}" in
            alpine*|windows-*)
              flags="$uflags -fsanitize-undefined-trap-on-error" ;;
            *)
              flags="$aflags $uflags" ;;
          esac

          if [ -n "$flags" ] ; then
            flags="$flags -fno-sanitize-recover=all"
          fi

          if [ "${{ matrix.cc }}" = "tcc" ] || [ "${{ matrix.skip_tests }}" = "yes" ] ; then
            flags=""
          fi

          echo "SANFLAGS=$flags"
          echo "::set-output name=flags::${flags}"

      - name: Customize compiler
        if: matrix.api == 'app' && matrix.cc == 'gcc'
        run: >
          gcc -dumpspecs
          | sed 's/-lmsvcrt/-lucrtapp/g; s/-lkernel32/-lwindowsapp/g;<commit_msg>ci/gha: disable only sanitisers on UWP<commit_after>name: GitHub CI

on:
  push:
    branches: [master, ci, coverity_scan]
  pull_request:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    name: build(${{ matrix.msystem || matrix.docker_image || matrix.os }},
      ${{ matrix.cc }}${{ matrix.api && ', ' }}${{ matrix.api }})
    strategy:
      fail-fast: false
      matrix:
        include:
          # Enable distcheck for one build
          - os: ubuntu-latest
            cc: gcc
            do_distc: yes
          # Run Coverity on a clang build; Coverity's gcc causes issues
          - os: ubuntu-latest
            cc: clang
            do_coverity: yes
          # Add a tcc build
          - os: ubuntu-latest
            cc: tcc
            ld: tcc
          # Add docker-build on Alpine
          - os: ubuntu-latest
            cc: gcc
            docker_image: alpine:latest
            shell: '/usr/bin/docker exec dockerciimage sh -e {0}'
            art_reg_skip: 'font_nonunicode'
          # Add docker-build with minimum version of dependencies
          - os: ubuntu-latest
            cc: gcc
            docker_image: oldlibs
            docker_pullprefix: 'ghcr.io/theoneric/libass-containers/'
            shell: '/usr/bin/docker exec dockerciimage sh -e {0}'
            # Crash Tests detect (false?) leaks in Fontconfig, and
            # various regression test fail, assumed due to older deps
            skip_tests: yes
          # MacOS build
          - os: macos-latest
            cc: clang
          # Add a Windows build (MinGW-gcc via MSYS2) with no extras
          - os: windows-2019
            msystem: MINGW32
            cc: gcc
            api: desktop
            shell: 'msys2 {0}'
            package_prefix: mingw-w64-i686
          # Add a best-effort build for UWP apps for Microsoft Store
          - os: windows-2019
            msystem: UCRT64
            cc: gcc
            api: app
            extra_cflags: -DWINAPI_FAMILY=WINAPI_FAMILY_APP -specs=/tmp/windowsapp.specs
            shell: 'msys2 {0}'
            package_prefix: mingw-w64-ucrt-x86_64

    defaults:
      run:
        shell: ${{ matrix.shell || 'bash' }}

    env:
      ART_SAMPLES: ext_art-samples

    steps:
      - name: checkout code
        uses: actions/checkout@v3

      - name: download test samples
        uses: actions/checkout@v3
        with:
          repository: libass/libass-tests
          path: ${{ env.ART_SAMPLES }}

      - name: Start Docker
        if: matrix.docker_image
        shell: bash
        run: |
          # Note: Many containers default to the root user
          docker pull "${{ matrix.docker_pullprefix }}${{ matrix.docker_image }}"
          docker create --name dockerciimage \
            -v "/home/runner/work:/home/runner/work" --workdir "$PWD"  \
            --entrypoint "tail" \
            "${{ matrix.docker_pullprefix }}${{ matrix.docker_image }}" \
            "-f" "/dev/null"
          docker start dockerciimage

      - name: Setup MSys2
        uses: msys2/setup-msys2@v2
        if: matrix.msystem
        with:
          msystem: ${{ matrix.msystem }}
          update: false

      - name: install deps
        run: |
          case "${{ matrix.docker_image || matrix.os }}" in
            macos-*)
              #brew update
              # fontconfig, freetype, autoconf and libtool are preinstalled
              # and `brew install` fails if a non-uptodate version is already installed
              #brew upgrade fontconfig freetype autoconf libtool
              brew install automake fribidi harfbuzz nasm
              ;;
            windows-*)
              pre="${{ matrix.package_prefix }}"
              pacman --noconfirm -S \
                      automake autoconf libtool nasm make \
                      $pre-pkg-config $pre-gcc \
                      $pre-fribidi $pre-freetype $pre-harfbuzz $pre-fontconfig \
                      $pre-libpng
              ;;
            alpine:*)
              apk add nasm ${{ matrix.cc }} musl-dev \
                      make automake autoconf libtool pkgconf \
                      fontconfig-dev freetype-dev fribidi-dev harfbuzz-dev \
                      libpng-dev
              ;;
            oldlibs)
              : # Everything is preinstalled
              ;;
            *)
              sudo apt-get update #&& sudo apt-get upgrade
              ubver="$(apt-cache search libubsan | awk '/^libubsan[0-9]* / {print substr($1, 9)}' | sort -rn | head -n1)"
              asver="$(apt-cache search libasan | awk '/^libasan[0-9]* / {print substr($1, 8)}' | sort -rn | head -n1)"
              sudo apt-get install -y --no-install-recommends \
                   autoconf automake make libtool \
                   libfontconfig1-dev libfreetype6-dev libfribidi-dev \
                   libharfbuzz-dev nasm ${{ matrix.cc }} \
                   libpng-dev libubsan"$ubver" libasan"$asver"
              ;;
          esac

      - name: Determine Sanitizer Flags
        id: sanitizer
        run: |
          aflags="-fsanitize=address"
          uflags="-fsanitize=undefined -fsanitize=float-cast-overflow"
          if [ "${{ startsWith(matrix.cc, 'clang') }}" = "true" ] ; then
            # Clang's UBSAN exits with code zero even if issues were found
            # This options will instead force an SIGILL, but remove a report being printed
            # see https://reviews.llvm.org/D35085
            uflags="$uflags -fsanitize-undefined-trap-on-error"
          fi

          # UBSAN: Alpine and MSys2 doesn't ship the UBSAN library,
          #        but when SIGILL'ing the lib is not needed
          # ASAN:  Not supported with musl and in Windows
          case "${{ matrix.docker_image || matrix.os }}" in
            alpine*|windows-*)
              flags="$uflags -fsanitize-undefined-trap-on-error" ;;
            *)
              flags="$aflags $uflags" ;;
          esac

          if [ -n "$flags" ] ; then
            flags="$flags -fno-sanitize-recover=all"
          fi

          if [ "${{ matrix.cc }}" = "tcc" ] || [ "${{ matrix.skip_tests }}" = "yes" ] \
             || [ "${{ matrix.api }}" = "app" ] ; then
            # FIXME: For Windows UWP, UBSAN triggers on regression/karaoke/357-k-and-kf-desynced.ass
            flags=""
          fi

          echo "SANFLAGS=$flags"
          echo "::set-output name=flags::${flags}"

      - name: Customize compiler
        if: matrix.api == 'app' && matrix.cc == 'gcc'
        run: >
          gcc -dumpspecs
          | sed 's/-lmsvcrt/-lucrtapp/g; s/-lkernel32/-lwindowsapp/g;
{'fraction_non_alphanumeric': 0.10709403007747227, 'fraction_numerical': 0.008962479112866474, 'mean_word_length': 1.507044935262757, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480246', 'n_tokens_mistral': 4072, 'n_tokens_neox': 3802, 'n_words': 1009}