|
| 1 | +# Based on: |
| 2 | +# https://semgrep.dev/docs/semgrep-ci/sample-ci-configs#github-actions |
| 3 | +# https://0xdbe.github.io/GitHub-HowToEnableCodeScanningWithSemgrep/ |
| 4 | +# https://medium.com/@mostafa.elnakeb/supercharging-your-code-quality-with-semgrep-sast-in-github-actions-c8f30eb26655 |
| 5 | +# Name of this GitHub Actions workflow. |
| 6 | +name: Semgrep OSS scan |
| 7 | + |
| 8 | +on: |
| 9 | + # Scan on-demand through GitHub Actions interface: |
| 10 | + workflow_dispatch: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + # Schedule the CI job (this method uses cron syntax): |
| 14 | + schedule: |
| 15 | + - cron: '0 0 * * 1' # Run at start of week |
| 16 | + |
| 17 | +jobs: |
| 18 | + semgrep: |
| 19 | + # User definable name of this GitHub Actions job. |
| 20 | + name: semgrep-oss/scan |
| 21 | + # If you are self-hosting, change the following `runs-on` value: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + # Checkout the repository. |
| 26 | + - name: Clone source code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + # Checkout custom rules |
| 30 | + - name: Checkout custom rules |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + repository: JuliaComputing/semgrep-rules-julia |
| 34 | + ref: main |
| 35 | + path: ./JuliaRules |
| 36 | + |
| 37 | + # Prepare Python |
| 38 | + - uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.10' |
| 41 | + |
| 42 | + # Install Semgrep |
| 43 | + - name: Install Semgrep |
| 44 | + run: python3 -m pip install semgrep |
| 45 | + |
| 46 | + # Run Semgrep |
| 47 | + - name: Scan with Semgrep |
| 48 | + run: | |
| 49 | + semgrep scan \ |
| 50 | + --config ./JuliaRules/rules \ |
| 51 | + --metrics=off \ |
| 52 | + --sarif --output report.sarif \ |
| 53 | + --oss-only \ |
| 54 | + --exclude=JuliaRules |
| 55 | + |
| 56 | + - name: Save Semgrep report |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + name: report.sarif |
| 60 | + path: report.sarif |
| 61 | + |
| 62 | + - name: Upload Semgrep report |
| 63 | + uses: github/codeql-action/upload-sarif@v3 |
| 64 | + with: |
| 65 | + sarif_file: report.sarif |
| 66 | + category: semgrep |
0 commit comments