Skip to content

Commit 7e1eea1

Browse files
authored
Merge pull request #11 from advanced-security/jsinglet/ci-cd-additions
CI/CD Gating Functions
2 parents a362800 + b9b49ee commit 7e1eea1

File tree

17 files changed

+211
-38
lines changed

17 files changed

+211
-38
lines changed

.github/actions/install-qlt/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ runs:
2727
env:
2828
RUNNER_OS: ${{ runner.os }}
2929
RUNNER_TEMP: ${{ runner.temp }}
30-
GITHUB_TOKEN: ${{ github.token }}
3130
ADD_TO_PATH: ${{ inputs.add-to-path }}
3231
QLT_VERSION: ${{ inputs.qlt-version }}
3332
QLT_HOME: ${{ inputs.qlt-home }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: ⚙️ Validate Workflow Files
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
workflow_dispatch:
11+
12+
jobs:
13+
validate-workflow-files:
14+
name: Validate Workflow Files
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
20+
- name: Install QLT
21+
id: install-qlt
22+
uses: ./.github/actions/install-qlt-local
23+
with:
24+
qlt-version: 'latest'
25+
add-to-path: true
26+
27+
- name: Validate QLT Installation
28+
shell: bash
29+
run: |
30+
echo -e "Checking QLT Version:"
31+
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
32+
qlt version
33+
34+
- name: Generate Workflow Files (Test Feature)
35+
shell: bash
36+
run: |
37+
if ! qlt test init --use-runner ubuntu-latest --num-threads 4 --language cpp --automation-type actions --development --overwrite-existing ; then
38+
echo "Failed to generate test workflow files."
39+
exit 1
40+
fi
41+
42+
- name: Generate Workflow Files (Validation Feature)
43+
shell: bash
44+
run: |
45+
if ! qlt validation init --use-runner ubuntu-latest --language cpp --automation-type actions --development --overwrite-existing ; then
46+
echo "Failed to generate validation workflow files."
47+
exit 1
48+
fi
49+
50+
- name: Check Git Clean Status
51+
shell: bash
52+
run: |
53+
if git diff --quiet .github ; then
54+
echo "Git is clean - generation is as expected."
55+
else
56+
echo "Some files have changed - please check for regressions."
57+
git status
58+
git diff .github
59+
exit 1
60+
fi
61+
62+

.github/workflows/DEMO-run-codeql-unit-tests-cpp.yml renamed to .github/workflows/run-codeql-unit-tests-cpp.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ⚙️ DEMO CodeQL - Run Unit Tests (cpp)
1+
name: ⚙️ CodeQL - Run Unit Tests (cpp)
22

33

44
on:
@@ -20,6 +20,7 @@ jobs:
2020
- name: Checkout repository
2121
uses: actions/checkout@v3
2222

23+
2324
- name: Install QLT
2425
id: install-qlt
2526
uses: ./.github/actions/install-qlt-local
@@ -32,6 +33,7 @@ jobs:
3233
run: |
3334
qlt test run get-matrix --os-version ubuntu-latest --base example/
3435
36+
3537
run-test-suites:
3638
name: Run Unit Tests
3739
needs: create-unit-test-matrix
@@ -45,13 +47,15 @@ jobs:
4547
- name: Checkout repository
4648
uses: actions/checkout@v3
4749

50+
4851
- name: Install QLT
4952
id: install-qlt
5053
uses: ./.github/actions/install-qlt-local
5154
with:
5255
qlt-version: 'latest'
5356
add-to-path: true
54-
57+
58+
5559
- name: Install CodeQL
5660
id: install-codeql
5761
uses: ./.github/actions/install-codeql
@@ -71,11 +75,13 @@ jobs:
7175
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
7276
qlt version
7377
78+
7479
- name: Install QL Packs
7580
shell: bash
7681
run: |
7782
qlt query run install-packs --base example/
7883
84+
7985
- name: Run test suites
8086
id: run-test-suites
8187
env:
@@ -86,11 +92,14 @@ jobs:
8692
RUNNER_TMP: ${{ runner.temp }}
8793
shell: bash
8894
run: >
89-
qlt test run execute-unit-tests
95+
96+
97+
qlt test run execute-unit-tests
98+
--codeql-args "--threads=0"
9099
--num-threads 4
91100
--language cpp
92101
--runner-os $RUNNER_OS
93-
--work-dir $RUNNER_TMP
102+
--work-dir $RUNNER_TMP
94103
--base example/
95104
96105
@@ -107,20 +116,24 @@ jobs:
107116
needs: [run-test-suites]
108117
runs-on: ubuntu-latest
109118
steps:
119+
110120
- name: Checkout repository
111121
uses: actions/checkout@v3
112122

123+
113124
- name: Install QLT
114125
id: install-qlt
115126
uses: ./.github/actions/install-qlt-local
116127
with:
117128
qlt-version: 'latest'
118129
add-to-path: true
119130

131+
120132
- name: Collect test results
121133
uses: actions/download-artifact@v2
122134

123135
- name: Validate test results
124136
run: |
125137
qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY
126-
qlt test run validate-unit-tests --results-directory .
138+
qlt test run validate-unit-tests --results-directory .
139+

.github/workflows/DEMO-validate-codeql-queries-cpp.yml renamed to .github/workflows/validate-codeql-queries-cpp.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ⚙️ DEMO CodeQL - Validate Queries (cpp)
1+
name: ⚙️ CodeQL - Validate Queries (cpp)
22

33
on:
44
push:
@@ -19,6 +19,7 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v3
2121

22+
2223
- name: Install QLT
2324
id: install-qlt
2425
uses: ./.github/actions/install-qlt-local
@@ -31,6 +32,7 @@ jobs:
3132
run: |
3233
qlt test run get-matrix --os-version ubuntu-latest --base example/
3334
35+
3436
validate-queries:
3537
name: Validate Queries
3638
needs: create-matrix
@@ -44,11 +46,15 @@ jobs:
4446
- name: Checkout repository
4547
uses: actions/checkout@v3
4648

49+
50+
4751
- name: Install QLT
52+
id: install-qlt
4853
uses: ./.github/actions/install-qlt-local
4954
with:
5055
qlt-version: 'latest'
5156
add-to-path: true
57+
5258

5359
- name: Install CodeQL
5460
uses: ./.github/actions/install-codeql
@@ -68,14 +74,16 @@ jobs:
6874
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
6975
qlt version
7076
77+
7178
- name: Install QL Packs
7279
shell: bash
7380
run: |
7481
qlt query run install-packs --base example/
7582
83+
7684
- name: Run validation tests
7785
shell: bash
7886
run: >
79-
qlt validation run check-queries --pretty-print --language cpp --base example/ >> $GITHUB_STEP_SUMMARY
87+
qlt validation run check-queries --pretty-print --language cpp --base example/ >> $GITHUB_STEP_SUMMARY
8088
81-
qlt validation run check-queries --language cpp --base example/
89+
qlt validation run check-queries --language cpp --base example/

src/CodeQLToolkit.Core/Main.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static async Task<int> Main(string[] args)
2727
// Add global option for the root directory
2828
rootCommand.AddGlobalOption(Globals.BasePathOption);
2929
rootCommand.AddGlobalOption(Globals.AutomationTypeOption);
30+
rootCommand.AddGlobalOption(Globals.Development);
3031

3132
var versionCommand = new Command("version", "Get the current tool version.");
3233
rootCommand.Add(versionCommand);
@@ -49,9 +50,7 @@ public static async Task<int> Main(string[] args)
4950
// Register the `Validation` feature
5051
ValidationFeatureMain.Instance.Register(rootCommand);
5152

52-
await rootCommand.InvokeAsync(args);
53-
54-
return 0;
53+
return await rootCommand.InvokeAsync(args);
5554
}
5655
}
5756
}

src/CodeQLToolkit.Features/Templates/Test/Actions/install-qlt.liquid

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ inputs:
1414
required: false
1515
default: 'true'
1616

17-
token:
18-
description: |
19-
Token to use for auth
20-
required: true
21-
22-
2317
outputs:
2418
qlt-home:
2519
description: 'The directory containing the QLT installation'
@@ -33,8 +27,6 @@ runs:
3327
env:
3428
RUNNER_OS: ${{ runner.os }}
3529
RUNNER_TEMP: ${{ runner.temp }}
36-
# GITHUB_TOKEN: ${{ github.token }}
37-
GITHUB_TOKEN: ${{ inputs.token }}
3830
ADD_TO_PATH: ${{ inputs.add-to-path }}
3931
QLT_VERSION: ${{ inputs.qlt-version }}
4032
QLT_HOME: ${{ inputs.qlt-home }}

src/CodeQLToolkit.Features/Templates/Test/Actions/run-unit-tests.liquid

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,32 @@ jobs:
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v3
22+
{% endraw %}
23+
{% if dev_mode %}
24+
- name: Install QLT
25+
id: install-qlt
26+
uses: ./.github/actions/install-qlt-local
27+
with:
28+
qlt-version: 'latest'
29+
add-to-path: true
2230

31+
- name: Export unit test matrix
32+
id: export-unit-test-matrix
33+
run: |
34+
qlt test run get-matrix --os-version {{ use_runner }} --base example/
35+
{% else %}
2336
- name: Install QLT
2437
id: install-qlt
2538
uses: ./.github/actions/install-qlt
2639
with:
2740
qlt-version: 'latest'
2841
add-to-path: true
29-
{% endraw %}
42+
3043
- name: Export unit test matrix
3144
id: export-unit-test-matrix
3245
run: |
3346
qlt test run get-matrix --os-version {{ use_runner }}
47+
{% endif %}
3448
{% raw %}
3549
run-test-suites:
3650
name: Run Unit Tests
@@ -44,14 +58,23 @@ jobs:
4458
steps:
4559
- name: Checkout repository
4660
uses: actions/checkout@v3
47-
61+
{% endraw %}
62+
{% if dev_mode %}
63+
- name: Install QLT
64+
id: install-qlt
65+
uses: ./.github/actions/install-qlt-local
66+
with:
67+
qlt-version: 'latest'
68+
add-to-path: true
69+
{% else %}
4870
- name: Install QLT
4971
id: install-qlt
5072
uses: ./.github/actions/install-qlt
5173
with:
5274
qlt-version: 'latest'
5375
add-to-path: true
54-
76+
{% endif %}
77+
{% raw %}
5578
- name: Install CodeQL
5679
id: install-codeql
5780
uses: ./.github/actions/install-codeql
@@ -70,12 +93,19 @@ jobs:
7093
echo -e "Checking QLT Version:"
7194
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
7295
qlt version
73-
96+
{% endraw %}
97+
{% if dev_mode %}
98+
- name: Install QL Packs
99+
shell: bash
100+
run: |
101+
qlt query run install-packs --base example/
102+
{% else %}
74103
- name: Install QL Packs
75104
shell: bash
76105
run: |
77106
qlt query run install-packs
78-
107+
{% endif %}
108+
{% raw %}
79109
- name: Run test suites
80110
id: run-test-suites
81111
env:
@@ -87,12 +117,22 @@ jobs:
87117
shell: bash
88118
run: >
89119
{% endraw %}
120+
{% if dev_mode %}
121+
qlt test run execute-unit-tests
122+
--codeql-args "{{ codeql_args }}"
123+
--num-threads {{ num_threads }}
124+
--language {{ language }}
125+
--runner-os $RUNNER_OS
126+
--work-dir $RUNNER_TMP
127+
--base example/
128+
{% else %}
90129
qlt test run execute-unit-tests
91130
--codeql-args "{{ codeql_args }}"
92131
--num-threads {{ num_threads }}
93132
--language {{ language }}
94133
--runner-os $RUNNER_OS
95134
--work-dir $RUNNER_TMP
135+
{% endif %}
96136
{% raw %}
97137
- name: Upload test results
98138
uses: actions/upload-artifact@v2
@@ -110,14 +150,23 @@ jobs:
110150
111151
- name: Checkout repository
112152
uses: actions/checkout@v3
113-
153+
{% endraw %}
154+
{% if dev_mode %}
155+
- name: Install QLT
156+
id: install-qlt
157+
uses: ./.github/actions/install-qlt-local
158+
with:
159+
qlt-version: 'latest'
160+
add-to-path: true
161+
{% else %}
114162
- name: Install QLT
115163
id: install-qlt
116164
uses: ./.github/actions/install-qlt
117165
with:
118166
qlt-version: 'latest'
119167
add-to-path: true
120-
168+
{% endif %}
169+
{% raw %}
121170
- name: Collect test results
122171
uses: actions/download-artifact@v2
123172

0 commit comments

Comments
 (0)