Skip to content

Commit

Permalink
Send data with node also for cross compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar committed Oct 14, 2023
1 parent f9c23f3 commit f7266f8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/bench-turborepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ jobs:

- name: Augment ttft data
run: |
cd benchmark && node -r esbuild-register ./src/ttft-augment.ts "$PWD/ttft.json" ${{github.run_id}}
cat ./ttft.json
cd benchmark && TINYBIRD_TOKEN=${{secrets.TINYBIRD_TOKEN}} node -r esbuild-register ./src/ttft-augment.ts "$PWD/ttft.json" ${{github.job_url}}
${{github.job}}
- name: Save to Tinybird
run: |
myjson=$(cat ./benchmark/ttft.json | jq -c)
echo $myjson
curl --retry 3 -i -X POST -d "$myjson" -H "Authorization: Bearer ${{ secrets.TINYBIRD_TOKEN }}" https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft
# - name: Save to Tinybird
# run: |

# myjson=$(cat ./benchmark/ttft.json)
# echo $myjson
# curl --retry 3 -i -X POST -d "$myjson" -H "Authorization: Bearer ${{ secrets.TINYBIRD_TOKEN }}" https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft

# The benchmark always produces profile.json, but we can change the name for the purpose of saving it
- name: Prep artifact
Expand Down
4 changes: 3 additions & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"esbuild": "^0.15.0",
"esbuild-register": "^3.3.2",
"fs-extra": "^10.0.0",
"ndjson": "^2.0.0"
"ndjson": "^2.0.0",
"node-fetch": "^2.6.8"
},
"scripts": {
"benchmark": "echo done",
Expand All @@ -18,6 +19,7 @@
"@types/fs-extra": "^9.0.13",
"@types/ndjson": "^2.0.2",
"@types/node": "^18.17.4",
"@types/node-fetch": "^2.6.6",
"typescript": "^5.2.2"
}
}
31 changes: 23 additions & 8 deletions benchmark/src/ttft-augment.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import fs from "fs";
import fetch from "node-fetch";
import { getCommitDetails } from "./helpers";

const filePath = process.argv[2];
const runID = process.argv[3];
const url = process.argv[3];

const contents = fs.readFileSync(filePath);
const data = JSON.parse(contents.toString());
const DATA_SOURCE_URL =
"https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft";

const commitDetails = getCommitDetails();
(async function () {
const contents = fs.readFileSync(filePath);
const data = JSON.parse(contents.toString());

data.commitSha = commitDetails.commitSha;
data.commitTimestamp = commitDetails.commitTimestamp;
data.url = `https://github.com/vercel/turbo/actions/runs/${runID}`;
const commitDetails = getCommitDetails();

fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
data.commitSha = commitDetails.commitSha;
data.commitTimestamp = commitDetails.commitTimestamp;
data.url = url;

console.log("Sending data to Tinybird: ", data);

await fetch(DATA_SOURCE_URL, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TINYBIRD_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
})();
15 changes: 14 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit f7266f8

Please sign in to comment.