diff --git a/.github/actions/install-codeql-packs/action.yml b/.github/actions/install-codeql-packs/action.yml index 2e6d5f1a2e..3a60e47bb1 100644 --- a/.github/actions/install-codeql-packs/action.yml +++ b/.github/actions/install-codeql-packs/action.yml @@ -7,6 +7,11 @@ inputs: The path to the CodeQL CLI directory. required: false + common_caches: + description: | + The path to the CodeQL common caches directory. + required: false + mode: description: | The `--mode` option to `codeql pack install`. @@ -22,4 +27,6 @@ runs: CODEQL_CLI: ${{ inputs.cli_path }} run: | PATH=$PATH:$CODEQL_CLI - python scripts/install-packs.py --mode ${{ inputs.mode }} + python scripts/install-packs.py \ + --mode ${{ inputs.mode }} \ + --common-caches "${{ inputs.common_caches }}" diff --git a/.github/workflows/codeql_unit_tests.yml b/.github/workflows/codeql_unit_tests.yml index 23d6972a13..eea96cbd85 100644 --- a/.github/workflows/codeql_unit_tests.yml +++ b/.github/workflows/codeql_unit_tests.yml @@ -17,7 +17,6 @@ on: - "rc/**" jobs: - prepare-unit-test-matrix: name: Prepare CodeQL unit test matrix runs-on: ubuntu-22.04 @@ -59,7 +58,7 @@ jobs: - name: Cache CodeQL id: cache-codeql - uses: actions/cache@v5 + uses: actions/cache@v6 with: # A list of files, directories, and wildcard patterns to cache and restore path: ${{github.workspace}}/codeql_home @@ -75,16 +74,26 @@ jobs: codeql-home: ${{ github.workspace }}/codeql_home add-to-path: false + - name: Cache queries compilation + uses: actions/cache@v6 + with: + path: ${{ github.workspace }}/codeql_cache + key: ${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}-${{ github.run_id }} + restore-keys: ${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} + - name: Install CodeQL packs uses: ./.github/actions/install-codeql-packs with: cli_path: ${{ github.workspace }}/codeql_home/codeql + common_caches: ${{ github.workspace }}/codeql_cache - name: Pre-Compile Queries id: pre-compile-queries run: | - ${{ github.workspace }}/codeql_home/codeql/codeql query compile --threads 0 ${{ matrix.language }} - + ${{ github.workspace }}/codeql_home/codeql/codeql query compile \ + --common-caches=${{ github.workspace }}/codeql_cache \ + --threads 0 \ + ${{ matrix.language }} - name: Run test suites id: run-test-suites @@ -135,7 +144,7 @@ jobs: os.makedirs(os.path.dirname(test_report_path), exist_ok=True) test_report_file = open(test_report_path, 'w') files_to_close.append(test_report_file) - procs.append(subprocess.Popen([codeql_bin, "test", "run", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", *test_roots], stdout=test_report_file, stderr=subprocess.PIPE)) + procs.append(subprocess.Popen([codeql_bin, "test", "run", "--common-caches=${{ github.workspace }}/codeql_cache", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", *test_roots], stdout=test_report_file, stderr=subprocess.PIPE)) for p in procs: _, err = p.communicate() diff --git a/scripts/install-packs.py b/scripts/install-packs.py index ab45c32818..f9a703e1d3 100644 --- a/scripts/install-packs.py +++ b/scripts/install-packs.py @@ -6,6 +6,7 @@ parser = argparse.ArgumentParser(description="Install CodeQL library pack dependencies.") parser.add_argument('--mode', required=False, choices=['use-lock', 'update', 'verify', 'no-lock'], default="use-lock", help="Installation mode, identical to the `--mode` argument to `codeql pack install`") parser.add_argument('--codeql', required=False, default='codeql', help="Path to the `codeql` executable.") +parser.add_argument('--common-caches', required=False, help="Path to the CodeQL common caches directory.") args = parser.parse_args() # Find the root of the repo @@ -19,5 +20,7 @@ pack_path = os.path.join(root, pack) # Run `codeql pack install` to install dependencies. command = [args.codeql, 'pack', 'install', '--allow-prerelease', '--mode', args.mode, pack_path] + if args.common_caches: + command.insert(3, f'--common-caches={args.common_caches}') print(f'Running `{" ".join(command)}`') subprocess.check_call(command)