Sleep tight #67
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
jobs: | |
prepare: | |
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 | |
steps: | |
- name: Set commit status as in progress | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
var pr = (await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
})).data; | |
github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: pr.head.sha, | |
state: "pending", | |
target_url: process.env.WORKFLOW_URL, | |
description: 'Benchmarking in progress...', | |
context: 'touchstone' | |
}); | |
// Used later in the workflow to update the commit status. | |
return pr.head.sha; | |
build: | |
needs: prepare | |
# This job run potentially untrusted code from the PR. 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. | |
permissions: | |
contents: read | |
runs-on: ubuntu-24.04 | |
env: | |
RSPM: "https://packagemanager.posit.co/cran/__linux__/noble/2024-05-15" | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: lorenzwalthert/touchstone/actions/receive@main | |
# https://github.com/lorenzwalthert/touchstone/pull/138 | |
- name: Upload raw results | |
uses: actions/upload-artifact@v2 | |
with: | |
name: data | |
path: touchstone/records/ | |
overwrite: true | |
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: ${{ steps.prepare.outputs.result }} | |
with: | |
script: | | |
github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: process.env.HEAD_SHA, | |
state: process.env.RESULT, | |
target_url: process.env.WORKFLOW_URL, | |
description: process.env.RESULT == "success" ? 'Benchmarking succeeded!' : 'Benchmarking failed!', | |
context: 'touchstone' | |
}); |