forked from coral-xyz/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: Add a script to sync benchmark results for all versions (coral…
- Loading branch information
1 parent
a195106
commit c166712
Showing
8 changed files
with
236 additions
and
48 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Sync all saved data by re-running the tests for each version. | ||
* | ||
* This script should be used when the bench program or its tests has changed | ||
* and all data needs to be updated. | ||
*/ | ||
|
||
import path from "path"; | ||
import { spawnSync } from "child_process"; | ||
|
||
import { ANCHOR_VERSION_ARG, BenchData, Toml } from "./utils"; | ||
|
||
(async () => { | ||
const bench = await BenchData.open(); | ||
|
||
const cargoToml = await Toml.open( | ||
path.join("..", "programs", "bench", "Cargo.toml") | ||
); | ||
const anchorToml = await Toml.open(path.join("..", "Anchor.toml")); | ||
|
||
for (const version of bench.getVersions()) { | ||
console.log(`Updating '${version}'...`); | ||
|
||
const isUnreleased = version === "unreleased"; | ||
|
||
// Update the anchor dependency versions | ||
for (const dependency of ["lang", "spl"]) { | ||
cargoToml.replaceValue(`anchor-${dependency}`, () => { | ||
return isUnreleased | ||
? `{ path = "../../../../${dependency}" }` | ||
: `"${version}"`; | ||
}); | ||
} | ||
|
||
// Save Cargo.toml | ||
await cargoToml.save(); | ||
|
||
// Update `anchor test` command to pass version in Anchor.toml | ||
anchorToml.replaceValue( | ||
"test", | ||
(cmd) => { | ||
return cmd.includes(ANCHOR_VERSION_ARG) | ||
? cmd.replace( | ||
new RegExp(`\\s*${ANCHOR_VERSION_ARG}\\s+(.+)`), | ||
(arg, ver) => (isUnreleased ? "" : arg.replace(ver, version)) | ||
) | ||
: `${cmd} ${ANCHOR_VERSION_ARG} ${version}`; | ||
}, | ||
{ insideQuotes: true } | ||
); | ||
|
||
// Save Anchor.toml | ||
await anchorToml.save(); | ||
|
||
// Run the command to update the current version's results | ||
const result = spawnSync("anchor", ["test", "--skip-lint"]); | ||
console.log(result.output.toString()); | ||
|
||
// Check for failure | ||
if (result.status !== 0) { | ||
console.error("Please fix the error and re-run this command."); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
} | ||
})(); |
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
Oops, something went wrong.