name: msys windows gfortran

on: [push, pull_request]

env:
  CTEST_TIME_TIMEOUT: "5"  # some failures hang forever
  FC: gfortran
  TZ: UTC+04:00

jobs:
  gfortran-windows-msys2-mingw64:
    runs-on: windows-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v1

    - name: Setup MinGW (MSYS2)
      uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: false
        install: >-
          git
          wget
          mingw-w64-x86_64-gcc-fortran
          mingw-w64-x86_64-meson
          mingw-w64-x86_64-ninja

    - name: Install fpm
      shell: msys2 {0}
      run: |
           wget https://raw.githubusercontent.com/urbanjost/index/main/bootstrap/fpm.F90
           gfortran fpm.F90 -o fpm

    - name: Run tests and demo programs (debug)
      shell: msys2 {0}
      run: |
        gfortran --version
        ./fpm test --profile release -flag "-D _WIN32"
      env:
         FC: gfortran
         TZ: UTC+04:00

    - name: Run tests and demo programs (release)
      shell: msys2 {0}
      run: |
        gfortran --version
        ./fpm test --profile release -flag "-D _WIN32"
      env:
         FC: gfortran
         TZ: UTC+04:00

    - name: Build with meson
      shell: msys2 {0}
      run: |
        meson --version
        meson setup build -Dbuildtype=debug
        meson compile -C build

    - name: cleanup 
      run: dir
