forked from meshery/meshery
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (125 loc) · 4.65 KB
/
Copy pathcodeql-analysis.yml
File metadata and controls
138 lines (125 loc) · 4.65 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
name: "CodeQL"
on:
workflow_dispatch:
inputs:
debug_mode:
description: "Enable verbose workflow context logging"
required: false
default: false
type: boolean
schedule:
- cron: '26 22 * * 6'
jobs:
analyze:
name: Analyze (${{ matrix.language }})
if: github.repository == 'meshery/meshery'
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: javascript
build-mode: none
- language: go
build-mode: manual
steps:
- name: 🔍 Introspect Inputs
uses: actions/github-script@v8
with:
script: |
core.startGroup('Workflow Inputs and Context');
core.info(`debug_mode: ${JSON.stringify(context.payload.inputs?.debug_mode ?? false)}`);
core.info(`repository: ${context.repo.owner}/${context.repo.repo}`);
core.info(`event_name: ${context.eventName}`);
core.info(`actor: ${context.actor}`);
core.info(`ref: ${context.ref}`);
core.info(`sha: ${context.sha}`);
core.info(`run_id: ${context.runId}`);
core.info(`language: ${process.env.CODEQL_LANGUAGE}`);
core.endGroup();
env:
CODEQL_LANGUAGE: ${{ matrix.language }}
- name: Checkout repository
uses: actions/checkout@v6
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql-config.yml
build-mode: ${{ matrix.build-mode }}
- name: Build Go
if: matrix.language == 'go'
run: |
go build -v ./...
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
- name: Comment on associated pull requests when analysis fails
if: failure()
uses: actions/github-script@v8
env:
CODEQL_LANGUAGE: ${{ matrix.language }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
script: |
const { owner, repo } = context.repo;
const associatedPullRequests = await github.paginate(
github.rest.repos.listPullRequestsAssociatedWithCommit,
{
owner,
repo,
commit_sha: context.sha,
},
);
const openPullRequests = associatedPullRequests.filter((pullRequest) => pullRequest.state === 'open');
if (!openPullRequests.length) {
core.info('No associated open pull requests found for this commit.');
return;
}
const body = [
`⚠️ CodeQL analysis failed for \`${process.env.CODEQL_LANGUAGE}\` on \`${context.sha.slice(0, 7)}\`.`,
'',
`- Workflow: ${context.workflow}`,
`- Event: ${context.eventName}`,
`- Actor: ${context.actor}`,
`- Run: ${process.env.RUN_URL}`,
].join('\n');
for (const pullRequest of openPullRequests) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: pullRequest.number,
body,
});
}
- name: 🚨 Email Alert on Failure
# 1. Map the secrets to environment variables first
env:
MAIL_USER: ${{ secrets.MAIL_USERNAME }}
MAIL_PASS: ${{ secrets.MAIL_PASSWORD }}
# 2. Check the 'env' context instead of the 'secrets' context
if: failure() && env.MAIL_USER != '' && env.MAIL_PASS != ''
uses: dawidd6/action-send-mail@v7
with:
server_address: smtp.gmail.com
server_port: 465
secure: true
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: "Workflow Failed: ${{ github.workflow }} (${{ matrix.language }})"
from: '"Meshery" <no-reply@meshery.io>'
to: maintainers@meshery.io
body: |
Repository: ${{ github.repository }}
Workflow: ${{ github.workflow }}
Job: ${{ github.job }}
Language: ${{ matrix.language }}
Event: ${{ github.event_name }}
Actor: ${{ github.actor }}
Run URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}