diff --git a/.Rbuildignore b/.Rbuildignore index 3e91f6fd..5963c998 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ codecov.yml ^data-raw$ ^doc$ ^Meta$ +^touchstone$ diff --git a/.github/workflows/touchstone-comment.yaml b/.github/workflows/touchstone-comment.yaml new file mode 100644 index 00000000..aa3d40de --- /dev/null +++ b/.github/workflows/touchstone-comment.yaml @@ -0,0 +1,21 @@ +name: Continuous Benchmarks (Comment) + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +on: + workflow_run: + workflows: ["Continuous Benchmarks (Receive)"] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: > + ${{ github.event.workflow_run.event == 'pull_request' }} + steps: + - uses: lorenzwalthert/touchstone/actions/comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/touchstone-receive.yaml b/.github/workflows/touchstone-receive.yaml new file mode 100644 index 00000000..a3f3d52b --- /dev/null +++ b/.github/workflows/touchstone-receive.yaml @@ -0,0 +1,35 @@ +name: Continuous Benchmarks (Receive) + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +on: + issue_comment: + types: ['created', 'edited'] + +jobs: + build: + 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-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: + - name: Echo github obj + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - uses: lorenzwalthert/touchstone/actions/receive@v1 + with: + cache-version: 1 + force_upstream: true diff --git a/touchstone/.gitignore b/touchstone/.gitignore new file mode 100644 index 00000000..ee8eacf0 --- /dev/null +++ b/touchstone/.gitignore @@ -0,0 +1,6 @@ +* +!script.R +!config.json +!.gitignore +!header.R +!footer.R diff --git a/touchstone/footer.R b/touchstone/footer.R new file mode 100644 index 00000000..e827d7b5 --- /dev/null +++ b/touchstone/footer.R @@ -0,0 +1,10 @@ +# You can modify the PR comment footer here. You can use github markdown e.g. +# emojis like :tada:. +# This file will be parsed and evaluate within the context of +# `benchmark_analyze` and should return the comment text as the last value. +# See `?touchstone::pr_comment` +link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html" +glue::glue( + "\nFurther explanation regarding interpretation and", + " methodology can be found in the [documentation]({link})." +) diff --git a/touchstone/header.R b/touchstone/header.R new file mode 100644 index 00000000..d84b90eb --- /dev/null +++ b/touchstone/header.R @@ -0,0 +1,13 @@ +# You can modify the PR comment header here. You can use github markdown e.g. +# emojis like :tada:. +# This file will be parsed and evaluate within the context of +# `benchmark_analyze` and should return the comment text as the last value. +# Available variables for glue substitution: +# * ci: confidence interval +# * branches: BASE and HEAD branches benchmarked against each other. +# See `?touchstone::pr_comment` +glue::glue( + "This is how benchmark results would change (along with a", + " {100 * ci}% confidence interval in relative change) if ", + "{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n" +) diff --git a/touchstone/script.R b/touchstone/script.R new file mode 100644 index 00000000..6b326cea --- /dev/null +++ b/touchstone/script.R @@ -0,0 +1,21 @@ +touchstone::branch_install() + +touchstone::benchmark_run( + small_population = { + params <- malariasimulation::get_parameters( + overrides = list(human_population=1e4)) + malariasimulation::run_simulation(10000, params) + }, + n = 4 +) + +touchstone::benchmark_run( + large_population = { + params <- malariasimulation::get_parameters( + overrides = list(human_population=1e6)) + malariasimulation::run_simulation(1000, params) + }, + n = 2 +) + +touchstone::benchmark_analyze()