# Check that syntax is correct

name: CIFSyntaxandStyleCheck

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
    paths-ignore:
            - '.github/**'

  pull_request:
    branches: [ master ]
    paths-ignore:
            - '.github/**'
  workflow_dispatch:   

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  syntax:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
        - name: checkout
          uses: actions/checkout@v4
          
      # Check syntax of all CIF files
        - name: check_syntax
          uses: COMCIFS/cif_syntax_check_action@master
          id: cif_syntax_check
  ddlm:
    runs-on: ubuntu-latest
    needs: syntax
    steps:
        - name: checkout
          uses: actions/checkout@v4

        - name: check_ddlm
          uses: COMCIFS/dictionary_check_action@main
          id: ddlm_check
  layout:
    runs-on: ubuntu-latest
    needs: syntax

    steps:
      - name: Get the cache
        uses: actions/cache@v4
        id: cache
        with:
                 path: ~/.julia
                 key: ${{ runner.os }}-julia-v2
                 
      - name: Install Julia
        uses: julia-actions/setup-julia@v1
        with:
                version: '1.6'

      - name: Install Julia packages
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
               julia -e 'import Pkg;Pkg.add("CrystalInfoFramework");Pkg.add("Lerche");Pkg.add("FilePaths");Pkg.add("ArgParse")'

      - name: checkout
        uses: actions/checkout@v4
        with:
                path: main
      - name: checkout julia tools
        uses: actions/checkout@v4
        with:
                repository: jamesrhester/julia_cif_tools
                path: julia_cif_tools

      - name: Checkout CIF master files
        uses: actions/checkout@v4
        with:
                repository: COMCIFS/cif_core
                path: cif_core
      - name: Diagnostics
        run: |
            ls -a
            pwd
            which julia

      - name: one_dict_layout
        run: |
               julia -e 'using Pkg; Pkg.status()'
               for file in main/*.dic
               do      
                  echo "Checking $file"
                  julia -O0 ./julia_cif_tools/linter.jl -i $PWD/cif_core $file cif_core/ddl.dic
                  if [ $? != 0 ] 
                  then 
                    exit 1 ;
                  fi 
               done
