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 <[email protected]>
  • Loading branch information
kantord and peppescg committed Dec 19, 2024
1 parent 4484e16 commit 2bc3b4b
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion profiles/github/dependabot_ghactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ context:
alert: "off"
remediate: "off"
repository:
- type: dependabot_configured
- type: pre_commit_github_action
def:
package_ecosystem: github-actions
schedule_interval: daily
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,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,30 @@
name: NodeJS with Gulp

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-versiodn: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- uses: pre-commit/[email protected]

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version-file: "package.json"
node-versiosdn: ${{ matrix.node-version }}

- name: Build
run: |
npm install
gulp
41 changes: 41 additions & 0 deletions rule-types/github/pre_commit_github_action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
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 {
print(actions)
"pre-commit/action" in actions
}
# Defines the configuration for alerting on the rule
alert:
type: security_advisory
security_advisory: {}

0 comments on commit 2bc3b4b

Please sign in to comment.