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

[ripgrep] Add test and autoUpdate functions #233

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
36 changes: 35 additions & 1 deletion packages/ripgrep/project.bri
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as std from "std";
import { cargoBuild } from "rust";
import { gitCheckout } from "git";
import nushell from "nushell";

export const project = {
name: "ripgrep",
Expand All @@ -14,7 +15,7 @@ const source = gitCheckout(
}),
);

export default function (): std.Recipe<std.Directory> {
export default function ripgrep(): std.Recipe<std.Directory> {
return cargoBuild({
source,
buildParams: {
Expand All @@ -23,3 +24,36 @@ export default function (): std.Recipe<std.Directory> {
runnable: "bin/rg",
});
}

export async function test() {
const script = std.runBash`
echo -n "$(rg --version)" | tee "$BRIOCHE_OUTPUT"
`.dependencies(ripgrep());
const output = await script.toFile().read();

const version = output.split("\n").at(0);

std.assert(
version === `ripgrep ${project.version}`,
`expected version ${project.version}, got ${version}`,
);

return script;
}

export async function autoUpdate() {
const src = std.file(std.indoc`
let version = http get https://api.github.com/repos/BurntSushi/ripgrep/releases/latest
| get tag_name
| str replace --regex '^v' ''

$env.project | from json | update version $version | to json
`);

return std.withRunnable(std.directory(), {
command: "nu",
args: [src],
env: { project: JSON.stringify(project) },
dependencies: [nushell()],
});
}