Skip to content

Commit

Permalink
add rule to require pre-commit to be added to github actions
Browse files Browse the repository at this point in the history
Co-authored-by: Giuseppe Scuglia <peppescg@gmail.com>
  • Loading branch information
kantord and peppescg committed Dec 19, 2024
1 parent c09f5f3 commit 7d7307a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rule-types/github/pre_commit_github_action.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests:
- name: "Should have pre-commit enabled"
def: {}
params: {}
expect: "pass"
git:
repo_base: good
- name: "Should not have pre-commit enabled"
def: {}
params: {}
expect: "fail"
git:
repo_base: bad
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: NodeJS with Gulp
'on':
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: package.json
- name: Build
run: |
npm install
gulp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
40 changes: 40 additions & 0 deletions rule-types/github/pre_commit_github_action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
version: v1
release_phase: alpha
type: rule-type
name: pre_commit_github_action
display_name: Require running `pre-commit` using GitHub Actions
short_failure_message: "`https://github.com/pre-commit/action` action is not configured"
severity:
value: medium
context: {}
description: |
Verifies that `pre-commit` is configured via a GitHub action for the repository.
guidance: |
Run your `pre-commit` checks in GitHub Actions as well.
def:
in_entity: repository
rule_schema:
type: object
properties: {}
ingest:
type: git
git: {}
eval:
type: rego
rego:
type: deny-by-default
def: |
package minder
import rego.v1
actions := github_workflow.ls_actions("./.github/workflows")
default message := "pre-commit GitHub action is not configured"
default allow := false
allow if {
"pre-commit/action" in actions
}
# Defines the configuration for alerting on the rule
alert:
type: security_advisory
security_advisory: {}

0 comments on commit 7d7307a

Please sign in to comment.