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

feat: add support for .zizmor.yml files #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ configuration files in the following order of precedence:
explicitly, the config file does *not* need to be named `zizmor.yml`.
1. `${CWD}/.github/zizmor.yml`
1. `${CWD}/zizmor.yml`
1. `${CWD}/.zizmor.yml`

For the last two discovery methods, `${CWD}` is the current working directory,
For the folder-tree-based discovery methods, `${CWD}` is the current working directory,
i.e. the directory that `zizmor` was executed from.

Only one configuration file is ever loaded. In other words: if both
Expand Down Expand Up @@ -59,7 +60,7 @@ where `filename.yml` is the base filename of the workflow, and `line` and
location to ignore. If one or both are absent, then the rule applies to the
entire file or entire line.

By example, here is a configuration file with two different audit ignore
For example, here is a configuration file with two different audit ignore
rule groups:

```yaml title="zizmor.yml"
Expand Down
14 changes: 5 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,18 @@ impl Config {
// If the user didn't pass a config path explicitly with
// `--config`, then we attempt to discover one relative to $CWD
// Our procedure is to first look for `$CWD/.github/zizmor.yml`,
// then `$CWD/zizmor.yml`, and then bail.
// then `$CWD/zizmor.yml`, then `$CWD/.zizmor.yml`, and then bail.
let cwd = std::env::current_dir()
.with_context(|| "config discovery couldn't access CWD")?;

let path = cwd.join(".github").join("zizmor.yml");
if path.is_file() {
serde_yaml::from_str(&fs::read_to_string(path)?)?
} else {
let path = cwd.join("zizmor.yml");
for path in &[".github/zizmor.yml", "zizmor.yml", ".zizmor.yml"] {
let path = cwd.join(path);
if path.is_file() {
serde_yaml::from_str(&fs::read_to_string(path)?)?
} else {
tracing::debug!("no config discovered; loading default");
Config::default()
}
}
tracing::debug!("no config discovered; loading default");
Config::default()
}
};

Expand Down