diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 11bbec39..cc1fd115 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -13,8 +13,38 @@ on: - '!documents/**' - '!fst/**' +env: + ICU_MAJOR: '77' + ICU_MINOR: '1' + jobs: + cache-icu: + runs-on: ubuntu-latest + steps: + - uses: actions/cache/restore@v4 + id: cache + with: + path: ~/icu + key: ${{ runner.os }}-icu-${ICU_MAJOR}-${ICU_MINOR} + - name: Download and install icu + if: steps.cache.outputs.cache-hit != 'true' + run: | + wget https://github.com/unicode-org/icu/releases/download/release-${ICU_MAJOR}-${ICU_MINOR}/icu4c-${ICU_MAJOR}_${ICU_MINOR}-Ubuntu22.04-x64.tgz + export ICU=~/icu/ + mkdir -p $ICU + echo "ICU directory is $ICU" + + # Get the release and unpack. + cp icu4c-${ICU_MAJOR}_${ICU_MINOR}-Ubuntu22.04-x64.tgz $ICU + pushd $ICU + + pwd + + tar xvfz *.tgz + rm *.tgz + build: + needs: cache-icu runs-on: ${{ matrix.os }} strategy: @@ -52,24 +82,17 @@ jobs: echo "project-root-dir=${{ github.workspace }}/inflection" >> "$GITHUB_OUTPUT" echo "build-output-dir=${{ github.workspace }}/inflection/build" >> "$GITHUB_OUTPUT" + - uses: actions/cache/restore@v4 + id: cache + with: + path: ~/icu + key: ${{ runner.os }}-icu-${ICU_MAJOR}-${ICU_MINOR} + # Install all the required dependencies for the macos - name: Install ICU (Ubuntu/macos) run: | if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - wget https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-Ubuntu22.04-x64.tgz - export TMP="/tmp/icu/" - # It may exist already - remove old stuff - mkdir -p $TMP - rm -rf $TMP/* - - # Get the release and unpack. - cp icu4c-77_1-Ubuntu22.04-x64.tgz $TMP - pushd $TMP - tar xvfz *.tgz - rm *.tgz - ls -l icu/usr/local/lib - popd - echo "ICU_ROOT=/tmp/icu/icu/usr/local" >> $GITHUB_ENV + echo "ICU_ROOT=~/icu/icu/usr/local" >> $GITHUB_ENV elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then brew list icu4c || brew install icu4c echo "ICU_ROOT=$(brew --prefix icu4c)" >> $GITHUB_ENV diff --git a/.github/workflows/ubuntu-memory-check.yml b/.github/workflows/ubuntu-memory-check.yml new file mode 100644 index 00000000..34f081f1 --- /dev/null +++ b/.github/workflows/ubuntu-memory-check.yml @@ -0,0 +1,106 @@ +name: Check memory leak by using valgrind + +on: + # Keep it for manual runs. + workflow_dispatch: + # Run it on all branches but ignore some paths. + pull_request: + paths: + - 'inflection/**' + - '!data/**' + - '!documents/**' + - '!fst/**' + +env: + ICU_MAJOR: '77' + ICU_MINOR: '1' + +jobs: + cache-icu: + runs-on: ubuntu-latest + steps: + - uses: actions/cache/restore@v4 + id: cache + with: + path: ~/icu + key: ${{ runner.os }}-icu-${ICU_MAJOR}-${ICU_MINOR} + - name: Download and install icu + if: steps.cache.outputs.cache-hit != 'true' + run: | + wget https://github.com/unicode-org/icu/releases/download/release-${ICU_MAJOR}-${ICU_MINOR}/icu4c-${ICU_MAJOR}_${ICU_MINOR}-Ubuntu22.04-x64.tgz + export ICU=~/icu/ + mkdir -p $ICU + echo "ICU directory is $ICU" + + # Get the release and unpack. + cp icu4c-${ICU_MAJOR}_${ICU_MINOR}-Ubuntu22.04-x64.tgz $ICU + pushd $ICU + + pwd + + tar xvfz *.tgz + rm *.tgz + + checkleak: + needs: cache-icu + runs-on: ubuntu-latest + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + lfs: 'true' + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "project-root-dir=${{ github.workspace }}/inflection" >> "$GITHUB_OUTPUT" + echo "build-output-dir=${{ github.workspace }}/inflection/build" >> "$GITHUB_OUTPUT" + + - name: Install valgrind + run: | + set -ex; + sudo apt-get -y update; + sudo apt-get install -y valgrind; + + - uses: actions/cache/restore@v4 + id: cache + with: + path: ~/icu + key: ${{ runner.os }}-icu-${ICU_MAJOR}-${ICU_MINOR} + + - name: Setup ICU_ROOT + run: | + echo "ICU_ROOT=~/icu/icu/usr/local" >> $GITHUB_ENV + + - name: Configure CMake + # 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 + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=clang++ + -DCMAKE_C_COMPILER=clang + -DCMAKE_BUILD_TYPE=Debug + -S ${{ steps.strings.outputs.project-root-dir }} + + - name: Get number of CPU cores + uses: SimenB/github-actions-cpu-cores@v2 + id: cpu-cores + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: + cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Debug -j ${{ steps.cpu-cores.outputs.count }} + + - name: Test with valgrind + env: + TEST_RUN_COMMAND: "valgrind --leak-check=full --show-leak-kinds=definite --errors-for-leak-kinds=definite --error-exitcode=1" + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: + cmake --build . -t check -j ${{ steps.cpu-cores.outputs.count }} +