codeql-action: v2.15.3 - Python code analysis fails

Hi there, I am trying to setup CodeQL analysis on a repo in our github enterprise server. This is a monorepo with TypeScript and Python code. The directory structure is like so

Repo
├── engine <- Python
├── cli <- Python
└── ui <- TypeScript

While analyzing the Python code, the CodeQL action fails with below error. Could you please help me figure out what I might be doing wrong?

2023-12-15T20:53:40.9634252Z ##[debug]Artifact debug-artifacts-python has been successfully uploaded, total size in bytes: 282039
2023-12-15T20:53:40.9635669Z Artifact has been finalized. All files have been successfully uploaded!
2023-12-15T20:53:40.9639065Z 
2023-12-15T20:53:40.9639865Z The raw size of all the files that were specified for upload is 282039 bytes
2023-12-15T20:53:40.9641501Z The size of all the files that were uploaded is 18399 bytes. This takes into account any gzip compression used to reduce the upload size, time and storage
2023-12-15T20:53:40.9642371Z 
2023-12-15T20:53:40.9643575Z Note: The size of downloaded zips can differ significantly from the reported size. For more information see: https://github.com/actions/upload-artifact#zipped-artifact-downloads 
2023-12-15T20:53:40.9644542Z 
2023-12-15T20:53:40.9646099Z ::group::CodeQL Debug Logs - python - database-trace-command-20231215.205329.488.log from file at path /__w/_temp/codeql_databases/python/log/database-trace-command-20231215.205329.488.log
2023-12-15T20:53:40.9648212Z ##[group]CodeQL Debug Logs - python - database-trace-command-20231215.205329.488.log from file at path /__w/_temp/codeql_databases/python/log/database-trace-command-20231215.205329.488.log
2023-12-15T20:53:40.9649754Z [2023-12-15 20:53:29] This is codeql database trace-command --index-traceless-dbs /__w/_temp/codeql_databases/python
2023-12-15T20:53:40.9650693Z [2023-12-15 20:53:29] Log file was started late.
2023-12-15T20:53:40.9651674Z [2023-12-15 20:53:29] Using autobuild script /__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/autobuild.sh.
2023-12-15T20:53:40.9652989Z [2023-12-15 20:53:29] [PROGRESS] database trace-command> Running command in /__w/nila/nila: [/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/autobuild.sh]
2023-12-15T20:53:40.9654275Z [2023-12-15 20:53:29] [build-stderr] /bin/sh: 1: python2: not found
2023-12-15T20:53:40.9655462Z [2023-12-15 20:53:29] [build-stdout] No directories containing root identifiers were found. Returning working directory as root.
2023-12-15T20:53:40.9656656Z [2023-12-15 20:53:29] [build-stdout] Will try to guess Python version, as it was not specified in `lgtm.yml`
2023-12-15T20:53:40.9657791Z [2023-12-15 20:53:29] [build-stdout] Trying to guess Python version based on Trove classifiers in setup.py
2023-12-15T20:53:40.9658896Z [2023-12-15 20:53:29] [build-stdout] Did not find setup.py (expected it to be at /__w/nila/nila/setup.py)
2023-12-15T20:53:40.9659906Z [2023-12-15 20:53:29] [build-stdout] Trying to guess Python version based on travis file
2023-12-15T20:53:40.9661145Z [2023-12-15 20:53:29] [build-stdout] Did not find any travis files (expected them at either ['/__w/nila/nila/.travis.yml', '/__w/nila/nila/travis.yml'])
2023-12-15T20:53:40.9662300Z [2023-12-15 20:53:29] [build-stdout] Trying to guess Python version based on installed versions
2023-12-15T20:53:40.9663400Z [2023-12-15 20:53:29] [build-stdout] Wanted to run Python 2, but it is not available. Using Python 3 instead
2023-12-15T20:53:40.9664755Z [2023-12-15 20:53:29] [build-stdout] This script is running Python 3, but Python 2 is also available (as 'python3')
2023-12-15T20:53:40.9666131Z [2023-12-15 20:53:29] [build-stdout] Could not guess Python version, will use default: Python 3
2023-12-15T20:53:40.9667251Z [2023-12-15 20:53:29] [build-stdout] Calling python3 /__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/get_venv_lib.py
2023-12-15T20:53:40.9669253Z [2023-12-15 20:53:29] [build-stdout] Calling python3 -S /__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python_tracer.py -v -z all -c /__w/_temp/codeql_databases/python/working/trap_cache -p /github/home/.local/lib/python3.6/site-packages --filter include:engine/engine/*.py --filter include:cli/cli/*.py --filter include:ui/packages/**/*.ts
2023-12-15T20:53:40.9670699Z [2023-12-15 20:53:30] [build-stderr] Process ForkProcess-1:
2023-12-15T20:53:40.9671590Z [2023-12-15 20:53:30] [build-stderr] Traceback (most recent call last):
2023-12-15T20:53:40.9672693Z [2023-12-15 20:53:30] [build-stderr]   File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
2023-12-15T20:53:40.9673610Z [2023-12-15 20:53:30] [build-stderr]     self.run()
2023-12-15T20:53:40.9674889Z [2023-12-15 20:53:30] [build-stderr]   File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
2023-12-15T20:53:40.9675910Z [2023-12-15 20:53:30] [build-stderr]     self._target(*self._args, **self._kwargs)
2023-12-15T20:53:40.9677133Z [2023-12-15 20:53:30] [build-stderr]   File "/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python3src.zip/semmle/logging.py", line 116, in _message_loop
2023-12-15T20:53:40.9678252Z [2023-12-15 20:53:30] [build-stderr]     sys.stdout.reconfigure(encoding='utf-8')
2023-12-15T20:53:40.9679360Z [2023-12-15 20:53:30] [build-stderr] AttributeError: '_io.TextIOWrapper' object has no attribute 'reconfigure'
2023-12-15T20:53:40.9680377Z [2023-12-15 20:53:30] [build-stderr] Traceback (most recent call last):
2023-12-15T20:53:40.9681694Z [2023-12-15 20:53:30] [build-stderr]   File "/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python_tracer.py", line 53, in <module>
2023-12-15T20:53:40.9682937Z [2023-12-15 20:53:30] [build-stderr]     semmle.populator.main(original_path)
2023-12-15T20:53:40.9684356Z [2023-12-15 20:53:30] [build-stderr]   File "/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python3src.zip/semmle/populator.py", line 43, in main
2023-12-15T20:53:40.9685586Z [2023-12-15 20:53:30] [build-stderr] AttributeError: '_io.TextIOWrapper' object has no attribute 'reconfigure'
2023-12-15T20:53:40.9686589Z [2023-12-15 20:53:30] [build-stderr] Traceback (most recent call last):
2023-12-15T20:53:40.9687685Z [2023-12-15 20:53:30] [build-stderr]   File "/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/index.py", line 23, in <module>
2023-12-15T20:53:40.9688650Z [2023-12-15 20:53:30] [build-stderr]     buildtools.index.main()
2023-12-15T20:53:40.9689831Z [2023-12-15 20:53:30] [build-stderr]   File "/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python3src.zip/buildtools/index.py", line 222, in main
2023-12-15T20:53:40.9691161Z [2023-12-15 20:53:30] [build-stderr]   File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
2023-12-15T20:53:40.9692190Z [2023-12-15 20:53:30] [build-stderr]     raise CalledProcessError(retcode, cmd)
2023-12-15T20:53:40.9694789Z [2023-12-15 20:53:30] [build-stderr] subprocess.CalledProcessError: Command '['python3', '-S', '/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/python_tracer.py', '-v', '-z', 'all', '-c', '/__w/_temp/codeql_databases/python/working/trap_cache', '-p', '/github/home/.local/lib/python3.6/site-packages', '--filter', 'include:engine/engine/*.py', '--filter', 'include:cli/cli/*.py', '--filter', 'include:ui/packages/**/*.ts']' returned non-zero exit status 1.
2023-12-15T20:53:40.9696854Z [2023-12-15 20:53:30] [ERROR] Spawned process exited abnormally (code 1; tried to run: [/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/autobuild.sh])
2023-12-15T20:53:40.9698225Z [2023-12-15 20:53:30] Exception caught at top level: Exit status 1 from command: [/__w/_tool/CodeQL/2.15.3/x64/codeql/python/tools/autobuild.sh]
2023-12-15T20:53:40.9699488Z                       com.semmle.cli2.Commandline.executeAndCheckResult(Commandline.java:170)
2023-12-15T20:53:40.9700478Z                       com.semmle.cli2.Commandline.runWithoutReturn(Commandline.java:123)
2023-12-15T20:53:40.9701720Z                       com.semmle.cli2.database.DatabaseProcessCommandCommon.executeSubcommand(DatabaseProcessCommandCommon.java:226)
2023-12-15T20:53:40.9703107Z                       com.semmle.cli2.database.TraceCommandCommand.executeSubcommand(TraceCommandCommand.java:110)
2023-12-15T20:53:40.9704593Z                       com.semmle.cli2.picocli.SubcommandCommon.lambda$executeSubcommandWithMessages$5(SubcommandCommon.java:803)
2023-12-15T20:53:40.9705867Z                       com.semmle.cli2.picocli.SubcommandCommon.withCompilationMessages(SubcommandCommon.java:442)
2023-12-15T20:53:40.9707183Z                       com.semmle.cli2.picocli.SubcommandCommon.executeSubcommandWithMessages(SubcommandCommon.java:801)
2023-12-15T20:53:40.9708421Z                       com.semmle.cli2.picocli.SubcommandCommon.toplevelMain(SubcommandCommon.java:685)
2023-12-15T20:53:40.9709472Z                       com.semmle.cli2.picocli.SubcommandCommon.call(SubcommandCommon.java:666)
2023-12-15T20:53:40.9710507Z                       com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:237)
2023-12-15T20:53:40.9711523Z                       com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:247)
2023-12-15T20:53:40.9712412Z                       com.semmle.cli2.CodeQL.main(CodeQL.java:115)
2023-12-15T20:53:40.9713399Z ::endgroup::
2023-12-15T20:53:40.9714036Z ##[endgroup]

codeql.yml

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
  pull_request:
    branches: [ "main" ]
  push:
    branches: [ "main" ]

jobs:
  analyze:
    name: Analyze
    runs-on: [ self-hosted, Linux ]
   container: 
     image: <custom image>
    permissions:
      actions: read
      contents: read
      security-events: write

    strategy:
      fail-fast: false
      matrix:
        language: [ 'javascript', 'python' ]
        # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
        # Use only 'java' to analyze code written in Java, Kotlin or both
        # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
        # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    # Initializes the CodeQL tools for scanning.
    - name: Initialize CodeQL
      uses: github/codeql-action/init@v2
      with:
        languages: ${{ matrix.language }}
        config-file: ./.github/codeql/codeql-config.yml
        # If you wish to specify custom queries, you can do so here or in a config file.
        # By default, queries listed here will override any specified in a config file.
        # Prefix the list here with "+" to use these queries and those in the config file.

        # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
        # queries: security-extended,security-and-quality


    # Autobuild attempts to build any compiled languages  (C/C++, C#, Go, or Java).
    # If this step fails, then you should remove it and run the build manually (see below)
    - name: Autobuild
      uses: github/codeql-action/autobuild@v2

    # ℹ️ Command-line programs to run using the OS shell.
    # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

    #   If the Autobuild fails above, remove it and uncomment the following three lines.
    #   modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

    # - run: |
    #   echo "Run, Build Application using script"
    #   ./location_of_script_within_repo/buildscript.sh

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@v2
      with:
        category: "/language:${{matrix.language}}"

codeql-config.yml

paths:
  - engine/engine/*.py
  - cli/cli/*.py
  - ui/packages/**/*.ts

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

@BullHacks3 please open a new issue then.

I could reproduce, and narrowed down the problem to cases where paths contains globs 😬 As a workaround, can you please use this config file?

paths:
  - 'engine/'
  - 'cli/'
  - 'ui/'

Sorry, I thought I replied back. The suggested config file does work @RasmusWL. Thanks!

For typescript, no compilation or code execution is required during extraction. For python, we need to execute the python extractor, which is built in python.

@RasmusWL do you have any suggestions on what to do?