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

Support writing data as JSON but still uploading it #261

Open
martincostello opened this issue Aug 13, 2024 · 1 comment
Open

Support writing data as JSON but still uploading it #261

martincostello opened this issue Aug 13, 2024 · 1 comment

Comments

@martincostello
Copy link
Contributor

I've written a custom UI on top of the benchmark data where I load the data using fetch() from raw.githubusercontent.com so I can switch between branches in the UI from a single deployed GitHub Pages site (as GitHub Pages does not support multiple branches).

However, as the data is expected to be loaded via a <script> tag as JavaScript, I need to trim the prefix from the file before parsing it as JSON.

const dataUrl = `https://raw.githubusercontent.com/${username}/${repository}/${branch}/${application}/data.js`;
const response = await fetch(dataUrl, { cache: 'no-cache' });
const dataText = await response.text();
const data = JSON.parse(dataText.slice('window.BENCHMARK_DATA = '.length));

I otherwise use the auto-push functionality, so would rather be able to control the format of the written file, rather than need to handle all that that functionality myself by using the external-data-json-path input.

If there were an input option to set the format between JavaScript and JSON, then I could directly fetch the data as JSON:

- uses: benchmark-action/github-action-benchmark@v1
  with:
    output-format: json # Optional, default would be javascript as it is today
const dataUrl = `https://raw.githubusercontent.com/${username}/${repository}/${branch}/${application}/data.json`;
const response = await fetch(dataUrl, { cache: 'no-cache' });
const data = await response.json();

I'd be happy to contribute a PR to add support for this if such a feature would be welcome.

@414owen
Copy link

414owen commented Dec 21, 2024

Exposing the data as JSON is a good idea for performance reasons, as parsing JSON is faster than parsing JS.

See https://github.com/GoogleChromeLabs/json-parse-benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants