Optimize bundle compilation workflow - #27
Conversation
This reverts commit 863e212.
Add compiler resource controls, reduce archive and pack-copy overhead, and overlap C++ cache acceptance with Java cache generation.
There was a problem hiding this comment.
Pull request overview
This PR optimizes CodeQL bundle compilation and cache workflows by introducing configurable resource limits (threads/RAM) and faster archive generation via tunable gzip compression, plus workflow adjustments to better isolate C++ cache building/validation.
Changes:
- Add CLI and internal plumbing for
--threads,--ram, and--compression-levelto tune compilation and bundle archive creation. - Speed up bundle creation by excluding generated pack artifacts when copying standard packs, making deletions more resilient, and limiting archive worker concurrency.
- Split the GitHub Actions cache workflow so C++ cache building and consumer validation run in dedicated jobs.
Show a summary per file
| File | Description |
|---|---|
tests/test_codeql.py |
Extends tests to assert --threads defaulting and --ram propagation into CodeQL pack commands. |
tests/test_bundle_archive.py |
Adds tests for gzip compression level handling and platform-specific tool exclusions in bundle archives. |
README.md |
Documents new resource-tuning flags and new workflow variables for runner/RAM selection. |
pyproject.toml |
Bumps package version to 0.5.1. |
codeql_bundle/helpers/codeql.py |
Adds ram configuration and passes --threads/--ram into pack create/pack bundle. |
codeql_bundle/helpers/bundle.py |
Adds default compression level, uses compresslevel= for gzip archives, improves pack copying/exclusion, and caps archive concurrency. |
codeql_bundle/cli.py |
Exposes --ram and --compression-level CLI flags and wires them into bundling. |
.github/workflows/codeql-compilation-caches.yml |
Refactors cache build workflow to separate C++ build and add a consumer validation job; adds optional RAM injection. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Suppressed comments (1)
tests/test_bundle_archive.py:37
- Same as above: the archive being opened is a .tar.gz; open it with an explicit gzip-capable read mode to avoid failures under
tarfile's default mode.
with tarfile.open(output / "codeql-bundle-linux64.tar.gz") as archive:
names = set(archive.getnames())
- Files reviewed: 8/8 changed files
- Comments generated: 3
- Review effort level: Lite
| with tarfile.open(output) as archive: | ||
| self.assertEqual(b"bundle", archive.extractfile("codeql/file").read()) |
There was a problem hiding this comment.
Updated both archive reads to use explicit r:gz mode.
| threads = self.threads if self.threads is not None else 0 | ||
| if self.threads is not None: | ||
| logging.info(f"Using {self.threads} threads for bundling {pack.config.name}.") | ||
| args.append(f"--threads={self.threads}") | ||
| else: | ||
| args.append(f"--threads=0") | ||
| logging.info( | ||
| f"Using {self.threads} threads for bundling {pack.config.name}." | ||
| ) | ||
| args.append(f"--threads={threads}") |
There was a problem hiding this comment.
Updated this to use the module logger and describe the pack create operation as creating the pack.
| The source tree for the next release after v0.5.0 adds controls for constrained | ||
| or high-capacity build agents: |
There was a problem hiding this comment.
Updated the documentation to refer explicitly to version 0.5.1.
There was a problem hiding this comment.
Review details
Suppressed comments (7)
codeql_bundle/helpers/codeql.py:251
logging.warnis deprecated and bypasses the module logger configuration. Uselogger.warningfor consistency with the rest of this module.
if disable_precompilation:
args.append("--no-precompile")
logging.warn(
f"NOTE: Precompilation is disabled for {pack.config.name}! This may result in slower query execution."
)
.github/workflows/codeql-compilation-caches.yml:249
- For the same reason as
build-cpp, this job should be skipped whenplan.outputs.cppfalls back to{language: "skip"}; otherwise it will fail later when trying to download/use a C++ cache artifact.
consumer-test:
needs:
- plan
- build-cpp
if: needs.plan.outputs.skip != 'true'
runs-on: ${{ vars.CODEQL_CACHE_CONSUMER_RUNNER || 'ubuntu-latest' }}
env:
.github/workflows/codeql-compilation-caches.yml:268
- This artifact name is hard-coded to
cache-cpp, butbuild-cppuploadscache-${{ fromJSON(needs.plan.outputs.cpp).language }}. Using the same expression here avoids a mismatch (especially if thecppoutput falls back to a non-cpp sentinel).
- uses: actions/download-artifact@v4
with:
name: cache-cpp
path: dist
codeql_bundle/helpers/codeql.py:206
logging.warnis deprecated and bypasses the module logger configuration. Uselogger.warninghere (and fix the mismatched indentation/paren).
This issue also appears on line 247 of the same file.
if disable_precompilation:
args.append("--no-precompile")
logging.warn(
f"NOTE: Precompilation is disabled for {pack.config.name}! This may result in slower query execution."
)
codeql_bundle/helpers/bundle.py:341
- Likely accidental missing whitespace around
=; this reduces readability and may trip linters.
@threads.setter
def threads(self, value: int):
self.codeql.threads= value
.github/workflows/codeql-compilation-caches.yml:197
plan.outputs.cpphas a fallback{"language":"skip","target":"skip"}, but this job will still run and try to build--target skipwhen no C++ target is present. Gate the job on the parsed language so it cleanly skips in that scenario.
This issue also appears in the following locations of the same file:
- line 243
- line 264
build-cpp:
needs: plan
if: needs.plan.outputs.skip != 'true'
runs-on: ubuntu-latest
env:
codeql_bundle/helpers/codeql.py:240
- When
--threads=0is provided explicitly, CodeQL interprets it as “use all available cores”, but this log message will read as “Using 0 threads”. Consider special-casing 0 so the log remains accurate.
if self.threads is not None:
logger.info(
f"Using {self.threads} threads for creating {pack.config.name}."
)
args.append(f"--threads={threads}")
- Files reviewed: 8/8 changed files
- Comments generated: 0 new
- Review effort level: Lite
This pull request introduces resource tuning options and refactors the CodeQL compilation cache workflow.
Resource management improvements:
--threadsfor parallelism,--ramfor memory limits, and--compression-levelfor gzip archive compression. These are now configurable via CLI options and repository variables, with sensible defaults and job-specific overrides. [1] [2] [3] [4] [5] [6] [7] [8]Workflow refactoring for C++ support:
build-cppandconsumer-test) in.github/workflows/codeql-compilation-caches.yml, ensuring C++ targets are handled separately from other languages and can be assigned different runners and resources. [1] [2] [3] [4] [5] [6]Code quality and maintainability:
consumer-testjob for better separation of concerns.These changes make the build and cache process more efficient/configurable for large or resource-constrained runners.