[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Touchstone init

+366 -2
+1
.Rbuildignore
··· 6 6 ^\.vscode$ 7 7 ^LICENSE\.md$ 8 8 ^AGENTS\.md$ 9 + ^touchstone$
+95
.github/workflows/touchstone-comment.yaml
··· 1 + name: Continuous Benchmarks (Comment) 2 + 3 + concurrency: 4 + group: ${{ github.workflow }}-${{ github.head_ref }} 5 + cancel-in-progress: true 6 + 7 + on: 8 + workflow_run: 9 + workflows: [ "Continuous Benchmarks (Receive)" ] 10 + types: [ completed ] 11 + 12 + jobs: 13 + comment: 14 + runs-on: ubuntu-latest 15 + permissions: 16 + actions: read 17 + contents: write 18 + pull-requests: write 19 + if: ${{ github.event.workflow_run.event == 'pull_request' }} 20 + steps: 21 + - uses: actions/checkout@v6 22 + 23 + - name: Download Touchstone comment artifact 24 + id: download_comment 25 + uses: actions/download-artifact@v8 26 + with: 27 + name: pr 28 + path: ./pr 29 + github-token: ${{ github.token }} 30 + repository: ${{ github.repository }} 31 + run-id: ${{ github.event.workflow_run.id }} 32 + 33 + - name: Download Touchstone plot artifact 34 + id: download_plots 35 + continue-on-error: true 36 + uses: actions/download-artifact@v8 37 + with: 38 + name: visual-benchmarks 39 + path: ./plots 40 + github-token: ${{ github.token }} 41 + repository: ${{ github.repository }} 42 + run-id: ${{ github.event.workflow_run.id }} 43 + 44 + # defensive since issues could cause commenting in random places 45 + - name: Read PR number 46 + id: pr 47 + shell: bash 48 + run: | 49 + number="$(tr -cd '0-9' < ./pr/NR)" 50 + test -n "$number" 51 + echo "number=$number" >> "$GITHUB_OUTPUT" 52 + 53 + - name: Publish Touchstone plots 54 + if: ${{ steps.download_plots.outcome == 'success' }} 55 + uses: JamesIves/github-pages-deploy-action@v4.8.0 56 + with: 57 + branch: touchstone-plots 58 + folder: plots 59 + target-folder: pr-${{ steps.pr.outputs.number }} 60 + commit-message: touchstone plots for PR #${{ steps.pr.outputs.number }} 61 + clean: false 62 + 63 + - name: Build comment body 64 + shell: bash 65 + env: 66 + PR_NUMBER: ${{ steps.pr.outputs.number }} 67 + run: | 68 + set -euo pipefail 69 + 70 + cp ./pr/info.txt ./comment.txt 71 + 72 + if ! compgen -G "./plots/*.png" > /dev/null; then 73 + exit 0 74 + fi 75 + 76 + { 77 + printf '\n\n<details>\n<summary>Plots</summary>\n\n' 78 + 79 + for plot in ./plots/*.png; do 80 + file="$(basename "$plot")" 81 + label="${file%.png}" 82 + printf '![%s](../blob/touchstone-plots/pr-%s/%s?raw=true)\n\n' "$label" "$PR_NUMBER" "$file" 83 + done 84 + 85 + printf '</details>\n' 86 + } >> ./comment.txt 87 + 88 + - name: Create or update sticky PR comment 89 + id: comment 90 + uses: marocchino/sticky-pull-request-comment@v3 91 + with: 92 + GITHUB_TOKEN: ${{ github.token }} 93 + number_force: ${{ steps.pr.outputs.number }} 94 + header: touchstone 95 + path: ./comment.txt
+60
.github/workflows/touchstone-receive.yaml
··· 1 + name: Continuous Benchmarks (Receive) 2 + 3 + concurrency: 4 + group: ${{ github.workflow }}-${{ github.head_ref }} 5 + cancel-in-progress: true 6 + 7 + on: 8 + pull_request: 9 + 10 + permissions: 11 + contents: read 12 + 13 + jobs: 14 + prepare: 15 + runs-on: ubuntu-latest 16 + if: 17 + true && 18 + ( 19 + github.event.pull_request.author_association == 'OWNER' || 20 + github.event.pull_request.author_association == 'MEMBER' || 21 + github.event.pull_request.author_association == 'COLLABORATOR' 22 + ) 23 + outputs: 24 + config: ${{ steps.read_touchstone_config.outputs.config }} 25 + steps: 26 + - name: Checkout repo 27 + uses: actions/checkout@v6 28 + with: 29 + fetch-depth: 0 30 + 31 + - id: read_touchstone_config 32 + run: | 33 + content=`cat ./touchstone/config.json` 34 + # the following lines are only required for multi line json 35 + content="${content//'%'/'%25'}" 36 + content="${content//$'\n'/'%0A'}" 37 + content="${content//$'\r'/'%0D'}" 38 + # end of optional handling for multi line json 39 + echo "::set-output name=config::$content" 40 + build: 41 + needs: prepare 42 + runs-on: ${{ matrix.config.os }} 43 + strategy: 44 + fail-fast: false 45 + matrix: 46 + config: 47 + - ${{ fromJson(needs.prepare.outputs.config) }} 48 + env: 49 + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 50 + RSPM: ${{ matrix.config.rspm }} 51 + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 52 + steps: 53 + - uses: lorenzwalthert/touchstone/actions/receive@v1 54 + with: 55 + cache-version: 1 56 + benchmarking_repo: ${{ matrix.config.benchmarking_repo }} 57 + benchmarking_ref: ${{ matrix.config.benchmarking_ref }} 58 + benchmarking_path: ${{ matrix.config.benchmarking_path }} 59 + force_upstream: true 60 + r-version: ${{ matrix.config.r }}
+1
DESCRIPTION
··· 15 15 Imports: 16 16 fs, 17 17 spelling, 18 + touchstone, 18 19 usethis, 19 20 utils 20 21 Suggests:
+2
NAMESPACE
··· 7 7 export(setup_dependabot) 8 8 export(setup_gha) 9 9 export(setup_precommit) 10 + export(setup_touchstone) 10 11 export(use_license) 11 12 importFrom(spelling,update_wordlist) 13 + importFrom(touchstone,use_touchstone) 12 14 importFrom(utils,person)
+1
R/bootstrapper-package.R
··· 3 3 4 4 ## usethis namespace: start 5 5 #' @importFrom spelling update_wordlist 6 + #' @importFrom touchstone use_touchstone 6 7 #' @importFrom utils person 7 8 ## usethis namespace: end 8 9
+24 -1
R/bootstrapper.R
··· 78 78 setup_gha = TRUE, 79 79 setup_dependabot = TRUE, 80 80 setup_AGENTS = FALSE, 81 - setup_precommit = TRUE 81 + setup_precommit = TRUE, 82 + setup_touchstone = TRUE 82 83 ) { 83 84 tryCatch( 84 85 usethis::use_testthat(), ··· 109 110 } 110 111 if (setup_precommit) { 111 112 setup_precommit() 113 + } 114 + if (setup_touchstone) { 115 + setup_touchstone() 112 116 } 113 117 114 118 # cleanup ··· 231 235 copy_template_file("pre-commit", fs::path(".git", "hooks", "pre-commit")) 232 236 Sys.chmod(fs::path(".git", "hooks", "pre-commit"), mode = "0755") 233 237 invisible(NULL) 238 + } 239 + 240 + #' Configure Touchstone 241 + #' 242 + #' Write a modified Touchstone GHA to benchmark PRs. You still 243 + #' need to write an appropriate `script.R` for the actual 244 + #' benchmarks. This version of the touchstone commenting GHA 245 + #' updates a single comment instead of making multiple, and also 246 + #' adds the touchstone plots in a dropdown. These are stored on a new 247 + #' branch. 248 + #' 249 + #' @return Invisibly returns `NULL`. 250 + #' @export 251 + setup_touchstone <- function() { 252 + suppressWarnings(touchstone::use_touchstone()) 253 + copy_template_file( 254 + "touchstone-comment.yaml", 255 + fs::path(".github", "workflows", "touchstone-comment.yaml") 256 + ) 234 257 } 235 258 236 259 #' Remove RStudio Project Ignore Entries
+95
inst/templates/touchstone-comment.yaml
··· 1 + name: Continuous Benchmarks (Comment) 2 + 3 + concurrency: 4 + group: ${{ github.workflow }}-${{ github.head_ref }} 5 + cancel-in-progress: true 6 + 7 + on: 8 + workflow_run: 9 + workflows: [ "Continuous Benchmarks (Receive)" ] 10 + types: [ completed ] 11 + 12 + jobs: 13 + comment: 14 + runs-on: ubuntu-latest 15 + permissions: 16 + actions: read 17 + contents: write 18 + pull-requests: write 19 + if: ${{ github.event.workflow_run.event == 'pull_request' }} 20 + steps: 21 + - uses: actions/checkout@v6 22 + 23 + - name: Download Touchstone comment artifact 24 + id: download_comment 25 + uses: actions/download-artifact@v8 26 + with: 27 + name: pr 28 + path: ./pr 29 + github-token: ${{ github.token }} 30 + repository: ${{ github.repository }} 31 + run-id: ${{ github.event.workflow_run.id }} 32 + 33 + - name: Download Touchstone plot artifact 34 + id: download_plots 35 + continue-on-error: true 36 + uses: actions/download-artifact@v8 37 + with: 38 + name: visual-benchmarks 39 + path: ./plots 40 + github-token: ${{ github.token }} 41 + repository: ${{ github.repository }} 42 + run-id: ${{ github.event.workflow_run.id }} 43 + 44 + # defensive since issues could cause commenting in random places 45 + - name: Read PR number 46 + id: pr 47 + shell: bash 48 + run: | 49 + number="$(tr -cd '0-9' < ./pr/NR)" 50 + test -n "$number" 51 + echo "number=$number" >> "$GITHUB_OUTPUT" 52 + 53 + - name: Publish Touchstone plots 54 + if: ${{ steps.download_plots.outcome == 'success' }} 55 + uses: JamesIves/github-pages-deploy-action@v4.8.0 56 + with: 57 + branch: touchstone-plots 58 + folder: plots 59 + target-folder: pr-${{ steps.pr.outputs.number }} 60 + commit-message: touchstone plots for PR #${{ steps.pr.outputs.number }} 61 + clean: false 62 + 63 + - name: Build comment body 64 + shell: bash 65 + env: 66 + PR_NUMBER: ${{ steps.pr.outputs.number }} 67 + run: | 68 + set -euo pipefail 69 + 70 + cp ./pr/info.txt ./comment.txt 71 + 72 + if ! compgen -G "./plots/*.png" > /dev/null; then 73 + exit 0 74 + fi 75 + 76 + { 77 + printf '\n\n<details>\n<summary>Plots</summary>\n\n' 78 + 79 + for plot in ./plots/*.png; do 80 + file="$(basename "$plot")" 81 + label="${file%.png}" 82 + printf '![%s](../blob/touchstone-plots/pr-%s/%s?raw=true)\n\n' "$label" "$PR_NUMBER" "$file" 83 + done 84 + 85 + printf '</details>\n' 86 + } >> ./comment.txt 87 + 88 + - name: Create or update sticky PR comment 89 + id: comment 90 + uses: marocchino/sticky-pull-request-comment@v3 91 + with: 92 + GITHUB_TOKEN: ${{ github.token }} 93 + number_force: ${{ steps.pr.outputs.number }} 94 + header: touchstone 95 + path: ./comment.txt
+2 -1
man/pkg_setup.Rd
··· 8 8 setup_gha = TRUE, 9 9 setup_dependabot = TRUE, 10 10 setup_AGENTS = FALSE, 11 - setup_precommit = TRUE 11 + setup_precommit = TRUE, 12 + setup_touchstone = TRUE 12 13 ) 13 14 } 14 15 \arguments{
+19
man/setup_touchstone.Rd
··· 1 + % Generated by roxygen2: do not edit by hand 2 + % Please edit documentation in R/bootstrapper.R 3 + \name{setup_touchstone} 4 + \alias{setup_touchstone} 5 + \title{Configure Touchstone} 6 + \usage{ 7 + setup_touchstone() 8 + } 9 + \value{ 10 + Invisibly returns \code{NULL}. 11 + } 12 + \description{ 13 + Write a modified Touchstone GHA to benchmark PRs. You still 14 + need to write an appropriate \code{script.R} for the actual 15 + benchmarks. This version of the touchstone commenting GHA 16 + updates a single comment instead of making multiple, and also 17 + adds the touchstone plots in a dropdown. These are stored on a new 18 + branch. 19 + }
+6
touchstone/.gitignore
··· 1 + * 2 + !script.R 3 + !config.json 4 + !.gitignore 5 + !header.R 6 + !footer.R
+8
touchstone/config.json
··· 1 + { 2 + "os": "ubuntu-20.04", 3 + "r": "4.1.1", 4 + "rspm": "https://packagemanager.rstudio.com/all/__linux__/focal/2022-01-07+MTo3NDQwNTcyLDI6NDUyNjIxNTs0QzU3NUZBRQ", 5 + // "benchmarking_repo": "lorenzwalthert/here", 6 + // "benchmarking_ref": "ca9c8e69c727def88d8ba1c8b85b0e0bcea87b3f", 7 + "benchmarking_path": "touchstone/sources/here", 8 + }
+10
touchstone/footer.R
··· 1 + # You can modify the PR comment footer here. You can use github markdown e.g. 2 + # emojis like :tada:. 3 + # This file will be parsed and evaluate within the context of 4 + # `benchmark_analyze` and should return the comment text as the last value. 5 + # See `?touchstone::pr_comment` 6 + link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html" 7 + glue::glue( 8 + "\nFurther explanation regarding interpretation and", 9 + " methodology can be found in the [documentation]({link})." 10 + )
+13
touchstone/header.R
··· 1 + # You can modify the PR comment header here. You can use github markdown e.g. 2 + # emojis like :tada:. 3 + # This file will be parsed and evaluate within the context of 4 + # `benchmark_analyze` and should return the comment text as the last value. 5 + # Available variables for glue substitution: 6 + # * ci: confidence interval 7 + # * branches: BASE and HEAD branches benchmarked against each other. 8 + # See `?touchstone::pr_comment` 9 + glue::glue( 10 + "This is how benchmark results would change (along with a", 11 + " {100 * ci}% confidence interval in relative change) if ", 12 + "{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n" 13 + )
+29
touchstone/script.R
··· 1 + # see `help(run_script, package = 'touchstone')` on how to run this 2 + # interactively 3 + 4 + # TODO OPTIONAL Add directories you want to be available in this file or during the 5 + # benchmarks. 6 + # touchstone::pin_assets("some/dir") 7 + 8 + # installs branches to benchmark 9 + touchstone::branch_install() 10 + 11 + # benchmark a function call from your package (two calls per branch) 12 + touchstone::benchmark_run( 13 + # expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark 14 + random_test = yourpkg::f(), #<- TODO put the call you want to benchmark here 15 + n = 2 16 + ) 17 + 18 + # TODO OPTIONAL benchmark any R expression (six calls per branch) 19 + # touchstone::benchmark_run( 20 + # more = { 21 + # if (TRUE) { 22 + # y <- yourpkg::f2(x = 3) 23 + # } 24 + # }, #<- TODO put the call you want to benchmark here 25 + # n = 6 26 + # ) 27 + 28 + # create artifacts used downstream in the GitHub Action 29 + touchstone::benchmark_analyze()