<commit_before>name: CI Test for GEF

on:
  push:
    branches:
      - main
      - dev

  pull_request:
    branches:
      - main
      - dev

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-22.04
          - ubuntu-20.04
    name: "Run Unit tests on ${{ matrix.os }}"
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash

    steps:
    - uses: actions/checkout@v3

    - name: Install python and toolchain
      run: |
        sudo apt-get update
        sudo apt-get install -y gdb-multiarch python3-dev python3-pip python3-wheel python3-setuptools git cmake gcc g++ pkg-config libglib2.0-dev gdbserver qemu-user
        sudo python3 -m pip install --upgrade pip

    - name: Set runtime environment variables
      run: |
        echo PY_VER=`gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit` >> $GITHUB_ENV
        echo GEF_CI_NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV
        echo GEF_CI_ARCH=`uname --processor` >> $GITHUB_ENV
        echo GEF_CI_CACHE_DIR=`python3 -m pip cache dir` >> $GITHUB_ENV

    - name: Cache dependencies
      uses: actions/cache@v3
      id: cache-deps
      env:
        cache-name: cache-deps
      with:
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        path: ${{ env.GEF_CI_CACHE_DIR }}
        restore-keys:
          ${{ runner.os }}-pip-${{ env.cache-name }}-
          ${{ runner.os }}-pip-
          ${{ runner.os }}-${{ env.cache-name }}-
          ${{ runner.os }}-

    - name: Install Python Requirements
      run: |
        mkdir -p ${{ env.GEF_CI_CACHE_DIR }}
        python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt

    - name: Setup GEF
      run: |
        echo "source $(pwd)/gef.py" > ~/.gdbinit
        gdb -q -ex 'gef missing' -ex 'gef help' -ex 'gef config' -ex start -ex continue -ex quit /bin/pwd

    - name: Run Tests
      run: |
        make -C tests/binaries -j ${{ env.GEF_CI_NB_CPU }}
        python${{ env.PY_VER }} -m pytest --forked -n ${{ env.GEF_CI_NB_CPU }} -v -k "not benchmark" tests/

    - name: Run linter
      run: |
        python${{ env.PY_VER }} -m pylint --rcfile=$(pwd)/.pylintrc gef.py tests/*/*.py

    - name: Run test coverage
      if: matrix.os == 'ubuntu-22.04'
      run: |
        current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
        bash scripts/generate-coverage-docs.sh
        new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
        echo "New coverage score: ${new_score}% (current ${current_score}%)"
        python${{ env.PY_VER }} -c "( ${new_score} >= ${current_score} ) or exit(1)"<commit_msg>[ci] added a margin for the coverage reduction test<commit_after>name: CI Test for GEF

on:
  push:
    branches:
      - main
      - dev

  pull_request:
    branches:
      - main
      - dev

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-22.04
          - ubuntu-20.04
    name: "Run Unit tests on ${{ matrix.os }}"
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash

    steps:
    - uses: actions/checkout@v3

    - name: Install python and toolchain
      run: |
        sudo apt-get update
        sudo apt-get install -y gdb-multiarch python3-dev python3-pip python3-wheel python3-setuptools git cmake gcc g++ pkg-config libglib2.0-dev gdbserver qemu-user
        sudo python3 -m pip install --upgrade pip

    - name: Set runtime environment variables
      run: |
        echo PY_VER=`gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit` >> $GITHUB_ENV
        echo GEF_CI_NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV
        echo GEF_CI_ARCH=`uname --processor` >> $GITHUB_ENV
        echo GEF_CI_CACHE_DIR=`python3 -m pip cache dir` >> $GITHUB_ENV

    - name: Cache dependencies
      uses: actions/cache@v3
      id: cache-deps
      env:
        cache-name: cache-deps
      with:
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        path: ${{ env.GEF_CI_CACHE_DIR }}
        restore-keys:
          ${{ runner.os }}-pip-${{ env.cache-name }}-
          ${{ runner.os }}-pip-
          ${{ runner.os }}-${{ env.cache-name }}-
          ${{ runner.os }}-

    - name: Install Python Requirements
      run: |
        mkdir -p ${{ env.GEF_CI_CACHE_DIR }}
        python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt

    - name: Setup GEF
      run: |
        echo "source $(pwd)/gef.py" > ~/.gdbinit
        gdb -q -ex 'gef missing' -ex 'gef help' -ex 'gef config' -ex start -ex continue -ex quit /bin/pwd

    - name: Run Tests
      run: |
        make -C tests/binaries -j ${{ env.GEF_CI_NB_CPU }}
        python${{ env.PY_VER }} -m pytest --forked -n ${{ env.GEF_CI_NB_CPU }} -v -k "not benchmark" tests/

    - name: Run linter
      run: |
        python${{ env.PY_VER }} -m pylint --rcfile=$(pwd)/.pylintrc gef.py tests/*/*.py

    - name: Run test coverage
      if: matrix.os == 'ubuntu-22.04'
      env:
        ALLOWED_MARGIN: 0.05
      run: |
        current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
        bash scripts/generate-coverage-docs.sh
        new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
        echo "New coverage score: ${new_score}% (current ${current_score}%)"
        python${{ env.PY_VER }} -c "( ${new_score} < ( ${current_score} - ${{ env.ALLOWED_MARGIN}} ) ) and exit(1)"
{'fraction_non_alphanumeric': 0.16026854880358066, 'fraction_numerical': 0.009468066792907558, 'mean_word_length': 2.1036324786324787, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 30, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '903156', 'n_tokens_mistral': 2171, 'n_tokens_neox': 2042, 'n_words': 501}