[mirror] Opinionated R package quickstart
0
fork

Configure Feed

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

Update tests

+249 -20
+95
tests/testthat/.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
tests/testthat/.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 }}
+21 -14
tests/testthat/_snaps/workflow.md
··· 3 3 Code 4 4 files[!grepl("^\\.git/", files)] 5 5 Output 6 - [1] ".Rbuildignore" 7 - [2] ".github/dependabot.yml" 8 - [3] ".github/workflows/check-standard.yaml" 9 - [4] ".github/workflows/format-suggest.yaml" 10 - [5] ".github/workflows/test-coverage.yaml" 11 - [6] ".vscode/extensions.json" 12 - [7] "AGENTS.md" 13 - [8] "DESCRIPTION" 14 - [9] "LICENSE.md" 15 - [10] "NEWS.md" 16 - [11] "README.md" 17 - [12] "air.toml" 18 - [13] "tests/jarl.toml" 19 - [14] "tests/testthat.R" 6 + [1] ".Rbuildignore" 7 + [2] ".github/dependabot.yml" 8 + [3] ".github/workflows/check-standard.yaml" 9 + [4] ".github/workflows/format-suggest.yaml" 10 + [5] ".github/workflows/test-coverage.yaml" 11 + [6] ".github/workflows/touchstone-comment.yaml" 12 + [7] ".github/workflows/touchstone-receive.yaml" 13 + [8] ".vscode/extensions.json" 14 + [9] "AGENTS.md" 15 + [10] "DESCRIPTION" 16 + [11] "LICENSE.md" 17 + [12] "NEWS.md" 18 + [13] "README.md" 19 + [14] "air.toml" 20 + [15] "tests/jarl.toml" 21 + [16] "tests/testthat.R" 22 + [17] "touchstone/.gitignore" 23 + [18] "touchstone/config.json" 24 + [19] "touchstone/footer.R" 25 + [20] "touchstone/header.R" 26 + [21] "touchstone/script.R" 20 27
+1
tests/testthat/_snaps/workflow/dot-Rbuildignore.txt
··· 1 1 README\.Rmd 2 2 AGENTS.md 3 + ^touchstone$
+1 -1
tests/testthat/_snaps/workflow/dot-github-workflows-check-standard.yaml
··· 1 1 name: check 2 2 steps: 3 3 - uses: actions/checkout@v6 4 - - uses: actions/upload-artifact@v6 4 + - uses: actions/upload-artifact@v7 5 5 - uses: JamesIves/github-pages-deploy-action@v4
+5 -5
tests/testthat/test-bootstrapper.R
··· 317 317 actions$replacements, 318 318 c( 319 319 "actions/checkout@v4 -> actions/checkout@v6", 320 - "actions/upload-artifact@v4 -> actions/upload-artifact@v6", 320 + "actions/upload-artifact@v4 -> actions/upload-artifact@v7", 321 321 "JamesIves/github-pages-deploy-action@v4.5.0 -> JamesIves/github-pages-deploy-action@v4" 322 322 ) 323 323 ) ··· 747 747 fs::path(".github", "workflows", "check.yml") 748 748 ) 749 749 find_replace_in_gha("actions/checkout@v4", "actions/checkout@v6") 750 - expect_true(grepl( 751 - "checkout@v6", 752 - readLines(fs::path(".github", "workflows", "check.yml")) 753 - )) 750 + expect_match( 751 + readLines(fs::path(".github", "workflows", "check.yml")), 752 + "checkout@v6" 753 + ) 754 754 })
+6
tests/testthat/touchstone/.gitignore
··· 1 + * 2 + !script.R 3 + !config.json 4 + !.gitignore 5 + !header.R 6 + !footer.R
+8
tests/testthat/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
tests/testthat/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
tests/testthat/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
tests/testthat/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()