-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inject git rev at build time and expose as zome call (#109)
- Loading branch information
Showing
11 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,11 @@ | ||
[package] | ||
name = "version_coordinator" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
name = "version_coordinator" | ||
|
||
[dependencies] | ||
hdk = { workspace = true } |
This file contains 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,9 @@ | ||
use std::process::Command; | ||
fn main() { | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.expect("Can get git revision"); | ||
let git_hash = String::from_utf8(output.stdout).unwrap(); | ||
println!("cargo:rustc-env=GIT_HASH={}", git_hash); | ||
} |
This file contains 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,7 @@ | ||
use hdk::prelude::*; | ||
|
||
/// Returns the monorepo git commit revision that was injected at build time. | ||
#[hdk_extern] | ||
pub fn git_rev(_: ()) -> ExternResult<String> { | ||
Ok(env!("GIT_HASH").to_string()) | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { AppClient } from "@holochain/client"; | ||
import { Player } from "@holochain/tryorama"; | ||
import { UsernameRegistryCoordinator, SignerCoordinator } from "@holoom/types"; | ||
import { | ||
UsernameRegistryCoordinator, | ||
SignerCoordinator, | ||
VersionCoordinator, | ||
} from "@holoom/types"; | ||
|
||
export function bindCoordinators(player: Player) { | ||
const appClient = player.appWs as AppClient; | ||
return { | ||
signer: new SignerCoordinator(appClient), | ||
usernameRegistry: new UsernameRegistryCoordinator(appClient), | ||
version: new VersionCoordinator(appClient), | ||
}; | ||
} |
This file contains 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,16 @@ | ||
import { expect, test } from "vitest"; | ||
import { runScenario } from "@holochain/tryorama"; | ||
import { execSync } from "node:child_process"; | ||
|
||
import { setupAliceOnly } from "../utils/setup-happ.js"; | ||
|
||
test("Injected git revision matches monorepo's", async () => { | ||
await runScenario(async (scenario) => { | ||
const { aliceCoordinators } = await setupAliceOnly(scenario); | ||
|
||
const revision = await execSync("git rev-parse HEAD").toString().trim(); | ||
expect(/^[a-f0-9]{40}/.test(revision)).toBe(true); | ||
|
||
await expect(aliceCoordinators.version.gitRev()).resolves.toBe(revision); | ||
}); | ||
}); |
This file contains 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,18 @@ | ||
import { AppClient } from "@holochain/client"; | ||
|
||
export class VersionCoordinator { | ||
constructor( | ||
private readonly client: AppClient, | ||
private readonly roleName = "holoom", | ||
private readonly zomeName = "version", | ||
) {} | ||
|
||
async gitRev(): Promise<string> { | ||
return this.client.callZome({ | ||
role_name: this.roleName, | ||
zome_name: this.zomeName, | ||
fn_name: "git_rev", | ||
payload: null, | ||
}); | ||
} | ||
} |
This file contains 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 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