Knope is open to all kinds of contributions—if you want to contribute code there are a few helpful hints.
The docs website is built using starlight.
The source is contained in the docs
directory.
The easiest way to find a document to edit is to go to that doc on the website and click on "Edit page"
at the bottom.
npm --prefix docs install
, then npm --prefix docs start
(or just serve-docs
).
CI will fail if the docs are not formatted correctly or there are broken relative links.
Use just reformat
to reformat the docs and just build-docs
to check for broken links.
just
is a command runner (like make
) which makes it easier to run
common tasks the same way on many platforms. Specifically, you can run the same sorts of commands that CI does to
replicate failures (or prevent them) locally! Start by installing
via your favorite method (like cargo binstall just
).
Then, run just -l
to see all the available commands.
This project uses rustfmt
to format Rust code, but depends on unstable features (for example, sorting imports).
You need to install the nightly toolchain (for example, with rustup toolchain install nightly
) before formatting the
code.
Prettier formats Markdown (via npx
)
and Taplo formats TOML. just install-all-dependencies
will install
Taplo (via cargo-binstall, which you must install manually), but won't install NPM.
Most of the tests for Knope are end-to-end snapshot tests in the tests
directory, where one directory/module
corresponds to one test.
To create a new test:
- Copy a test directory
- Add it as a
mod
to whatever directory is above it. - Change the contents of
in
as required for what you're testing. - Change the contents of
out
to match whatin
should look like after running the command (for example, increased versions) - Change
mod.rs
to have the setup & command invocation that you want - Run the test with
just
(orcargo test
) - If the test fails, you can run
SNAPSHOTS=overwrite just
to update the snapshots
Most snapshot tests look like this:
#[test]
fn name_of_test() {
TestCase::new(file!()) // Corresponds to a directory you make for this test
.git(&[ // Run Git commands as needed to set up the test
Commit("Initial commit"),
Tag("v0.1.0"),
])
.env("KNOPE_PRERELEASE_LABEL", "alpha") // Set environment variables as needed
.run("prepare-release --prerelease-label alpha") // The command you want to run, omitting the binary name
}
This test must be in a "test directory," which has the following:
- An
in
directory with all the files that the command needs to run.TestCase::run
will create a temporary directory, copy the contents ofin
into it, and run the command from there. - An
out
directory, if the command should alter the files inin
. - If the command should succeed (exit with a 0 status code):
- A
stdout.log
file if the command produces an output. - A
dryrun_stdout.log
file if.run()
should also execute the command with--dry-run
to snapshot the output.
- A
- If the command should fail (exit with a non-0 status code):
- A
stderr.log
file if the command should fail and produce an error message. - A
dryrun_stderr.log
file if.run()
should also execute the command with--dry-run
to snapshot the output.
- A
If neither of stdout.log
or stderr.log
are present, the command should succeed and produce no output.
TestCase
leverages snapbox under the hood, so you can set SNAPSHOTS=overwrite
to
update the snapshots if you've made changes to the test.
The setup functions (new
, git
, env
) of TestCase
are const
,
so you can define them once and reuse them in multiple cases,
when slightly different setups should produce the same results
(for example, in tests/prepare_release/override_prerelease_label/mod.rs
).