diff --git a/action.yml b/action.yml index 302d92002..73aa96252 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,9 @@ inputs: github-token: description: 'GitHub API token to pull/push GitHub pages branch and deploy GitHub pages. For public repository, this must be personal access token for now. Please read README.md for more details' required: false + ref: + description: 'optional Ref to use when finding commit' + required: false auto-push: description: 'Push GitHub Pages branch to remote automatically. This option requires github-token input' required: false diff --git a/dist/src/config.js b/dist/src/config.js index 3535fdd9c..d77f6111f 100644 --- a/dist/src/config.js +++ b/dist/src/config.js @@ -202,6 +202,7 @@ async function configFromJobInput() { let benchmarkDataDirPath = core.getInput('benchmark-data-dir-path'); const name = core.getInput('name'); const githubToken = core.getInput('github-token') || undefined; + const ref = core.getInput('ref') || undefined; const autoPush = getBoolInput('auto-push'); const skipFetchGhPages = getBoolInput('skip-fetch-gh-pages'); const commentAlways = getBoolInput('comment-always'); @@ -258,6 +259,7 @@ async function configFromJobInput() { externalDataJsonPath, maxItemsInChart, failThreshold, + ref, }; } exports.configFromJobInput = configFromJobInput; diff --git a/dist/src/extract.js b/dist/src/extract.js index 2d7be0cee..03dfd8f47 100644 --- a/dist/src/extract.js +++ b/dist/src/extract.js @@ -54,12 +54,12 @@ function getCommitFromPullRequestPayload(pr) { url: `${pr.html_url}/commits/${id}`, }; } -async function getCommitFromGitHubAPIRequest(githubToken) { +async function getCommitFromGitHubAPIRequest(githubToken, ref) { const octocat = new github.GitHub(githubToken); const { status, data } = await octocat.repos.getCommit({ owner: github.context.repo.owner, repo: github.context.repo.repo, - ref: github.context.ref, + ref: ref !== null && ref !== void 0 ? ref : github.context.ref, }); if (!(status === 200 || status === 304)) { throw new Error(`Could not fetch the head commit. Received code: ${status}`); @@ -82,7 +82,7 @@ async function getCommitFromGitHubAPIRequest(githubToken) { url: data.html_url, }; } -async function getCommit(githubToken) { +async function getCommit(githubToken, ref) { if (github.context.payload.head_commit) { return github.context.payload.head_commit; } @@ -93,7 +93,7 @@ async function getCommit(githubToken) { if (!githubToken) { throw new Error(`No commit information is found in payload: ${JSON.stringify(github.context.payload, null, 2)}. Also, no 'github-token' provided, could not fallback to GitHub API Request.`); } - return getCommitFromGitHubAPIRequest(githubToken); + return getCommitFromGitHubAPIRequest(githubToken, ref); } function extractCargoResult(output) { const lines = output.split(/\r?\n/g); @@ -125,7 +125,7 @@ function extractGoResult(output) { // Example: // BenchmarkFib20-8 30000 41653 ns/op // BenchmarkDoWithConfigurer1-8 30000000 42.3 ns/op - const reExtract = /^(Benchmark\w+(?:\/?[\w()$%^&*-]*?)*?)(-\d+)?\s+(\d+)\s+([0-9.]+)\s+(.+)$/; + const reExtract = /^(Benchmark\w+(?:\/?[\w()$%^&*-=,]*?)*?)(-\d+)?\s+(\d+)\s+([0-9.]+)\s+(.+)$/; for (const line of lines) { const m = line.match(reExtract); if (m === null) { @@ -343,8 +343,9 @@ function extractJmhResult(output) { const name = b.benchmark; const value = b.primaryMetric.score; const unit = b.primaryMetric.scoreUnit; + const params = b.params ? ' ( ' + JSON.stringify(b.params) + ' )' : ''; const extra = `iterations: ${b.measurementIterations}\nforks: ${b.forks}\nthreads: ${b.threads}`; - return { name, value, unit, extra }; + return { name: name + params, value, unit, extra }; }); } function extractBenchmarkDotnetResult(output) { @@ -394,7 +395,7 @@ function extractLuauBenchmarkResult(output) { } async function extractResult(config) { const output = await fs_1.promises.readFile(config.outputFilePath, 'utf8'); - const { tool, githubToken } = config; + const { tool, githubToken, ref } = config; let benches; switch (tool) { case 'cargo': @@ -440,7 +441,7 @@ async function extractResult(config) { if (benches.length === 0) { throw new Error(`No benchmark result was found in ${config.outputFilePath}. Benchmark output was '${output}'`); } - const commit = await getCommit(githubToken); + const commit = await getCommit(githubToken, ref); return { commit, date: Date.now(), diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index d6d5efc1c..5f59572c4 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,7 +1,7 @@ { "name": "github-action-benchmark", "version": "0.0.0", - "lockfileVersion": 2, + "lockfileVersion": 3, "requires": true, "packages": { "node_modules/@actions/core": {