Skip to content

Fix continuous benchmarking: #62

Fix continuous benchmarking:

Fix continuous benchmarking: #62

Workflow file for this run

name: Continuous benchmarking
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number }}
cancel-in-progress: true
on:
issue_comment:
types: ['created', 'edited']
permissions:
contents: read
statuses: write
pull-requests: write
env:
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
# This generally gives more consistent benchmarking results.
R_GC_MEM_GROW: 3
jobs:
prepare:
# The other jobs all depend on this one succeeding. They'll implicitly get
# skipped as well if this condition is not met.
if: >
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/benchmark') && (
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
runs-on: ubuntu-latest
outputs:
# The HEAD's sha is exported so we can update the status when the workflow
# completes.
head_sha: ${{ steps.metadata.outputs.result }}
steps:
- id: metadata
name: Fetch PR metadata
uses: actions/github-script@v7
with:
result-encoding: string
script: |
let pr = (await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})).data;
return pr.head.sha;
- name: Set commit status as in progress
uses: actions/github-script@v7
env:
HEAD_SHA: ${{ steps.metadata.outputs.result }}
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.HEAD_SHA,
state: "pending",
target_url: process.env.WORKFLOW_URL,
description: 'Benchmarking in progress...',
context: 'touchstone'
});
build:
needs: prepare
# This job run potentially untrusted code from the PR (albeit gated by a
# comment from a collaborator). We restrict the scope of the token as much
# as we can. We also need to be careful not to use any repository secrets
# as inputs to the job. The rest of the workflow only runs code from the
# master branch so isn't vulnerable to outsiders.
permissions:
contents: read
runs-on: ubuntu-22.04
env:
RSPM: "https://packagemanager.posit.co/cran/__linux__/jammy/2024-05-15"
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: lorenzwalthert/touchstone/actions/receive@main
comment:
needs: ['prepare', 'build']
if: always() && needs.prepare.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Download benchmarking results
if: needs.build.result == 'success'
# Version number must match the one used by touchstone when uploading
uses: actions/download-artifact@v2
with:
name: pr
- name: Comment on PR
if: needs.build.result == 'success'
uses: actions/github-script@v7
with:
script: |
var fs = require('fs');
var body = fs.readFileSync('./info.txt').toString();
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
- name: Update commit status
uses: actions/github-script@v7
env:
RESULT: ${{ needs.build.result }}
HEAD_SHA: ${{ needs.prepare.outputs.head_sha }}
with:
script: |
let description;
switch (process.env.RESULT) {
case "success":
description = 'Benchmarking succeeded!';
break;
case "cancelled":
description = 'Benchmarking was cancelled.';
break;
default:
description = 'Benchmarking failed!';
break;
}
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.HEAD_SHA,
state: process.env.RESULT == "success" ? "success" : "failure",
target_url: process.env.WORKFLOW_URL,
description: description,
context: 'touchstone'
});