|
| 1 | +################################################################################ |
| 2 | +# DataSHIELD GHA test suite - dsBase |
| 3 | +# Adapted from `azure-pipelines.yml` by Roberto Villegas-Diaz |
| 4 | +# |
| 5 | +# Inside the root directory $(Pipeline.Workspace) will be a file tree like: |
| 6 | +# /dsBase <- Checked out version of datashield/dsBase |
| 7 | +# /dsBase/logs <- Where results of tests and logs are collated |
| 8 | +# /testStatus <- Checked out version of datashield/testStatus |
| 9 | +# |
| 10 | +# As of Jul 2025 this takes ~ 9 mins to run. |
| 11 | +################################################################################ |
| 12 | +name: dsBase tests' suite |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + - v6.3.3-dev |
| 19 | + |
| 20 | + schedule: |
| 21 | + - cron: '0 0 * * 0' # Weekly on master |
| 22 | + - cron: '0 1 * * *' # Nightly on v6.3.3-dev |
| 23 | + |
| 24 | +jobs: |
| 25 | + dsBase_test_suite: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 120 |
| 28 | + |
| 29 | + # These should all be constant, except TEST_FILTER. This can be used to test |
| 30 | + # subsets of test files in the testthat directory. Options are like: |
| 31 | + # '*' <- Run all tests. |
| 32 | + # 'asNumericDS*' <- Run all asNumericDS tests, i.e. all the arg, etc. tests. |
| 33 | + # '*_smk_*' <- Run all the smoke tests for all functions. |
| 34 | + env: |
| 35 | + TEST_FILTER: '*' |
| 36 | + _r_check_system_clock_: 0 |
| 37 | + WORKFLOW_ID: ${{ github.run_id }}-${{ github.run_attempt }} |
| 38 | + PROJECT_NAME: dsBase |
| 39 | + BRANCH_NAME: ${{ github.ref_name }} |
| 40 | + REPO_OWNER: ${{ github.repository_owner }} |
| 41 | + R_KEEP_PKG_SOURCE: yes |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Checkout dsBase |
| 45 | + uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + path: dsBase |
| 48 | + |
| 49 | + - name: Checkout testStatus |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + repository: ${{ env.REPO_OWNER }}/testStatus |
| 53 | + token: ${{ secrets.GH_TOKEN }} |
| 54 | + ref: master |
| 55 | + path: testStatus |
| 56 | + |
| 57 | + - uses: r-lib/actions/setup-pandoc@v2 |
| 58 | + |
| 59 | + - uses: r-lib/actions/setup-r@v2 |
| 60 | + with: |
| 61 | + r-version: release |
| 62 | + http-user-agent: release |
| 63 | + use-public-rspm: true |
| 64 | + |
| 65 | + - uses: r-lib/actions/setup-r-dependencies@v2 |
| 66 | + with: |
| 67 | + extra-packages: | |
| 68 | + any::rcmdcheck |
| 69 | + cran::devtools |
| 70 | + cran::git2r |
| 71 | + cran::RCurl |
| 72 | + cran::readr |
| 73 | + cran::magrittr |
| 74 | + cran::xml2 |
| 75 | + cran::purrr |
| 76 | + cran::dplyr |
| 77 | + cran::stringr |
| 78 | + cran::tidyr |
| 79 | + cran::quarto |
| 80 | + cran::knitr |
| 81 | + cran::kableExtra |
| 82 | + cran::rmarkdown |
| 83 | + cran::downlit |
| 84 | + needs: check |
| 85 | + |
| 86 | + - name: Check man files up-to-date |
| 87 | + run: | |
| 88 | + orig_sum=$(find man -type f | sort -u | xargs cat | md5sum) |
| 89 | + R -e "devtools::document()" |
| 90 | + new_sum=$(find man -type f | sort -u | xargs cat | md5sum) |
| 91 | + if [ "$orig_sum" != "$new_sum" ]; then |
| 92 | + echo "Your committed manual files (man/*.Rd) are out of sync with the R files. Run devtools::document() locally then commit." |
| 93 | + exit 1 |
| 94 | + else |
| 95 | + echo "Documentation up-to-date." |
| 96 | + fi |
| 97 | + working-directory: dsBase |
| 98 | + continue-on-error: true |
| 99 | + |
| 100 | + - name: Run devtools::check |
| 101 | + run: | |
| 102 | + R -q -e "library('devtools'); devtools::check(args = c('--no-tests', '--no-examples'))" | tee ../check.Rout |
| 103 | + grep -q "^0 errors" ../check.Rout && grep -q " 0 warnings" ../check.Rout && grep -q " 0 notes" ../check.Rout |
| 104 | + working-directory: dsBase |
| 105 | + continue-on-error: true |
| 106 | + |
| 107 | + - name: Run tests with coverage & JUnit report |
| 108 | + run: | |
| 109 | + mkdir -p logs |
| 110 | + R -q -e "devtools::reload();" |
| 111 | + R -q -e ' |
| 112 | + write.csv( |
| 113 | + covr::coverage_to_list( |
| 114 | + covr::package_coverage( |
| 115 | + type = c("none"), |
| 116 | + code = c('"'"' |
| 117 | + output_file <- file("test_console_output.txt"); |
| 118 | + sink(output_file); |
| 119 | + sink(output_file, type = "message"); |
| 120 | + junit_rep <- testthat::JunitReporter$new(file = file.path(getwd(), "test_results.xml")); |
| 121 | + progress_rep <- testthat::ProgressReporter$new(max_failures = 999999); |
| 122 | + multi_rep <- testthat::MultiReporter$new(reporters = list(progress_rep, junit_rep)); |
| 123 | + testthat::test_package("${{ env.PROJECT_NAME }}", filter = "${{ env.TEST_FILTER }}", reporter = multi_rep, stop_on_failure = FALSE)'"'"' |
| 124 | + ) |
| 125 | + ) |
| 126 | + ), |
| 127 | + "coveragelist.csv" |
| 128 | + )' |
| 129 | + |
| 130 | + mv coveragelist.csv logs/ |
| 131 | + mv test_* logs/ |
| 132 | + grep -q " FAIL 0 " logs/test_console_output.txt |
| 133 | + working-directory: dsBase |
| 134 | + |
| 135 | + - name: Check for JUnit errors |
| 136 | + run: | |
| 137 | + issue_count=$(sed 's/failures="0" errors="0"//' test_results.xml | grep -c errors= || true) |
| 138 | + echo "Number of testsuites with issues: $issue_count" |
| 139 | + sed 's/failures="0" errors="0"//' test_results.xml | grep errors= > issues.log || true |
| 140 | + cat issues.log || true |
| 141 | + exit $issue_count |
| 142 | + working-directory: dsBase/logs |
| 143 | + |
| 144 | + - name: Write versions to file |
| 145 | + run: | |
| 146 | + echo "branch:${{ env.BRANCH_NAME }}" > ${{ env.WORKFLOW_ID }}.txt |
| 147 | + echo "os:$(lsb_release -ds)" >> ${{ env.WORKFLOW_ID }}.txt |
| 148 | + echo "R:$(R --version | head -n1)" >> ${{ env.WORKFLOW_ID }}.txt |
| 149 | + working-directory: dsBase/logs |
| 150 | + |
| 151 | + - name: Parse results from testthat and covr |
| 152 | + run: | |
| 153 | + Rscript --verbose --vanilla ../testStatus/source/parse_test_report.R logs/ |
| 154 | + working-directory: dsBase |
| 155 | + |
| 156 | + - name: Commit results to testStatus |
| 157 | + # if: github.repository == 'villegar/dsBase' && github.event_name != 'pull_request' |
| 158 | + run: | |
| 159 | + git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 160 | + git config --global user.name "$GITHUB_ACTOR" |
| 161 | + cd testStatus |
| 162 | + git checkout master |
| 163 | + git pull |
| 164 | +
|
| 165 | + mkdir -p logs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/ |
| 166 | + mkdir -p docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/ |
| 167 | + mkdir -p docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/latest/ |
| 168 | + # clear the latest directory |
| 169 | + rm -rf docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/latest/* |
| 170 | + |
| 171 | + # Copy logs to new logs directory location |
| 172 | + cp -rv ../dsBase/logs/* logs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/ |
| 173 | + cp -rv ../dsBase/logs/${{ env.WORKFLOW_ID }}.txt logs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/ |
| 174 | + |
| 175 | + # Create symbolic links |
| 176 | + ln -sf ${{ env.WORKFLOW_ID }}/ logs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/.LATEST |
| 177 | + # ln -sf docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/ docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/latest |
| 178 | + |
| 179 | + R -e 'input_dir <- file.path("../logs", Sys.getenv("PROJECT_NAME"), Sys.getenv("BRANCH_NAME"), Sys.getenv("WORKFLOW_ID")); quarto::quarto_render("source/test_report.qmd", execute_params = list(input_dir = input_dir))' |
| 180 | + mv source/test_report.html docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/index.html |
| 181 | + cp -r docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/${{ env.WORKFLOW_ID }}/* docs/${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }}/latest |
| 182 | +
|
| 183 | + git add . |
| 184 | + git commit -m "Auto test for ${{ env.PROJECT_NAME }}/${{ env.BRANCH_NAME }} @ ${{ env.WORKFLOW_ID }}" |
| 185 | + git push |
| 186 | + |
| 187 | + env: |
| 188 | + PROJECT_NAME: ${{ env.PROJECT_NAME }} |
| 189 | + BRANCH_NAME: ${{ env.BRANCH_NAME }} |
| 190 | + WORKFLOW_ID: ${{ env.WORKFLOW_ID }} |
| 191 | + |
| 192 | + - name: Dump environment info |
| 193 | + run: | |
| 194 | + echo -e "\n#############################" |
| 195 | + echo -e "ls /: ######################" |
| 196 | + ls -al . |
| 197 | + echo -e "\n#############################" |
| 198 | + echo -e "lscpu: ######################" |
| 199 | + lscpu |
| 200 | + echo -e "\n#############################" |
| 201 | + echo -e "memory: #####################" |
| 202 | + free -m |
| 203 | + echo -e "\n#############################" |
| 204 | + echo -e "env: ########################" |
| 205 | + env |
| 206 | + echo -e "\n#############################" |
| 207 | + echo -e "R sessionInfo(): ############" |
| 208 | + R -e 'sessionInfo()' |
| 209 | + sudo apt install tree -y |
| 210 | + tree . |
| 211 | +
|
0 commit comments