Skip to content

Commit

Permalink
Merge branch 'main' into feat/max-params
Browse files Browse the repository at this point in the history
  • Loading branch information
JoSeBu1 committed Mar 18, 2024
2 parents 10b7847 + 5edd196 commit 2a04f23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -94,7 +94,8 @@ jobs:
FIXTURE: ${{ matrix.fixture }}
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
# Dummy token for tokenless runs, to suppress logging hash of metadata JSON (see `upload.mjs`)
token: ${{ secrets.CODSPEED_TOKEN || 'dummy' }}
upload-url: http://localhost:${{ env.INTERCEPT_PORT }}/upload

- name: Upload bench data artefact
Expand Down
19 changes: 17 additions & 2 deletions tasks/benchmark/codspeed/upload.mjs
Expand Up @@ -110,13 +110,28 @@ const metadata = JSON.parse(
);
metadata.profileMd5 = md5;

// If no token, set `metadata.tokenless`, and log hash of metadata JSON.
// For tokenless runs (PRs from forks), `codspeed-runner` logs SHA256 hash of metadata JSON.
// CodSpeed then reads the job logs to find a line matching `CodSpeed Run Hash: "..."`.
// So we used a dummy token for `CodSpeedHQ/action` to prevent it logging the hash,
// so can log the correct hash ourselves here instead.
if (!token) metadata.tokenless = true;
const metadataJson = JSON.stringify(metadata);
if (!token) {
const metadataHash = createHash('sha256').update(metadataJson).digest('hex');
console.log(`CodSpeed Run Hash: "${metadataHash}"`);
}

// Upload metadata to CodSpeed
console.log('Uploading metadata to CodSpeed');
const {data} = await axios({
method: 'post',
url: CODSPEED_UPLOAD_URL,
data: metadata,
headers: {Authorization: token},
data: metadataJson,
headers: {
'Content-Type': 'application/json',
...(token ? {Authorization: token} : null),
},
});
assert(data?.status === 'success', 'Failed to upload metadata to Codspeed');
const {uploadUrl} = data;
Expand Down

0 comments on commit 2a04f23

Please sign in to comment.