benchmark-action / benchmark-action/github-action-benchmark
Support writing data as JSON but still uploading it
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 184
- PR merge metrics
- No merged PRs in 30d
Description
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 `` tag as JavaScript, I need to trim the prefix from the file before parsing it as JSON.
```javascript
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:
```yaml
- uses: benchmark-action/github-action-benchmark@v1
with:
output-format: json # Optional, default would be javascript as it is today
```
```javascript
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.
Contributor guide
Assessment
This issue has not been assessed yet.