Repository navigation
chore: add a justfile that mirrors the CI gate #247
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,158 @@ | ||
| # Gravity command runner. | ||
| # Run `just --list` to see available recipes, or `just <recipe>` to run one. | ||
| # | ||
| # `just check` runs the same steps as .github/workflows/ci.yml, in the same | ||
| # order. Change both together. | ||
|
|
||
| # show available recipes (default when no recipe is given) | ||
| [private] | ||
| default: | ||
| @just --list | ||
|
|
||
| # rust-toolchain.toml pins the toolchain CI uses; an inherited override would | ||
| # replace it. | ||
| unexport RUSTUP_TOOLCHAIN | ||
|
|
||
| # examples/generate.go builds into and reads from ../target, so a relocated | ||
| # target directory makes `go generate` fail with "unable to read file". | ||
| unexport CARGO_TARGET_DIR | ||
|
|
||
| # styled header: bold cyan ✦, bold white label | ||
| h := BOLD + CYAN + "✦" + WHITE + " " | ||
| n := NORMAL | ||
|
|
||
| # ─── Root commands ─────────────────────────────────────────────────────────────── | ||
|
|
||
| # run the full CI gate: format check, build, unit tests, Go example tests, CLI | ||
| # snapshot tests | ||
| [doc('run the full CI gate')] | ||
| [group('ci')] | ||
| check: lint build test test-go test-cli | ||
|
|
||
| # install the toolchain, components and targets pinned in rust-toolchain.toml | ||
| [group('setup')] | ||
| install: | ||
| @echo '{{ h }}install: rustup toolchain{{ n }}' | ||
| @rustup toolchain install --no-self-update | ||
|
|
||
| # auto-format Rust code and this justfile | ||
| [group('format')] | ||
| format: | ||
| @echo '{{ h }}format: cargo fmt{{ n }}' | ||
| @cargo fmt --all | ||
| @echo '{{ h }}format: justfile{{ n }}' | ||
| @just --fmt | ||
|
|
||
| # check formatting of Rust code and this justfile | ||
| [group('ci')] | ||
| [group('lint')] | ||
| lint: | ||
| @echo '{{ h }}lint: cargo fmt{{ n }}' | ||
| @cargo fmt --all --check | ||
| @echo '{{ h }}lint: justfile{{ n }}' | ||
| @just --fmt --check | ||
|
|
||
| # lint with clippy. Not part of `check`, because CI does not run clippy. | ||
| [doc('lint with clippy (not part of the CI gate)')] | ||
| [group('lint')] | ||
| clippy: | ||
| @echo '{{ h }}lint: cargo clippy{{ n }}' | ||
| @cargo clippy --workspace --all-targets --locked | ||
|
|
||
| # ─── Build and test ────────────────────────────────────────────────────────────── | ||
|
|
||
| # build the workspace | ||
| [group('build')] | ||
| [group('ci')] | ||
| build: | ||
| @echo '{{ h }}build: cargo build{{ n }}' | ||
| @cargo build --locked | ||
|
|
||
| # run the Rust unit tests. The CLI snapshot tests are excluded; see `test-cli`. | ||
| [doc('run the Rust unit tests')] | ||
| [group('ci')] | ||
| [group('test')] | ||
| test: | ||
| @echo '{{ h }}test: cargo test{{ n }}' | ||
| @cargo test --locked | ||
|
|
||
| # run gravity with the given arguments, e.g. | ||
| # `just run --world basic --output basic.go basic.wasm` | ||
| [doc('run gravity with the given arguments')] | ||
| [group('build')] | ||
| [positional-arguments] | ||
| run *args: | ||
| @cargo run --quiet --locked --bin gravity -- "$@" | ||
|
|
||
| # build the example wasm and generate their Go bindings | ||
| [group('build')] | ||
| generate: | ||
| @echo '{{ h }}generate: example wasm and Go bindings{{ n }}' | ||
| @go generate ./... | ||
|
|
||
| # run the Go example tests against freshly generated bindings | ||
| [group('ci')] | ||
| [group('test')] | ||
| test-go: generate | ||
| @echo '{{ h }}test: go test{{ n }}' | ||
| @go test ./... | ||
|
|
||
|
arcjet-rei marked this conversation as resolved.
|
||
| # run the trycmd CLI snapshot tests. They read the example wasm that | ||
| # `generate` builds. | ||
| [doc('run the trycmd CLI snapshot tests')] | ||
| [group('ci')] | ||
| [group('test')] | ||
| test-cli: generate | ||
| @echo '{{ h }}test: cargo test --test cli{{ n }}' | ||
| @cargo test --locked --test cli | ||
|
|
||
| # rewrite the CLI snapshot .stdout and .stderr files from current output. Read | ||
| # the diff before committing it. trycmd cannot create a snapshot file, so a new | ||
| # test's files must exist first; see AGENTS.md. | ||
| [doc('rewrite existing CLI snapshot files from current output')] | ||
| [group('test')] | ||
| update-snapshots: generate | ||
| @echo '{{ h }}test: cargo test --test cli (overwrite){{ n }}' | ||
| @TRYCMD=overwrite cargo test --locked --test cli | ||
|
|
||
| # create the CLI snapshot files for the example in examples/<name>: a .toml | ||
| # that runs gravity on the example's wasm, the .stdout gravity prints for it, | ||
| # and an empty .stderr. trycmd cannot create these files, only update them. | ||
| # `world` defaults to the example's name. Existing files are left alone. | ||
| [doc('create the CLI snapshot files for a new example')] | ||
| [group('test')] | ||
| [script('bash')] | ||
| new-snapshot name world=name: | ||
| set -euo pipefail | ||
| name={{ quote(name) }} | ||
| world={{ quote(world) }} | ||
| base="cmd/gravity/tests/cmd/$name" | ||
| for ext in toml stdout stderr; do | ||
| if [[ -e "$base.$ext" ]]; then | ||
| echo "{{ style("error") }}error:{{ n }} $base.$ext already exists" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
| wasm="target/wasm32-unknown-unknown/release/example_${name//-/_}.wasm" | ||
| echo "{{ h }}build: example-$name (wasm){{ n }}" | ||
| cargo build --locked -p "example-$name" --target wasm32-unknown-unknown --release | ||
| echo "{{ h }}snapshot: $name{{ n }}" | ||
| # Capture first, so a failing gravity run leaves no partial snapshot behind. | ||
| stdout="$(mktemp)" | ||
| trap 'rm -f "$stdout"' EXIT | ||
| cargo run --quiet --locked --bin gravity -- --world "$world" "$wasm" > "$stdout" | ||
| # trycmd runs gravity from cmd/gravity, so the .toml's path is relative to it. | ||
| printf 'bin.name = "gravity"\nargs = "--world %s ../../%s"\n' "$world" "$wasm" > "$base.toml" | ||
| cp "$stdout" "$base.stdout" | ||
| : > "$base.stderr" | ||
|
|
||
| # ─── Cleanup ───────────────────────────────────────────────────────────────────── | ||
|
|
||
| # remove gitignored example output. After switching to a branch without an | ||
| # example, its directory holds only generated files, and the examples/* | ||
| # workspace glob then fails every cargo command with "failed to load manifest". | ||
| [doc('remove gitignored example output (generated Go and wasm)')] | ||
| [group('setup')] | ||
| clean-examples: | ||
| @echo '{{ h }}clean: examples{{ n }}' | ||
| @git clean -f -X -- examples/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.