Skip to content

Commit 4c80737

Browse files
Add GitHub workflow to scan project with CodeQL
- Set up CodeQL analysis workflow to scan both the Kubebuilder CLI and generated projects in 'testdata'. - Run 'make install' in the root directory to build and install the Kubebuilder CLI as part of the setup. - For sample projects in 'testdata' (e.g., project-v4, project-v4-multigroup, and project-v4-with-plugins), add a step to run 'make all' to ensure all resources are generated and ready for analysis. - Configure the manual build mode for Go projects in 'testdata' to run 'make manifests' and 'make build' if autobuild is insufficient.
1 parent f7a02ad commit 4c80737

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "CodeQL Advanced"
2+
3+
on:
4+
# We are checking master and book-v4 because book-v4 has always the code
5+
# from the latest release
6+
push:
7+
branches: ["master", "book-v4"]
8+
pull_request:
9+
branches: ["master", "book-v4"]
10+
schedule:
11+
- cron: '30 20 * * 1' # Runs a periodic scan every Monday at 8:30 PM
12+
13+
jobs:
14+
analyze:
15+
name: Analyze (${{ matrix.language }})
16+
runs-on: ubuntu-latest
17+
permissions:
18+
security-events: write
19+
packages: read
20+
actions: read
21+
contents: read
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- language: go
28+
build-mode: autobuild
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Go
35+
uses: actions/setup-go@v4
36+
with:
37+
go-version: '1.22'
38+
39+
- name: Install Kubebuilder tools
40+
run: |
41+
go install sigs.k8s.io/controller-tools/cmd/[email protected]
42+
go install sigs.k8s.io/kustomize/kustomize/[email protected]
43+
44+
- name: Build and install Kubebuilder CLI
45+
run: make install
46+
47+
# Adicione a etapa go mod tidy antes do make all
48+
- name: Build sample projects in testdata
49+
run: |
50+
for dir in testdata/*; do
51+
if [ -d "$dir" ]; then
52+
(cd "$dir" && go mod tidy && make all)
53+
fi
54+
done
55+
56+
- name: Initialize CodeQL
57+
uses: github/codeql-action/init@v3
58+
with:
59+
languages: ${{ matrix.language }}
60+
build-mode: ${{ matrix.build-mode }}
61+
62+
- if: matrix.language == 'go' && matrix.build-mode == 'manual'
63+
shell: bash
64+
run: |
65+
for dir in testdata/*; do
66+
if [ -d "$dir" ]; then
67+
(cd "$dir" && go mod tidy && echo 'Running manual build commands for Go in sample project' && make manifests && make build)
68+
fi
69+
done
70+
71+
- name: Perform CodeQL Analysis
72+
uses: github/codeql-action/analyze@v3
73+
with:
74+
category: "/language:${{matrix.language}}"

0 commit comments

Comments
 (0)