name: Check Code-Scanning Config
description: |
    Checks the code scanning configuration file generated by the
    action to ensure it contains the expected contents
inputs:
  languages:
    required: false
    description: The languages field passed to the init action.

  packs:
    required: false
    description: The packs field passed to the init action.

  queries:
    required: false
    description: The queries field passed to the init action.

  config-file-test:
    required: false
    description: |
      The location of the config file to use. If empty,
      then no config file is used.

  expected-config-file-contents:
    required: true
    description: |
      A JSON string containing the exact contents of the config file.

  tools:
    required: true
    description: |
      The version of CodeQL passed to the `tools` input of the init action.
      This can be any of the following:

      - A local path to a tarball containing the CodeQL tools, or
      - A URL to a GitHub release assets containing the CodeQL tools, or
      - A special value `linked` which is forcing the use of the CodeQL tools
        that the action has been bundled with.

      If not specified, the Action will check in several places until it finds
      the CodeQL tools.

runs:
  using: composite
  steps:
    - uses: ./../action/init
      with:
        languages: ${{ inputs.languages }}
        config-file: ${{ inputs.config-file-test }}
        queries: ${{ inputs.queries }}
        packs: ${{ inputs.packs }}
        tools: ${{ inputs.tools }}
        db-location: ${{ runner.temp }}/codescanning-config-cli-test
      env:
        CODEQL_ACTION_TEST_MODE: 'true'

    - name: Install dependencies
      shell: bash
      run: npm install --location=global ts-node js-yaml

    - name: Check config
      working-directory: ${{ github.action_path }}
      shell: bash
      env:
        EXPECTED_CONFIG_FILE_CONTENTS: '${{ inputs.expected-config-file-contents }}'
      run: ts-node ./index.ts "$RUNNER_TEMP/user-config.yaml" "$EXPECTED_CONFIG_FILE_CONTENTS"
    - name: Clean up
      shell: bash
      if: always()
      run: |
        rm -rf $RUNNER_TEMP/codescanning-config-cli-test
        rm -rf $RUNNER_TEMP/user-config.yaml
