Skip to content

Commit 04ef077

Browse files
ci: harden CodeQL language detection
1 parent 6535243 commit 04ef077

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎.github/workflows/codeql.yml‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ jobs:
1717
- id: lang
1818
shell: bash
1919
run: |
20+
set -euo pipefail
2021
langs=''
21-
find . -name '*.py' -print -quit | grep -q . && langs="$langs python"
22-
find . ( -name '*.js' -o -name '*.ts' -o -name '*.tsx' ) -print -quit | grep -q . && langs="$langs javascript-typescript"
22+
[ -n "$(find . -name '*.py' -print -quit)" ] && langs="$langs python"
23+
[ -n "$(find . -name '*.js' -print -quit)" ] || [ -n "$(find . -name '*.ts' -print -quit)" ] && langs="$langs javascript-typescript"
2324
[ -f go.mod ] && langs="$langs go"
2425
[ -f Cargo.toml ] && langs="$langs rust"
2526
[ -f pom.xml ] || [ -f build.gradle ] && langs="$langs java-kotlin"
26-
find . ( -name '*.c' -o -name '*.cpp' -o -name '*.h' ) -print -quit | grep -q . && langs="$langs c-cpp"
27+
[ -n "$(find . -name '*.c' -print -quit)" ] || [ -n "$(find . -name '*.cpp' -print -quit)" ] && langs="$langs c-cpp"
2728
[ -n "$langs" ] || langs=' python'
28-
langs="${langs# }"
29-
echo "languages=$(printf '%s
30-
' $langs | jq -Rsc 'split("\n")[:-1]')" >> "$GITHUB_OUTPUT"
29+
json="$(printf '%s\n' $langs | jq -Rsc 'split("
30+
") | map(select(length > 0))')"
31+
echo "languages=$json" >> "$GITHUB_OUTPUT"
3132
analyze:
3233
needs: detect
3334
strategy:

0 commit comments

Comments
 (0)