name: Checks
on: [pull_request]

jobs:
  Regressions:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Install Required Libraries
      run: sudo apt-get install libfuse2

    - name: Install OpenSCAD
      run: |
        cd $GITHUB_WORKSPACE
        wget https://github.com/openscad/openscad/releases/download/openscad-2021.01/OpenSCAD-2021.01-x86_64.AppImage
        sudo mv OpenSCAD-2021.01*-x86_64.AppImage /usr/local/bin/openscad
        sudo chmod +x /usr/local/bin/openscad

    - name: Run Regression Tests
      run: |
        cd $GITHUB_WORKSPACE
        export OPENSCADPATH=$(dirname $GITHUB_WORKSPACE)
        ./scripts/run_tests.sh

  CheckTutorials:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Clone Wiki
      uses: actions/checkout@v3
      with:
        repository: BelfrySCAD/BOSL2.wiki
        path: BOSL2.wiki

    - name: Apt Update
      run: sudo apt update

    - name: Install Required Libraries
      run: sudo apt-get install python3-pip python3-dev python3-setuptools python3-pil libfuse2

    - name: Install OpenSCAD-DocsGen package.
      run: sudo pip3 install openscad-docsgen

    - name: Install OpenSCAD
      run: |
        cd $GITHUB_WORKSPACE
        wget https://github.com/openscad/openscad/releases/download/openscad-2021.01/OpenSCAD-2021.01-x86_64.AppImage
        sudo mv OpenSCAD-2021.01*-x86_64.AppImage /usr/local/bin/openscad
        sudo chmod +x /usr/local/bin/openscad

    - name: Tabs Check
      run: |
        cd $GITHUB_WORKSPACE
        echo "::add-matcher::.github/check_for_tabs.json"
        ./scripts/check_for_tabs.sh

    - name: Checking Tutorials
      run: |
        cd $GITHUB_WORKSPACE
        echo "::add-matcher::.github/openscad_docsgen.json"
        export OPENSCADPATH=$(dirname $GITHUB_WORKSPACE)
        openscad-mdimggen -T

  CheckDocs:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Clone Wiki
      uses: actions/checkout@v3
      with:
        repository: BelfrySCAD/BOSL2.wiki
        path: BOSL2.wiki

    - name: Apt Update
      run: sudo apt update

    - name: Install Required Libraries
      run: sudo apt-get install python3-pip python3-dev python3-setuptools python3-pil libfuse2

    - name: Install OpenSCAD-DocsGen package.
      run: sudo pip3 install openscad-docsgen

    - name: Install OpenSCAD
      run: |
        cd $GITHUB_WORKSPACE
        wget https://github.com/openscad/openscad/releases/download/openscad-2021.01/OpenSCAD-2021.01-x86_64.AppImage
        sudo mv OpenSCAD-2021.01*-x86_64.AppImage /usr/local/bin/openscad
        sudo chmod +x /usr/local/bin/openscad

    - name: Checking Docs
      run: |
        cd $GITHUB_WORKSPACE
        echo "::add-matcher::.github/openscad_docsgen.json"
        export OPENSCADPATH=$(dirname $GITHUB_WORKSPACE)
        openscad-docsgen -Tmf