name: Julia

on:
  push:

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-20.04]
        julia-version: ['1']

    runs-on: ${{ matrix.os }}

    env:
      # Set `JULIA_PKG_SERVER` to the empty string so that the registry will
      # be fetched using git instead of the package server (to avoid delays).
      JULIA_PKG_SERVER: ""

    steps:
      - name: Environment setup
        uses: actions/checkout@v2
      - name: Julia setup
        uses: julia-actions/setup-julia@latest
        with:
          version: ${{ matrix.julia-version }}
      - name: Julia test and style
        run: |
          make info
          make -j2
          LIBCEED_LIB=$(find $PWD/lib -name "libceed.*")
          pushd julia/LibCEED.jl
          echo >> test/Project.toml
          echo "[preferences.libCEED_jll]" >> test/Project.toml
          echo "libceed_path = \"$LIBCEED_LIB\"" >> test/Project.toml
          [[ "$GITHUB_REF" =~ ^refs/(heads/release|tags/).* ]] || julia --project -e 'import Pkg; Pkg.test("LibCEED"; coverage=true, test_args=["--run-dev-tests"])'
          git checkout test/Project.toml && julia --project -e 'import Pkg; Pkg.test("LibCEED")'
          julia --project=.style/ -e 'import Pkg; Pkg.instantiate()' && julia --project=.style/ .style/ceed_style.jl && git diff --exit-code src test examples
