Add config options to disable checks

This commit is contained in:
Alessio
2025-04-19 17:21:21 -07:00
parent 90215c0ce3
commit 9767667760
3 changed files with 57 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"
_ "github.com/mattn/go-sqlite3"
@@ -18,7 +19,7 @@ const (
func main() {
// Check if a filepath argument is provided
if len(os.Args) < 2 {
fmt.Println("Please provide a filepath as the first argument.")
fmt.Println(RED + "Please provide a filepath as the first argument." + RESET)
os.Exit(1)
}
@@ -37,6 +38,10 @@ func main() {
is_failure := false
// Execute each check against the database
for _, check := range checks.Checks {
// Checks can be disabled via Github config / environment variables
if !is_check_enabled(check) {
continue
}
results, err := check.Execute(db)
if err != nil {
panic(err)
@@ -58,3 +63,22 @@ func main() {
}
fmt.Println(GREEN + "Success" + RESET)
}
// github_actions_input_env_var converts an input name to the corresponding
// environment variable name used by GitHub Actions.
func github_actions_input_env_var(name string) string {
// GitHub normalizes both hyphens and underscores to underscores, then uppercases the name
normalized := strings.NewReplacer("-", "_", " ", "_").Replace(name)
return "INPUT_" + strings.ToUpper(normalized)
}
// Setting the environment variable INPUT_REQUIRE_NOT_NULL="false" disables the "require_not_null" check
func is_check_enabled(c checks.Check) bool {
val, is_set := os.LookupEnv(github_actions_input_env_var(c.Name))
if !is_set {
// Enable all checks by default
return true
}
// Anything except "false" is true
return val != "false"
}