Skip to content

Commit fe6adf9

Browse files
committed
fix parsing
1 parent 2936006 commit fe6adf9

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

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

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,38 @@ jobs:
3434
- name: Checkout central repository
3535
uses: actions/checkout@v4
3636

37-
- name: Parse pinned repository versions
37+
- name: Parse known_good.json and create repos.json
3838
id: parse-repos
3939
run: |
40-
4140
sudo apt-get update && sudo apt-get install -y jq
4241
JSON_FILE="./known_good.json"
4342
4443
# Check if the file exists
4544
if [ ! -f "$JSON_FILE" ]; then
46-
echo "Fehler: Die Datei '$JSON_FILE' wurde nicht gefunden."
45+
echo "Error file not found '$JSON_FILE' "
46+
ls -la .
4747
exit 1
4848
fi
4949
50-
50+
# Create repos.json from known_good.json
51+
# This jq command transforms the 'modules' object into an array of repository objects
52+
# with 'name', 'url', 'version' (branch/tag/hash), and 'path'.
53+
jq '[.modules | to_entries[] | {
54+
name: .key,
55+
url: .value.repo,
56+
version: (.value.branch // .value.version // .value.hash),
57+
path: ("repos/" + .key)
58+
}]' "$JSON_FILE" > repos.json
59+
60+
echo "Generated repos.json:"
61+
cat repos.json
62+
echo "" # Add a newline for better readability
63+
64+
# The following GITHUB_OUTPUT variables are set for each module.
65+
# These might be useful for other steps, but are not directly used by the 'checkout-repos' step
66+
# which now reads 'repos.json' directly.
5167
echo "MODULE_COUNT=$(jq '.modules | length' "$JSON_FILE")" >> $GITHUB_OUTPUT
5268
53-
5469
jq -c '.modules | to_entries[]' "$JSON_FILE" | while read -r module_entry; do
5570
module_name=$(echo "$module_entry" | jq -r '.key')
5671
repo_url=$(echo "$module_entry" | jq -r '.value.repo // empty')
@@ -76,30 +91,47 @@ jobs:
7691
- name: Checkout all pinned repositories
7792
id: checkout-repos
7893
run: |
79-
# Install jq for JSON parsing
80-
sudo apt-get install -y jq
94+
# jq is already installed by the previous step.
8195
82-
# Read repositories from JSON file
96+
# Read repositories from the repos.json file created by the previous step
8397
repos=$(cat repos.json)
84-
repo_count=$(echo $repos | jq length)
98+
repo_count=$(echo "$repos" | jq length)
8599
100+
# Initialize an empty string for paths to be outputted
101+
repo_paths_output=""
102+
86103
for i in $(seq 0 $((repo_count-1))); do
87-
name=$(echo $repos | jq -r ".[$i].name")
88-
url=$(echo $repos | jq -r ".[$i].url")
89-
version=$(echo $repos | jq -r ".[$i].version")
90-
path=$(echo $repos | jq -r ".[$i].path")
104+
name=$(echo "$repos" | jq -r ".[$i].name")
105+
url=$(echo "$repos" | jq -r ".[$i].url")
106+
ref=$(echo "$repos" | jq -r ".[$i].version") # This can be a branch, tag, or commit hash
107+
path=$(echo "$repos" | jq -r ".[$i].path") # e.g., "repos/score_baselibs"
91108
92-
echo "Checking out $name ($version) to $path"
109+
echo "Checking out $name ($ref) to $path"
93110
94-
# Checkout the specific version/branch
95-
git clone --depth 1 --branch $version $url $path
111+
# Create the parent directory if it doesn't exist
112+
mkdir -p "$(dirname "$path")"
113+
114+
# Check if 'ref' looks like a commit hash (e.g., 40 hex characters)
115+
# This is a heuristic; a more robust check might involve fetching refs first.
116+
if [[ "$ref" =~ ^[0-9a-fA-F]{40}$ ]]; then
117+
echo " Detected commit hash. Cloning and then checking out."
118+
git clone "$url" "$path"
119+
(cd "$path" && git checkout "$ref")
120+
else
121+
echo " Detected branch/tag. Cloning with --branch."
122+
git clone --depth 1 --branch "$ref" "$url" "$path"
123+
fi
96124
97-
# Store paths for later use
98-
echo "$path" >> repo-paths.txt
125+
# Append the path to the list, separated by commas
126+
if [ -z "$repo_paths_output" ]; then
127+
repo_paths_output="$path"
128+
else
129+
repo_paths_output="$repo_paths_output,$path"
130+
fi
99131
done
100132
101133
# Output all paths as a single variable
102-
echo "repo_paths=$(cat repo-paths.txt | tr '\n' ',')" >> $GITHUB_OUTPUT
134+
echo "repo_paths=$repo_paths_output" >> $GITHUB_OUTPUT
103135
104136
- name: Initialize CodeQL for all repositories
105137
uses: github/codeql-action/init@v4

0 commit comments

Comments
 (0)