Skip to content

Commit 38db97f

Browse files
committed
using exisitng libs
1 parent ad2717c commit 38db97f

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

.github/workflows/codeql-multiple-repo-scan.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,19 @@ jobs:
4040
steps:
4141
- name: Checkout central repository
4242
uses: actions/checkout@v4
43-
- name: Checkout CodeQL Coding Standards scripts
44-
uses: actions/checkout@v4
45-
with:
46-
repository: github/codeql-coding-standards
47-
path: codeql-coding-standards-repo # Klonen in diesen Ordner
48-
ref: main # Oder eine spezifische Release-Version, z.B. 'v2.53.0-dev'
4943
# Add coding standard packages and dependencies
50-
- name: Install Python dependencies for Coding Standards scripts
44+
- name: Install Python dependencies
5145
run: |
5246
python3 -m pip install --upgrade pip
53-
pip3 install pyyaml jsonpath-ng jsonschema jsonpatch jsonpointer pytest sarif-tools
47+
pip3 install --break-system-packages pyyaml jsonpath-ng jsonschema jsonpatch jsonpointer pytest sarif-tools
5448
- name: Parse known_good.json and create repos.json
5549
id: parse-repos
5650
run: |
5751
python3 scripts/workflow/parse_repos.py
5852
- name: Checkout all pinned repositories
5953
id: checkout-repos
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6056
run: |
6157
python3 scripts/workflow/checkout_repos.py
6258
- name: List files in repos directory (debug)
@@ -76,6 +72,13 @@ jobs:
7672
upload-database: false # Don't upload databases for each repo
7773
output: sarif-results/
7874
category: "multi-repo-scan"
75+
# Checkout CodeQL Coding Standards AFTER analysis for recategorization
76+
- name: Checkout CodeQL Coding Standards for recategorization
77+
uses: actions/checkout@v4
78+
with:
79+
repository: github/codeql-coding-standards
80+
path: codeql-coding-standards-repo
81+
ref: v2.50.0 # Use frozen version instead of main
7982
- name: Recategorize Guidelines
8083
if: always()
8184
run: |

scripts/workflow/checkout_repos.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def is_commit_hash(ref):
6363

6464
def checkout_repo(name, url, ref, path):
6565
"""
66-
Checkout a single repository.
66+
Checkout a single repository using git with GitHub token for authentication.
6767
6868
Args:
6969
name: Repository name
@@ -80,12 +80,21 @@ def checkout_repo(name, url, ref, path):
8080
# Create parent directory if needed
8181
path_obj.parent.mkdir(parents=True, exist_ok=True)
8282

83+
# Use GitHub token if available to avoid rate limits
84+
github_token = os.environ.get("GITHUB_TOKEN", "")
85+
auth_url = url
86+
87+
if github_token and "github.com" in url:
88+
# Inject token into URL for authenticated requests
89+
# Replace https://github.com/ with https://token@github.com/
90+
auth_url = url.replace("https://github.com/", f"https://{github_token}@github.com/")
91+
8392
if is_commit_hash(ref):
8493
print(f"Checking out {name} ({ref}) to {path}")
8594
print(f" Detected commit hash. Cloning and then checking out.")
8695

8796
# Clone the repository
88-
subprocess.run(["git", "clone", url, path], check=True, capture_output=True)
97+
subprocess.run(["git", "clone", auth_url, path], check=True, capture_output=True)
8998

9099
# Checkout specific commit
91100
subprocess.run(["git", "-C", path, "checkout", ref], check=True, capture_output=True)
@@ -97,7 +106,9 @@ def checkout_repo(name, url, ref, path):
97106
# Add 'v' prefix if not already present (common convention)
98107
branch_ref = ref if ref.startswith("v") else f"v{ref}"
99108
subprocess.run(
100-
["git", "clone", "--depth", "1", "--branch", branch_ref, url, path], check=True, capture_output=True
109+
["git", "clone", "--depth", "1", "--branch", branch_ref, auth_url, path],
110+
check=True,
111+
capture_output=True,
101112
)
102113

103114
return True

scripts/workflow/parse_repos.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@
1313
# *******************************************************************************
1414
"""
1515
Parse known_good.json and create repos.json for multi-repository CodeQL analysis.
16+
17+
Uses scripts.tooling.lib.known_good for consistent parsing of known_good.json.
1618
"""
1719

1820
import json
1921
import os
2022
import sys
21-
import subprocess
2223
from pathlib import Path
2324

25+
# Add scripts directory to path for imports from tooling library
26+
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "scripts"))
2427

25-
def install_dependencies():
26-
"""Ensure jq is installed (for reference, though we use Python's json)."""
27-
try:
28-
subprocess.run(["sudo", "apt-get", "update"], check=True, capture_output=True)
29-
subprocess.run(["sudo", "apt-get", "install", "-y", "jq"], check=True, capture_output=True)
30-
except subprocess.CalledProcessError as e:
31-
print(f"Warning: Failed to install jq: {e}", file=sys.stderr)
28+
from tooling.lib.known_good import load_known_good
3229

3330

3431
def parse_known_good(json_file="./known_good.json"):
3532
"""
3633
Parse known_good.json and transform modules into repository objects.
3734
35+
Uses the centralized scripts.tooling.lib.known_good library for parsing.
36+
3837
Args:
3938
json_file: Path to known_good.json file
4039
@@ -49,39 +48,34 @@ def parse_known_good(json_file="./known_good.json"):
4948
sys.exit(1)
5049

5150
try:
52-
with open(json_path, "r") as f:
53-
data = json.load(f)
54-
except json.JSONDecodeError as e:
55-
print(f"Error: Failed to parse JSON: {e}", file=sys.stderr)
51+
# Use the centralized library to parse known_good.json
52+
known_good = load_known_good(json_path)
53+
except Exception as e:
54+
print(f"Error: Failed to parse known_good.json: {e}", file=sys.stderr)
5655
sys.exit(1)
5756

5857
# Extract target_sw modules
59-
modules = data.get("modules", {}).get("target_sw", {})
58+
modules = known_good.modules.get("target_sw", {})
6059

6160
# Transform modules into repository objects
6261
repos = []
6362
module_outputs = {}
6463

65-
for name, config in modules.items():
66-
repo_url = config.get("repo", "")
67-
version = config.get("version", "")
68-
branch = config.get("branch", "")
69-
hash_val = config.get("hash", "")
70-
71-
# Use version, branch, or hash (in that order of preference)
72-
ref = version or branch or hash_val
64+
for name, module in modules.items():
65+
repo_url = module.repo
66+
ref = module.version or module.branch or module.commit_hash
7367

7468
repo_obj = {"name": name, "url": repo_url, "version": ref, "path": f"repos/{name}"}
7569
repos.append(repo_obj)
7670

7771
# Store module outputs for GITHUB_OUTPUT compatibility
7872
module_outputs[f"{name}_url"] = repo_url
79-
if version:
80-
module_outputs[f"{name}_version"] = version
81-
if branch:
82-
module_outputs[f"{name}_branch"] = branch
83-
if hash_val:
84-
module_outputs[f"{name}_hash"] = hash_val
73+
if module.version:
74+
module_outputs[f"{name}_version"] = module.version
75+
if module.branch:
76+
module_outputs[f"{name}_branch"] = module.branch
77+
if module.commit_hash:
78+
module_outputs[f"{name}_hash"] = module.commit_hash
8579

8680
return repos, len(modules), module_outputs
8781

0 commit comments

Comments
 (0)