name: 'HackLintTest'
description: 'Runs the Hack typechecker, linter (HHAST) and tests (HackTest)'
inputs:
  hhvm:
    description: 'HHVM version (latest/nightly/#.##)'
    required: true
  skip_lint:
    description: 'Optional. Set to "true" to skip the hhast-lint step.'
    required: false
    default: false
  skip_tests:
    description: 'Optional. Set to "true" to skip the hacktest step.'
    required: false
    default: false
  hhvm_flags:
    description: 'Optional. Command line arguments that will be added to all `hhvm` invocations (hh-autoload, hhast-lint, hacktest).'
    required: false
runs:
  using: "composite"
  steps:
    - name: Install Composer
      shell: bash
      run: ${{github.action_path}}/install-composer.sh --install-dir=${{runner.temp}}
    - name: Install HHVM
      shell: bash
      run: ${{github.action_path}}/install-hhvm.sh ${{inputs.hhvm}}
    - name: Inspect HHVM and Hack versions
      shell: bash
      run: |
        hhvm --version
        hh_client --version
    - name: Install project dependencies
      shell: bash
      env:
        COMPOSER_ROOT_VERSION: dev-${{github.base_ref || github.ref_name}}
      run: |
        echo "::group::Install project dependencies"
        FLAGS=""
        if [ -n "${{inputs.hhvm_flags}}" ]; then
          FLAGS="--no-autoloader"
        fi
        php ${{runner.temp}}/composer.phar install $FLAGS
        echo "::endgroup::"
    - name: Generate autoload map
      shell: bash
      run: |
        if [ -n "${{inputs.hhvm_flags}}" ]; then
          echo "::group::Generate autoload map"
          (
            set -x
            hhvm ${{inputs.hhvm_flags}} vendor/hhvm/hhvm-autoload/bin/hh-autoload
          )
          echo "::endgroup::"
        fi
    - name: Typecheck
      shell: bash
      run: |
        echo "::group::Typecheck"
        hh_client
        echo "::endgroup::"
    - name: Lint
      shell: bash
      run: |
        ${{github.action_path}}/lint.sh \
          "${{inputs.hhvm}}" \
          "${{inputs.skip_lint}}" \
          "${{inputs.hhvm_flags}}"
    - name: Run tests
      shell: bash
      run: |
        ${{github.action_path}}/test.sh \
          "${{inputs.skip_tests}}" \
          "${{inputs.hhvm_flags}}"
