diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e899c47c3..af3746c9a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -131,6 +131,25 @@ jobs: with: fetch-depth: 2 + - name: Read repo config + uses: pietrobolcato/action-read-yaml@1.1.0 + id: repo-config + with: + config: repo-config.yml + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "${{ steps.repo-config.outputs['python-version'] }}" + + - name: Run Poetry Image + uses: abatilo/actions-poetry@v3 + with: + poetry-version: "${{ steps.repo-config.outputs['poetry-version'] }}" + + - name: Install Dependencies + run: poetry install + # Set up Rust for scanning. - name: Set up Rust if: ${{ matrix.language == 'rust' }} @@ -160,7 +179,7 @@ jobs: - name: Manual build if: ${{ matrix.build-mode == 'manual' }} - run: python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }} + run: poetry run python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 diff --git a/poetry.lock b/poetry.lock index 3fd9d6c58..730395534 100644 --- a/poetry.lock +++ b/poetry.lock @@ -973,4 +973,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" python-versions = ">=3.10,<4.0" -content-hash = "84de3f44dd7b7d8f09a127c665f10145d99000481103a6406e1976ec9611c374" +content-hash = "8a4a58c1d1be22b32acd5ffbbcba64fc20eec26b7fa49fad2b7fb86273aae809" diff --git a/pyproject.toml b/pyproject.toml index 960a95919..47e3dbe9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,8 @@ license = "MIT" dependencies = [ "ronbun (>=0.10.1,<0.11.0)", - "glotter2 (>=0.13.0,<0.14.0)" + "glotter2 (>=0.13.0,<0.14.0)", + "pyyaml (>=6.0.3,<7.0.0)" ] # Initiator of the collection diff --git a/scripts/build_codeql_language.py b/scripts/build_codeql_language.py index 8988aac01..7b1aac9aa 100644 --- a/scripts/build_codeql_language.py +++ b/scripts/build_codeql_language.py @@ -1,10 +1,11 @@ import argparse import re -import shlex import subprocess from dataclasses import dataclass from pathlib import Path -from typing import Dict, List +from typing import Any, Dict, List + +import yaml TEST_INFO_DIR: Dict[str, str] = { "c": "c", @@ -14,7 +15,6 @@ "swift": "swift", } -BUILD_PATTERN = re.compile(r"""^\s+build:\s*['"]([^'"]+)""", re.M) SOURCE_NAME_PATTERN = re.compile(r"\{\{\s*source\.name\s*\}\}") SOURCE_EXTENSION_PATTERN = re.compile(r"\{\{\s*source\.extension\s*\}\}") @@ -23,7 +23,7 @@ class TestInfoStruct: path: Path language: str - test_info_str: str + build: str def main(): @@ -36,22 +36,21 @@ def main(): path = Path(changed_file) print(f"Building {path}") command = get_build_command(testinfo_struct, path) - subprocess.run(command, cwd=path.parent, check=True) + subprocess.run(command, cwd=path.parent, check=True, shell=True) def get_test_info_struct(language: str) -> TestInfoStruct: path = Path("archive") / language[0] / TEST_INFO_DIR[language] / "testinfo.yml" - testinfo_str = path.read_text(encoding="utf-8") - return TestInfoStruct(path=path, language=language, test_info_str=testinfo_str) + with path.open() as f: + testinfo = yaml.safe_load(f) + return TestInfoStruct(path=path, language=language, build=testinfo["container"]["build"]) -def get_build_command(testinfo_struct: TestInfoStruct, path: Path) -> List[str]: - match_str = BUILD_PATTERN.search(testinfo_struct.test_info_str) - assert match_str - build = SOURCE_NAME_PATTERN.sub(path.stem, match_str.group(1)) +def get_build_command(testinfo_struct: TestInfoStruct, path: Path) -> str: + build = SOURCE_NAME_PATTERN.sub(path.stem, testinfo_struct.build) build = SOURCE_EXTENSION_PATTERN.sub(path.suffix, build) - return shlex.split(build) + return build if __name__ == "__main__": diff --git a/scripts/generate_cargo_toml.py b/scripts/generate_cargo_toml.py index f14b9b75e..dcb131a42 100644 --- a/scripts/generate_cargo_toml.py +++ b/scripts/generate_cargo_toml.py @@ -13,6 +13,7 @@ path = "{path}" """ + def main(): cargo_toml = CARGO_TOML for path in Path("archive/r/rust").glob("*.rs"):