Skip to content

Commit

Permalink
Add in gh cli with test/autoupdate (#225)
Browse files Browse the repository at this point in the history
* Add in gh cli with test/autoupdate

* move to github_cli and autoUpdate add date from data

* fix the nushell script up a bit
  • Loading branch information
asheliahut authored Jan 30, 2025
1 parent 6c2ca88 commit d96c602
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/github_cli/brioche.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions packages/github_cli/project.bri
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as std from "std";
import nushell from "nushell";
import { gitCheckout } from "git";
import { goBuild } from "go";

export const project = {
name: "github_cli",
version: "2.65.0",
latestBuildDate: "2025-01-29",
};

const source = gitCheckout(
Brioche.gitRef({
repository: "https://github.com/cli/cli.git",
ref: `v${project.version}`,
}),
);

export default function gh(): std.Recipe<std.Directory> {
return goBuild({
source,
buildParams: {
trimpath: true,
ldflags: [
`-X github.com/cli/cli/v2/internal/build.Version=${project.version}`,
`-X github.com/cli/cli/v2/internal/build.Date=${project.latestBuildDate}`,
],
},
path: "./cmd/gh",
runnable: "bin/gh",
});
}

export async function test() {
const script = std.runBash`
echo -n $(gh --version) | tee "$BRIOCHE_OUTPUT"
`.dependencies(gh());

const result = await script.toFile().read();

// Check that the result contains the expected version
const expected = `gh version ${project.version} (${project.latestBuildDate}) https://github.com/cli/cli/releases/tag/v${project.version}`;
std.assert(result === expected, `expected '${expected}', got '${result}'`);

return script;
}

export function autoUpdate() {
const src = std.file(std.indoc`
let releaseData = (http get https://api.github.com/repos/cli/cli/releases/latest | from json)
let version = $releaseData
| get tag_name
| str replace '^v' ''
let latestBuildDate = $releaseData
| get created_at
| into datetime
| date format "%Y-%m-%d"
$env.project
| from json
| update version $version
| update latestBuildDate $latestBuildDate
| to json
`);

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

0 comments on commit d96c602

Please sign in to comment.