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

Use GitHub Actions to run pre-commit #130

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Use GitHub Actions to run pre-commit #130

merged 1 commit into from
Dec 6, 2024

Conversation

5ouma
Copy link
Owner

@5ouma 5ouma commented Dec 6, 2024

⚠️ Issue

close #


✏️ Description

pre-commit.ci has a size limit.


🔄 Type of the Change

  • 🎉 New Feature
  • 🧰 Bug
  • 🛡️ Security
  • 📖 Documentation
  • 🏎️ Performance
  • 🧹 Refactoring
  • 🧪 Testing
  • 🔧 Maintenance
  • 🎽 CI
  • 🧠 Meta

pre-commit.ci has a size limit.
@Copilot Copilot bot review requested due to automatic review settings December 6, 2024 11:43
@prlabeler prlabeler bot added the 🎽 CI Changes to CI configuration files and scripts label Dec 6, 2024
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces several changes to the repository's configuration and documentation. It removes the autofix_commit_msg section from the .github/pre-commit.yml file, streamlining the focus on defined hooks. A new GitHub Actions workflow file, .github/workflows/pre-commit.yml, is added to automate pre-commit checks upon pushes and pull requests. Additionally, the README.md file is updated to reflect a change in the pre-commit status badge, linking it to the new GitHub Actions workflow instead of an external service.

Changes

File Change Summary
.github/pre-commit.yml Removed the autofix_commit_msg configuration section, retaining only the list of hooks.
.github/workflows/pre-commit.yml Added a new GitHub Actions workflow for pre-commit checks triggered by pushes and pull requests.
README.md Updated the pre-commit status badge to link to the new GitHub Actions workflow.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7e577 and 7a0eba1.

📒 Files selected for processing (3)
  • .github/pre-commit.yml (0 hunks)
  • .github/workflows/pre-commit.yml (1 hunks)
  • README.md (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/pre-commit.yml
✅ Files skipped from review due to trivial changes (1)
  • README.md
🔇 Additional comments (1)
.github/workflows/pre-commit.yml (1)

13-14: Verify the security and stability of the custom action

The workflow uses a custom action 5ouma/utils/pre-commit pinned to a specific commit. While pinning to a commit hash is good for security, consider:

  1. Reviewing the action's source code for security
  2. Using a version tag instead of a raw commit hash for better maintainability
  3. Adding documentation about what this custom action does
✅ Verification successful

Let me gather more information about the action's source code.


Let me try a different approach to get the action's content.


Action is safe but could use better versioning

After reviewing the action's source code, I can confirm that it's a safe composite action that:

  1. Uses official GitHub actions (checkout, setup-python) pinned to secure commits
  2. Uses official pre-commit actions (pre-commit/action, pre-commit-ci/lite-action) also pinned to secure commits
  3. Only requires a config file path as input with a sensible default

However, since there are no release tags in the repository, I recommend:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the custom action's source code and documentation

# Check if the action repository exists and is public
gh repo view 5ouma/utils

# Get the action's source code at the specified commit
gh api repos/5ouma/utils/contents/pre-commit?ref=23aec800e821891339568c454135bb9befe36fce

# Check for any security advisories
gh api graphql -f query='
{
  repository(owner: "5ouma", name: "utils") {
    vulnerabilityAlerts(first: 5) {
      nodes {
        securityVulnerability {
          severity
          advisory {
            description
          }
        }
      }
    }
  }
}'

Length of output: 2894


Script:

#!/bin/bash
# Get the actual content of the action.yml file
gh api repos/5ouma/utils/contents/pre-commit/action.yml?ref=23aec800e821891339568c454135bb9befe36fce | jq -r '.content' | base64 -d

# Check if there are any releases/tags
gh api repos/5ouma/utils/tags

Length of output: 265


Script:

#!/bin/bash
# Get the raw content of the action.yml file directly
curl -s https://raw.githubusercontent.com/5ouma/utils/23aec800e821891339568c454135bb9befe36fce/pre-commit/action.yml

# Check commit history for this specific file to understand its stability
gh api repos/5ouma/utils/commits?path=pre-commit/action.yml&per_page=5

Length of output: 4892


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.

Copy link

@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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
.github/workflows/pre-commit.yml (2)

3-6: Consider optimizing workflow triggers

The workflow currently runs on both push to main and pull requests, which could result in duplicate runs for the same commits when PRs are merged. Consider adding paths-ignore to exclude unnecessary runs or using if conditions to prevent duplicate executions.

 on:
   push:
     branches: [main]
+    paths-ignore:
+      - '**.md'
+      - 'docs/**'
   pull_request:
+    paths-ignore:
+      - '**.md'
+      - 'docs/**'

1-14: Add workflow documentation and pre-commit configuration

Consider adding:

  1. Workflow documentation explaining its purpose and configuration
  2. Pre-commit configuration details or link to configuration file
  3. Error handling and reporting configuration
 name: 🚸 pre-commit
 
+# This workflow runs pre-commit checks on all pull requests and pushes to main
+# Configuration: .pre-commit-config.yaml
+
 on:
   push:
     branches: [main]
   pull_request:
 
 jobs:
   pre-commit:
     runs-on: ubuntu-latest
+    timeout-minutes: 10
 
     steps:
       - uses: actions/checkout@v4
+
+      - name: Cache pre-commit environments
+        uses: actions/cache@v3
+        with:
+          path: ~/.cache/pre-commit
+          key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
+
       - name: 🚸 Run pre-commit
         uses: 5ouma/utils/pre-commit@23aec800e821891339568c454135bb9befe36fce # main
+        continue-on-error: false
🛑 Comments failed to post (2)
.github/workflows/pre-commit.yml (2)

8-10: ⚠️ Potential issue

Fix runner specification and add workflow safeguards

  1. The runner specification Ubuntu-Latest should be ubuntu-latest (case-sensitive)
  2. Consider adding timeout and concurrency settings for better resource management
 jobs:
   pre-commit:
-    runs-on: Ubuntu-Latest
+    runs-on: ubuntu-latest
+    timeout-minutes: 10
+    concurrency:
+      group: ${{ github.workflow }}-${{ github.ref }}
+      cancel-in-progress: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true

12-14: ⚠️ Potential issue

Add missing checkout step

The workflow is missing the checkout step, which is required to access repository files for pre-commit checks.

 steps:
+      - uses: actions/checkout@v4
       - name: 🚸 Run pre-commit
         uses: 5ouma/utils/pre-commit@23aec800e821891339568c454135bb9befe36fce # main
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    steps:
      - uses: actions/checkout@v4
      - name: 🚸 Run pre-commit
        uses: 5ouma/utils/pre-commit@23aec800e821891339568c454135bb9befe36fce # main

@5ouma 5ouma requested a review from Copilot December 6, 2024 11:48

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.

@5ouma 5ouma merged commit f04d1e5 into main Dec 6, 2024
6 checks passed
@5ouma 5ouma deleted the ci-pre-commit branch December 6, 2024 11:50
@github-actions github-actions bot mentioned this pull request Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎽 CI Changes to CI configuration files and scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant