-
-
Notifications
You must be signed in to change notification settings - Fork 153
207 lines (180 loc) · 7.76 KB
/
codeql.yml
File metadata and controls
207 lines (180 loc) · 7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: "CodeQL"
on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
types: [opened, labeled, unlabeled, synchronize]
schedule:
# runs on 19:17 every Tuesday
- cron: "27 19 * * 2"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["go", "javascript-typescript"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v4
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"
lint-golangci:
name: "Lint (golangci)"
runs-on:
- runs-on=${{github.run_id}}
- runner=terraform
- tag=atmos
- extras=s3-cache
- private=false
if: github.event_name == 'pull_request'
permissions:
# Required: allow read access to the content for analysis.
contents: read
# allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# allow write access to checks to allow the action to annotate code in the PR.
checks: write
# allow write access to security events to allow the action to upload SARIF files.
security-events: write
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0
# golangci-lint-action@v4.0.0+ requires explicit Go setup
# Without this step, the action may fail intermittently with
# "could not load export data" errors due to cache corruption
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
# Pre-populate module cache to prevent goanalysis_metalinter failures.
# Without this, the linter may fail with "could not load export data" errors.
# See: https://github.com/golangci/golangci-lint/issues/5437
- name: Download modules
run: go mod download
# Install the golangci-lint v2 CLI tool (not the linters themselves).
# This tool is needed to run `golangci-lint custom` which builds a custom binary
# that includes both standard linters AND our custom module plugins.
- name: Install golangci-lint v2 for custom build
run: |
# Pin to commit that fixes "-c advice.detachedHead=false" bug (PR #6206)
# https://github.com/golangci/golangci-lint/pull/6206
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@101ccaca0df22b2e36dd917ed5d0be423baa6298
# Build a custom golangci-lint binary with our lintroller plugin compiled in.
- name: Build custom golangci-lint with lintroller plugin
run: |
set -e
# Ensure lintroller module is ready
cd tools/lintroller && go mod tidy && cd ../..
# Build custom golangci-lint with plugins
golangci-lint custom
# Verify the custom binary was created
test -x ./custom-gcl || { echo "Error: custom-gcl not found or not executable"; exit 1; }
# Replace system binary with our custom one
mv ~/go/bin/golangci-lint ~/go/bin/golangci-lint.system
cp ./custom-gcl ~/go/bin/golangci-lint
chmod +x ~/go/bin/golangci-lint
golangci-lint --version
# Run the golangci-lint action using our custom binary with plugins.
#
# Key settings:
# - install-mode: none - Tells the action to use the binary already in PATH
# (our custom-gcl that we just installed)
# - only-new-issues: true - Only report issues in changed code
# - SARIF output - For GitHub Advanced Security / CodeQL integration
# - issues-exit-code: 0 - Always exit 0 so we upload SARIF to CodeQL
#
# The action provides:
# - Inline PR annotations for linting issues
# - Caching for faster runs
# - GitHub UI integration
#
# Our custom binary includes lintroller, so violations of:
# - os.MkdirTemp in tests (should use t.TempDir)
# - os.Setenv in tests (should use t.Setenv)
# - t.Setenv in defer blocks (should use os.Setenv)
# will appear in the SARIF output and GitHub Security tab.
- name: Run golangci-lint with lintroller plugin
uses: golangci/golangci-lint-action@v8.0.0
with:
version: 101ccaca0df22b2e36dd917ed5d0be423baa6298
install-mode: none
only-new-issues: true
args: >
--output.sarif.path=golangci-lint.sarif
--issues-exit-code=0
- name: Upload filtered SARIF results
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: golangci-lint.sarif
pr-semver-labels:
name: PR Semver Labels
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
# Checkout is required for local composite actions
- uses: actions/checkout@v4
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
# Remove Dependabot's auto-added semver labels
# Dependabot PRs should only have the 'no-release' label since
# dependency updates don't determine Atmos releases.
- name: Clean up Dependabot labels
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
uses: ./.github/actions/remove-dependabot-semver-labels
# Check for required semver labels
# Every PR must have exactly one: major, minor, patch, or no-release
- uses: mheap/github-action-required-labels@v5
with:
mode: exactly
count: 1
labels: |
major
minor
patch
no-release
add_comment: true
message: |
> [!WARNING]
> This PR is blocked from merging because a required semver label is missing.
> ```
> {{ provided }}
> ```
> You'll need to add one before this PR can be merged.