-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rule to require pre-commit to be added to github actions
Co-authored-by: Giuseppe Scuglia <peppescg@gmail.com>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
21 changes: 21 additions & 0 deletions
21
rule-types/github/pre_commit_github_action.testdata/bad/.workflows/checks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
rule-types/github/pre_commit_github_action.testdata/good/.workflows/checks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} |