CI.yml

This is the GitHub Actions script used to perform continuous integration testing for JSON-Fortran, and trigger automatic documentation deployment.

name: CI

on: [push, pull_request]

jobs:

  Build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        gcc_v: [12,10,11,9] # Version of GFortran we want to use.
        python-version: [3.11]
    env:
      FC: gfortran-${{matrix.gcc_v}}
      GCC_V: ${{matrix.gcc_v}}

      #
      # GCC version
      #
      #  9 - build.sh with documentation, unit tests and coverage analysis. doc deployment
      #  10 - build.sh - no documentation, with and without unicode.
      #  11 - FPM
      #  12 - CMake build with unit tests, no documentation, with coverage analysis. no unicode
      #
      # NOTE: coverage disabled for now

    steps:

    - name: Checkout code
      uses: actions/checkout@v4.2.2
      with:
        submodules: recursive

    - name: Setup cmake
      if: contains( matrix.gcc_v, 12 )
      uses: jwlawson/actions-setup-cmake@v2.0.2
      with:
        cmake-version: '3.28.x'

    - name: Install Python
      uses: actions/setup-python@v5.1.0 # Use pip to install latest CMake, & FORD/Jin2For, etc.
      with:
        python-version: ${{ matrix.python-version }}

    - name: Setup Graphviz
      uses: ts-graphviz/setup-graphviz@v2.0.2

    - name: Set current directory in env variable
      run: echo "MYDIR=$(pwd)" >> $GITHUB_ENV

    - name: Set PYTHONPATH and PATH for later steps
      run: |
        echo "PYTHONPATH=$MYDIR/FoBiS/src/main/python:$PYTHONPATH" >> $GITHUB_ENV
        echo "PATH=$MYDIR/FoBiS/src/main/python:$PATH" >> $GITHUB_ENV

    - name: Install Python dependencies
      if: contains( matrix.os, 'ubuntu')
      run: |
        python -m pip install --upgrade pip
        #pip install ford FoBiS.py pygooglechart fpm
        pip install ford pygooglechart fpm
        # just get the latest FoBiS from git:
        # git clone https://github.com/szaghi/FoBiS.git
        # use a fork until there is a new release:
        git clone https://github.com/jacobwilliams/FoBiS.git
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

    - name: Install GFortran Linux
      if: contains( matrix.os, 'ubuntu')
      run: |
        sudo add-apt-repository ppa:ubuntu-toolchain-r/test
        sudo apt-get update
        sudo apt-get install -y gcc-${GCC_V} gfortran-${GCC_V}
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
        --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
        --slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V}

    - name: Compile_with_build
      if: matrix.gcc_v == 10
      run: |
        GFORTRAN=gfortran-${{matrix.gcc_v}}
        GCOV=gcov-${{matrix.gcc_v}}
        # build with build.sh, run unit tests
        ./build.sh --skip-documentation
        ./build.sh --skip-documentation --enable-unicode

    - name: Compile_with_FPM
      if: matrix.gcc_v == 11
      run: |
        GFORTRAN=gfortran-${{matrix.gcc_v}}
        GCOV=gcov-${{matrix.gcc_v}}
        sudo apt update && sudo apt install -y valgrind
        fpm --version
        gfortran --version
        fpm test "*" --runner "valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1"

    - name: Compile_with_cmake
      # CMake build with unit tests, no documentation, with coverage analysis
      # No unicode so that coverage combined with the build script will cover unicode
      # and non-unicode code paths
      if: matrix.gcc_v == 12
      run: |
        GFORTRAN=gfortran-${{matrix.gcc_v}}
        GCOV=gcov-${{matrix.gcc_v}}
        mkdir cmake-build
        cd cmake-build
        cmake -D ENABLE_TESTS=ON ..
        make -j 4 check

    - name: Compile_with_build_mkdocs
      # build with build.sh, make documentation, run unit tests
      # and perform coverage analysis - used for doc deployment
      if: matrix.gcc_v == 9
      run: |
        GFORTRAN=gfortran-${{matrix.gcc_v}}
        GCOV=gcov-${{matrix.gcc_v}}
        ./build.sh --coverage --skip-documentation
        # delete old coverage files:
        find . -name '*.gcda' -delete
        find . -name '*.gcov' -delete
        ./build.sh --coverage --enable-unicode

    - name: Deploy Documentation for master
      if: matrix.gcc_v == 9 && github.ref == 'refs/heads/master'
      uses: JamesIves/github-pages-deploy-action@v4.7.3
      with:
        branch: gh-pages # The branch the action should deploy to.
        folder: doc  # The folder the action should deploy.
        clean: true
        clean-exclude: |
          prev

    - name: Rebuild documentation for tagged release
      env:
        TAGNAME: ${{github.ref_name}}
      if: matrix.gcc_v == 9 && startsWith(github.ref, 'refs/tags/')
      run: |
        echo ${TAGNAME}
        rm -rf doc
        sed "2 s/^/version: ${TAGNAME}\n/" ford.md > json-fortran.tagged.md
        ford --debug json-fortran.tagged.md

    - name: Deploy documentation for tagged release
      if: matrix.gcc_v == 9 && startsWith(github.ref, 'refs/tags/')
      uses: JamesIves/github-pages-deploy-action@v4.7.3
      with:
        branch: gh-pages # The branch the action should deploy to.
        folder: doc  # The folder the action should deploy.
        target-folder: prev/${{github.ref_name}} # deploy to a version-specific folder
        single-commit: true

    - name: Upload coverage
      if: matrix.gcc_v == 9
      run: |
        rm json_*.F90-*unicode.gcov || true
        mv json_*.F90.gcov src/
        mv jf_test*.[fF]90.gcov test/
        bash <(curl -s https://codecov.io/bash) -v -X $GCOV