Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add Semgrep to CI #2912

Merged
merged 3 commits into from
Sep 24, 2024
Merged

ci: Add Semgrep to CI #2912

merged 3 commits into from
Sep 24, 2024

Conversation

jkan2
Copy link
Contributor

@jkan2 jkan2 commented Sep 23, 2024

Description

adds semgrep to github actions

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow for continuous integration checks using Semgrep.
    • The workflow runs automatically on specified events and is scheduled to execute daily.
  • Bug Fixes

    • The workflow is designed to skip execution for changes made by the dependabot bot.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

A new GitHub Actions workflow named semgrep.yml has been added to the repository. This workflow is designed to trigger on various events, including manual dispatch, pull requests, and pushes to the main or master branches when changes occur in the workflow file itself. It is also scheduled to run daily at 22:56 UTC. The workflow includes a job that executes Semgrep for continuous integration checks, with specific conditions to skip execution for Dependabot.

Changes

File Change Summary
.github/workflows/semgrep.yml New workflow added for Semgrep CI checks, triggered by various events and scheduled daily.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Semgrep

    User->>GitHub Actions: Trigger workflow (manual, PR, push)
    GitHub Actions->>GitHub Actions: Check conditions (e.g., not Dependabot)
    GitHub Actions->>Semgrep: Run semgrep ci command
    Semgrep-->>GitHub Actions: Return results
    GitHub Actions-->>User: Complete workflow
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jkan2 jkan2 changed the title add semgrep to actions Add Semgrep to CI Sep 23, 2024
@github-actions github-actions bot added the ci Changes to CI pipeline or github actions label Sep 23, 2024
@jkan2 jkan2 marked this pull request as ready for review September 24, 2024 00:14
@jkan2 jkan2 requested a review from a team as a code owner September 24, 2024 00:14
@jkan2 jkan2 changed the title Add Semgrep to CI ci: Add Semgrep to CI Sep 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
.github/workflows/semgrep.yml (3)

1-13: Workflow triggers are well-defined and comprehensive.

The workflow configuration for name and triggers is appropriate and covers all necessary scenarios. The use of workflow_dispatch, pull_request, and conditional push events ensures that Semgrep runs when needed. The daily scheduled run is a good practice for regular checks.

Consider updating the comment on line 12 to be more specific:

-    # random HH:MM to avoid a load spike on GitHub Actions at 00:00
+    # Run at 22:56 UTC daily to avoid load spikes on GitHub Actions at 00:00

14-22: Job configuration is appropriate, with a suggestion for improvement.

The job configuration is well-structured and follows security best practices by using a secret for the Semgrep token. The use of a Docker container ensures a consistent environment for Semgrep execution.

Consider updating the Ubuntu version to use the latest LTS version:

-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest

This change will ensure that the workflow always uses the latest LTS version of Ubuntu, reducing the need for manual updates in the future.


23-25: Job steps are correct but can be enhanced.

The use of actions/checkout@v4 and the semgrep ci command are appropriate for running Semgrep in a CI environment.

Consider enhancing the Semgrep execution step to capture the output and handle potential errors:

    steps:
      - uses: actions/checkout@v4
      - name: Run Semgrep
        run: |
          set -eo pipefail
          semgrep ci | tee semgrep_output.txt
        continue-on-error: true
      - name: Check Semgrep output
        run: |
          if grep -q "Findings:" semgrep_output.txt; then
            echo "Semgrep found issues. Please review the output."
            exit 1
          fi

This change will:

  1. Capture Semgrep output to a file.
  2. Allow the workflow to continue even if Semgrep finds issues.
  3. Provide a clear indication of whether Semgrep found any problems.
  4. Fail the job if issues are found, ensuring they are addressed.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3eba701 and cba77e6.

Files selected for processing (1)
  • .github/workflows/semgrep.yml (1 hunks)

@jkan2 jkan2 added the no-changelog Skip changelog CI check label Sep 24, 2024
Copy link
Member

@gartnera gartnera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to be actually running? it exited instantly?

run `semgrep login` before using `semgrep ci` or use `semgrep scan` and set `--config`

@jkan2
Copy link
Contributor Author

jkan2 commented Sep 24, 2024

thanks for catching that @gartnera completely missed the token part as I previously used their bot to create it on my tests (which would commit to main 😓 )

.github/workflows/semgrep.yml Outdated Show resolved Hide resolved
.github/workflows/semgrep.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.49%. Comparing base (3eba701) to head (0fb41cc).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2912      +/-   ##
===========================================
+ Coverage    67.27%   67.49%   +0.21%     
===========================================
  Files          380      380              
  Lines        21175    21169       -6     
===========================================
+ Hits         14245    14287      +42     
+ Misses        6264     6213      -51     
- Partials       666      669       +3     

see 7 files with indirect coverage changes

@jkan2 jkan2 added this pull request to the merge queue Sep 24, 2024
Merged via the queue into develop with commit 3e0b307 Sep 24, 2024
31 checks passed
@jkan2 jkan2 deleted the jkan2/semgrep branch September 24, 2024 22:10
@coderabbitai coderabbitai bot mentioned this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Changes to CI pipeline or github actions no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants