Skip to content

Commit b037b99

Browse files
refactor(sca): Separate linters and sca for rust (#46)
1 parent 94e2100 commit b037b99

File tree

13 files changed

+217
-84
lines changed

13 files changed

+217
-84
lines changed

.github/workflows/luacheck.yml renamed to .github/workflows/lua-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
workflow_dispatch: {}
1313

1414
jobs:
15-
test-luacheck:
15+
test-lua-lint:
1616
env:
1717
TEST_REPOSITORY: "${{github.repository_owner}}/atc-router"
1818
runs-on: ubuntu-latest
@@ -23,6 +23,6 @@ jobs:
2323
with:
2424
repository: ${{env.TEST_REPOSITORY}}
2525
path: ${{env.TEST_REPOSITORY}}
26-
- uses: ./code-check-actions/luacheck
26+
- uses: ./code-check-actions/lua-lint
2727
with:
2828
additional_args: '--no-default-config --config ${{env.TEST_REPOSITORY}}/.luacheckrc ${{env.TEST_REPOSITORY}}'

.github/workflows/rust-lint.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Rust Lint Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
tags:
11+
- '*'
12+
workflow_dispatch: {}
13+
14+
jobs:
15+
test-rust-lint:
16+
permissions:
17+
# required for all workflows
18+
security-events: write
19+
checks: write
20+
pull-requests: write
21+
# only required for workflows in private repositories
22+
actions: read
23+
contents: read
24+
env:
25+
TEST_REPOSITORY: "${{github.repository_owner}}/atc-router"
26+
runs-on: ubuntu-latest
27+
name: Rust Code Linting checks
28+
steps:
29+
- uses: actions/checkout@v3
30+
- uses: actions/checkout@v3
31+
with:
32+
repository: ${{env.TEST_REPOSITORY}}
33+
path: ${{env.TEST_REPOSITORY}}
34+
- uses: ./code-check-actions/rust-lint
35+
with:
36+
token: ${{secrets.GITHUB_TOKEN}}
37+
manifest_dir: ${{ github.workspace }}/${{env.TEST_REPOSITORY}}

.github/workflows/rustcheck.yml renamed to .github/workflows/rust-sca.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Rust SCA and Lint Test
1+
name: Rust SCA Test
22

33
on:
44
pull_request:
@@ -31,8 +31,8 @@ jobs:
3131
with:
3232
repository: ${{env.TEST_REPOSITORY}}
3333
path: ${{env.TEST_REPOSITORY}}
34-
- uses: ./code-check-actions/rustcheck
34+
- uses: ./security-actions/scan-rust
3535
with:
3636
asset_prefix: ${{env.TEST_REPOSITORY}}
37-
token: ${{secrets.GITHUB_TOKEN}}
38-
dir: ${{ github.workspace }}/${{env.TEST_REPOSITORY}}
37+
dir: ${{ github.workspace }}/${{env.TEST_REPOSITORY}}
38+
codeql_upload: false

.github/workflows/semgrep.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
repository: ${{env.TEST_REPOSITORY}}
3131
token: ${{secrets.GITHUB_TOKEN}}
3232
path: ${{env.TEST_REPOSITORY}}
33-
- uses: Scimia/public-shared-actions/code-check-actions/semgrep@main
33+
- uses: ./code-check-actions/semgrep
3434
with:
3535
additional_config: '--config p/rust'
36+
codeql_upload: false
3637

File renamed without changes.
File renamed without changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Rust clippy - Github Action
2+
3+
This action uses Rust Clippy for code quality checks
4+
5+
6+
The action runs the following:
7+
- Installs rust
8+
- Run `clippy` to identify linting and code quality checks
9+
10+
## Inputs
11+
12+
```yaml
13+
manifest_dir:
14+
description: 'Speicify a directory to be scanned'
15+
required: false
16+
default: '.'
17+
```
18+
19+
## Outputs:
20+
- Push: Commit check summary
21+
- PR: Github check Summary and PR annotations
22+
23+
24+
## Detailed example
25+
26+
```yaml
27+
name: Rust Code Quality
28+
29+
on:
30+
pull_request: {}
31+
workflow_dispatch: {}
32+
push:
33+
branches:
34+
- main
35+
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ github.ref }}
38+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
39+
40+
jobs:
41+
rust:
42+
name: Rust Clippy
43+
runs-on: ubuntu-20.04
44+
45+
permissions:
46+
# required for all workflows
47+
security-events: write
48+
checks: write
49+
pull-requests: write
50+
# only required for workflows in private repositories
51+
actions: read
52+
contents: read
53+
54+
if: (github.actor != 'dependabot[bot]')
55+
56+
steps:
57+
- name: Checkout source code
58+
uses: actions/checkout@v3
59+
60+
- name: Rust Check
61+
uses: Kong/public-shared-actions/code-check-actions/rust-lint@main
62+
with:
63+
token: ${{ secrets.GITHUB_TOKEN }}
64+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Rust Clippy
2+
description: Rust Linting using Clippy
3+
author: 'Kong'
4+
inputs:
5+
manifest_dir:
6+
description: 'Rust Manifest Directory'
7+
required: false
8+
default: '.'
9+
token:
10+
description: 'Github token to annotate files with findings'
11+
required: true
12+
13+
runs:
14+
using: composite
15+
steps:
16+
17+
- uses: actions-rs/toolchain@b2417cde72dcf67f306c0ae8e0828a81bf0b189f
18+
with:
19+
toolchain: stable
20+
components: clippy
21+
22+
- name: Set Job Metadata
23+
shell: bash
24+
id: meta
25+
env:
26+
manifest_dir: ${{ inputs.manifest_dir }}
27+
run: $GITHUB_ACTION_PATH/scripts/set-env.sh
28+
29+
- uses: Swatinem/rust-cache@v1
30+
31+
- uses: actions-rs/clippy-check@v1
32+
continue-on-error: true
33+
with:
34+
token: ${{ inputs.token }}
35+
args: --manifest-path ${{ steps.meta.outputs.manifest_path }} -- -W clippy::correctness -W clippy::cargo -W clippy::pedantic
36+
name: Rust Clippy Report
37+
38+
# - uses: actions-rs/cargo@ae10961054e4aa8b4aa7dffede299aaf087aa33b
39+
# continue-on-error: true
40+
# with:
41+
# command: install
42+
# args: "clippy-sarif sarif-fmt"
43+
44+
# - name: Run Cargo Clippy
45+
# shell: bash
46+
# continue-on-error: true
47+
# run: |
48+
# cargo clippy --manifest-path ${{ steps.meta.outputs.manifest_path }} --message-format=json -- -W clippy::correctness -W clippy::cargo -W clippy::pedantic | clippy-sarif | tee rust_clippy_${{github.sha}}.sarif | sarif-fmt
49+
50+
# - name: Upload Rust Linting SARIF file to CodeQL
51+
# if: ${{ github.event.repository.visibility == 'public' }}
52+
# uses: github/codeql-action/upload-sarif@v2
53+
# with:
54+
# sarif_file: rust_clippy_${{github.sha}}.sarif
55+
# category: clippy_rust
56+
57+
# - name: Upload Rust Linting results to workflow
58+
# if: always()
59+
# uses: actions/upload-artifact@v3
60+
# with:
61+
# name: rust_clippy_results.sarif
62+
# path: |
63+
# rust_clippy_${{github.sha}}.sarif
64+
# if-no-files-found: warn
65+
66+
# # Rust Clippy - Linting report
67+
# - name: Rust Linting Report - SARIF
68+
# shell: bash
69+
# run: |
70+
# cat rust_clippy_${{github.sha}}.sarif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ -n ${manifest_dir} ]]; then
6+
echo "manifest_path=${manifest_dir}/Cargo.toml" >> $GITHUB_OUTPUT
7+
fi

code-check-actions/semgrep/action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ inputs:
66
description: 'Provide additional config to semgrep ci command using --config'
77
required: false
88
default: ''
9+
codeql_upload:
10+
description: 'Toggle to upload results to Github code scanning for public repositories'
11+
required: false
12+
default: true
13+
type: choice
14+
options:
15+
- 'true'
16+
- 'false'
917
runs:
1018
using: 'composite'
1119
steps:
@@ -27,7 +35,7 @@ runs:
2735
if-no-files-found: warn
2836

2937
- name: Upload SARIF to Github Code Scanning
30-
if: ${{ always() && github.event.repository.visibility == 'public' }}
38+
if: ${{ always() && inputs.codeql_upload == 'true' && github.event.repository.visibility == 'public' }}
3139
uses: github/codeql-action/upload-sarif@v2
3240
with:
3341
# Path to SARIF file relative to the root of the repository

0 commit comments

Comments
 (0)