Skip to content

Commit 2414243

Browse files
Mrtenzwitmicko
andauthored
refactor: Require ref and clean up a little bit (#56)
* Try without scanner-ref * Remove scanner-ref from more places * Add local workflow call * Remove steps * Add permissions * Clean up a bit * Add ref back * Specify ref * Fix monorepo path * Rename ref back to scanner-ref * Add analyse code to all-jobs-completed * Fix consistency * Update README * Revert checkout step rename * Add missing repository * chore: bump semgrep upload * Revert MONOREPO_PATH * Hardcode monorepo path --------- Co-authored-by: witmicko <witmicko@users.noreply.github.com> Co-authored-by: witmicko <mjogrodniczak@gmail.com>
1 parent 47295f0 commit 2414243

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
run: ${{ steps.download-actionlint.outputs.executable }} -color
2020
shell: bash
2121

22+
analyse-code:
23+
name: Analyse code
24+
uses: ./.github/workflows/security-scan.yml
25+
permissions:
26+
actions: read
27+
contents: read
28+
security-events: write
29+
with:
30+
scanner-ref: ${{ github.ref }}
31+
2232
build-lint-test:
2333
name: Build, lint, and test
2434
uses: ./.github/workflows/build-lint-test.yml
@@ -29,6 +39,7 @@ jobs:
2939
runs-on: ubuntu-latest
3040
needs:
3141
- check-workflows
42+
- analyse-code
3243
- build-lint-test
3344
outputs:
3445
PASSED: ${{ steps.set-output.outputs.PASSED }}

.github/workflows/security-scan.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ on:
1111
description: 'Repository that requested the scan'
1212
required: false
1313
type: string
14-
scanner_ref:
15-
description: 'Reference to the scanner repository'
16-
required: false
17-
type: string
18-
default: 'main'
19-
languages_config:
14+
default: ${{ github.repository }}
15+
languages-config:
2016
description: |
2117
Optional: JSON array of language configurations to override/supplement repo config file.
2218
Auto-detects languages and loads repo-specific config from packages/codeql-action/repo-configs/${repo}.cjs.
@@ -38,22 +34,26 @@ on:
3834
required: false
3935
type: string
4036
default: ''
41-
paths_ignored:
37+
scanner-ref:
38+
description: 'The git ref of the scanner to use'
39+
required: true
40+
type: string
41+
paths-ignored:
4242
description: 'Multi-line list of paths to ignore during scan (one path per line, supports glob patterns)'
4343
required: false
4444
type: string
4545
default: ''
46-
rules_excluded:
46+
rules-excluded:
4747
description: 'Comma delimited IDs of rules to exclude'
4848
required: false
4949
type: string
5050
default: ''
51-
project_metrics_token:
51+
project-metrics-token:
5252
description: 'Analytics token to log failed builds'
5353
required: false
5454
type: string
5555
default: ''
56-
slack_webhook:
56+
slack-webhook:
5757
description: 'Slack webhook for notifications'
5858
required: false
5959
type: string
@@ -65,6 +65,7 @@ env:
6565
jobs:
6666
# Detect languages and create matrix
6767
setup:
68+
name: Setup
6869
runs-on: ubuntu-latest
6970
outputs:
7071
matrix: ${{ steps.detect-languages.outputs.matrix }}
@@ -73,7 +74,7 @@ jobs:
7374
uses: actions/checkout@v4
7475
with:
7576
repository: MetaMask/action-security-code-scanner
76-
ref: ${{ inputs.scanner_ref || 'main' }}
77+
ref: ${{ inputs.scanner-ref }}
7778
path: ${{ env.MONOREPO_PATH }}
7879

7980
- name: Checkout target repository
@@ -87,10 +88,11 @@ jobs:
8788
uses: ./.security-scanner/packages/language-detector
8889
with:
8990
repo: ${{ inputs.repo }}
90-
languages_config: ${{ inputs.languages_config }}
91+
languages_config: ${{ inputs.languages-config }}
9192

9293
# Run CodeQL analysis for each detected language
9394
codeql-analysis:
95+
name: CodeQL analysis
9496
needs: setup
9597
if: ${{ fromJSON(needs.setup.outputs.matrix).include[0] != null }}
9698
strategy:
@@ -106,7 +108,7 @@ jobs:
106108
uses: actions/checkout@v4
107109
with:
108110
repository: MetaMask/action-security-code-scanner
109-
ref: ${{ inputs.scanner_ref || 'main' }}
111+
ref: ${{ inputs.scanner-ref }}
110112
path: ${{ env.MONOREPO_PATH }}
111113

112114
- name: Checkout target repository
@@ -120,15 +122,16 @@ jobs:
120122
with:
121123
repo: ${{ inputs.repo }}
122124
language: ${{ matrix.language }}
123-
paths_ignored: ${{ inputs.paths_ignored }}
124-
rules_excluded: ${{ inputs.rules_excluded }}
125+
paths_ignored: ${{ inputs.paths-ignored }}
126+
rules_excluded: ${{ inputs.rules-excluded }}
125127
build_mode: ${{ matrix.build_mode }}
126128
build_command: ${{ matrix.build_command }}
127129
version: ${{ matrix.version }}
128130
distribution: ${{ matrix.distribution }}
129131

130132
# Run Semgrep analysis once for all languages
131133
semgrep-analysis:
134+
name: Semgrep analysis
132135
needs: setup
133136
runs-on: ubuntu-latest
134137
permissions:
@@ -140,7 +143,7 @@ jobs:
140143
uses: actions/checkout@v4
141144
with:
142145
repository: MetaMask/action-security-code-scanner
143-
ref: ${{ inputs.scanner_ref || 'main' }}
146+
ref: ${{ inputs.scanner-ref }}
144147
path: ${{ env.MONOREPO_PATH }}
145148

146149
- name: Checkout target repository
@@ -152,19 +155,20 @@ jobs:
152155
- name: Run Semgrep Analysis
153156
uses: ./.security-scanner/packages/semgrep-action
154157
with:
155-
paths_ignored: ${{ inputs.paths_ignored }}
158+
paths_ignored: ${{ inputs.paths-ignored }}
156159

157160
# Collect results and handle notifications
158161
finalize:
162+
name: Finalize scans and notify
159163
needs: [codeql-analysis, semgrep-analysis]
160164
if: always()
161165
runs-on: ubuntu-latest
162166
env:
163-
SLACK_WEBHOOK: ${{ inputs.slack_webhook }}
164-
PROJECT_METRICS_TOKEN: ${{ inputs.project_metrics_token }}
167+
SLACK_WEBHOOK: ${{ inputs.slack-webhook }}
168+
PROJECT_METRICS_TOKEN: ${{ inputs.project-metrics-token }}
165169
REPO: ${{ inputs.repo }}
166170
steps:
167-
- name: Determine Overall Scan Success
171+
- name: Determine overall scan result
168172
id: scan-result
169173
env:
170174
CODEQL_RESULT: ${{ needs.codeql-analysis.result }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ on: [push, pull_request]
2323

2424
jobs:
2525
security-scan:
26-
uses: metamask/security-codescanner-monorepo/.github/workflows/security-scan.yml@main
26+
uses: MetaMask/action-security-code-scanner/.github/workflows/security-scan.yml@v2
2727
with:
28-
repo: ${{ github.repository }}
28+
scanner-ref: v2
2929
```
3030
3131
The workflow will:

packages/semgrep-action/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ runs:
3636
continue-on-error: true
3737

3838
- name: Upload Semgrep Results to GitHub
39-
uses: github/codeql-action/upload-sarif@v3
39+
uses: github/codeql-action/upload-sarif@v4
4040
with:
4141
sarif_file: semgrep-results.sarif
4242
checkout_path: ${{ github.workspace }}

0 commit comments

Comments
 (0)