Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 456a77a

Browse files
Exclude languages (advanced-security#2)
* add support for C * excluded languages * fix issue with json parsing * add some print statements for TS * troubleshooting * ts * try split * try split * remove print * trying quotes * print statements for ts * converting exclude to a set * fix with strip and add log * change excluded languages to exclude * updated documentation
1 parent ca3768b commit 456a77a

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The default Actions workflow for CodeQL auto-populates the job matrix with your
88

99
This action reads the repository languages API and adds all supported languages to the job matrix. No additional configuration is required.
1010

11+
Learn more about the supported CodeQL languages [here](https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed)
12+
1113
## How to use this action
1214

1315
Call this action before defining the CodeQL analyze job strategy, then set the matrix to the output from the action: `${{ fromJSON(needs.create-matrix.outputs.matrix) }}`
@@ -51,9 +53,6 @@ jobs:
5153
fail-fast: false
5254
matrix:
5355
language: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
54-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'kotlin' ]
55-
# Learn more:
56-
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
5756

5857
steps:
5958
- name: Checkout repository
@@ -74,6 +73,27 @@ jobs:
7473
with:
7574
category: "/language:${{matrix.language}}"
7675
```
76+
77+
### Excluding CodeQL Languages
78+
It's possible you may choose to exclude specific languages from your CodeQL scans. In that canse, use the `exclude` input.
79+
80+
Example:
81+
```
82+
create-matrix:
83+
runs-on: ubuntu-latest
84+
outputs:
85+
matrix: ${{ steps.set-matrix.outputs.languages }}
86+
steps:
87+
- name: Get languages from repo
88+
id: set-matrix
89+
uses: advanced-security/set-codeql-language-matrix@v1
90+
with:
91+
access-token: ${{ secrets.GITHUB_TOKEN }}
92+
endpoint: ${{ github.event.repository.languages_url }}
93+
exclude: 'java, python'
94+
95+
```
96+
7797
## License
7898

7999
This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE.md) for the full terms.

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
endpoint:
99
description: 'languages API endpoint'
1010
required: true
11+
exclude:
12+
description: 'Use a comma separated list here to exclude specific languges from your CodeQL scan. Example: "python, java"'
13+
required: false
1114
outputs:
1215
languages:
1316
description: 'List of languages that will set the job matrix'
@@ -17,5 +20,5 @@ runs:
1720
args:
1821
- ${{ inputs.access-token }}
1922
- ${{ inputs.endpoint }}
20-
- ${{ inputs.codeql-languages }}
23+
- ${{ inputs.exclude }}
2124

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh -l
22

33
# kick off the command
4-
python /main.py $1 $2 $3
4+
python /main.py $1 $2 "$3"

main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
token = sys.argv[1]
77
endpoint = sys.argv[2]
8+
exclude = sys.argv[3]
89
codeql_languages = ["cpp", "csharp", "go", "java", "javascript", "python", "ruby"]
910

1011

@@ -22,10 +23,19 @@ def build_languages_list(languages):
2223
languages[i] = ("csharp")
2324
if languages[i] == "c++":
2425
languages[i] = ("cpp")
26+
if languages[i] == "c":
27+
languages[i] = ("cpp")
2528

2629
intersection = list(set(languages) & set(codeql_languages))
2730
return intersection
2831

32+
# return a list of objects from language list if they are not in the exclude list
33+
def exclude_languages(language_list):
34+
excluded = [x.strip() for x in exclude.split(',')]
35+
output = list(set(language_list).difference(excluded))
36+
print("languages={}".format(output))
37+
return output
38+
2939
# Set the output of the action
3040
def set_action_output(output_name, value) :
3141
if "GITHUB_OUTPUT" in os.environ :
@@ -35,7 +45,8 @@ def set_action_output(output_name, value) :
3545

3646
def main():
3747
languages = get_languages()
38-
output = build_languages_list(languages)
48+
language_list = build_languages_list(languages)
49+
output = exclude_languages(language_list)
3950
set_action_output("languages", json.dumps(output))
4051

4152
if __name__ == '__main__':

0 commit comments

Comments
 (0)