😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

168 lines
6.1KB

  1. # Workflow inspired by:
  2. # - https://github.com/rstudio/shinycoreci/blob/master/.github/workflows/call-rituals.yaml
  3. # - https://github.com/r-lib/actions/blob/master/examples/lint.yaml
  4. # - https://github.com/r-lib/actions/blob/master/examples/render-rmarkdown.yaml
  5. on:
  6. pull_request:
  7. push:
  8. branches: main
  9. name: Package Maintenance
  10. jobs:
  11. pkg-maintenance:
  12. runs-on: ubuntu-latest
  13. env:
  14. GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
  15. # only add lintr annotations
  16. LINTR_COMMENT_BOT: false
  17. steps:
  18. - uses: actions/checkout@v2
  19. # Make sure the PR branch is checked out for pull requests
  20. - name: Git Pull (PR)
  21. if: github.event_name == 'pull_request'
  22. uses: r-lib/actions/pr-fetch@v1
  23. with:
  24. repo-token: ${{ github.token }}
  25. - name: Git Config
  26. run: |
  27. git config user.name "${GITHUB_ACTOR}"
  28. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  29. - uses: r-lib/actions/setup-r@v1
  30. with:
  31. use-public-rspm: true
  32. - uses: r-lib/actions/setup-pandoc@v1
  33. - uses: r-lib/actions/setup-r-dependencies@v1
  34. with:
  35. extra-packages: |
  36. lintr
  37. styler
  38. devtools
  39. rmarkdown
  40. - name: Tidy Description
  41. run: |
  42. Rscript -e 'usethis::use_tidy_description()'
  43. git add -u && git commit -m 'Tidy DESCRIPTION (GitHub Actions)' || echo "No DESCRIPTION changes to commit"
  44. - name: Document
  45. run: |
  46. Rscript -e 'roxygen2::roxygenise()'
  47. git add man/\* NAMESPACE DESCRIPTION && git commit -m 'Document (GitHub Actions)' || echo "No documentation changes to commit"
  48. - name: Build README and index
  49. run: |
  50. if [ -f "index.Rmd" ]; then
  51. Rscript -e 'rmarkdown::render("index.Rmd", quiet = FALSE, output_options = list(html_preview = FALSE))'
  52. git add index.md man/figures/index* && git commit -m 'Re-build index.Rmd (GitHub Actions)' || echo "No index.Rmd changes to commit"
  53. else
  54. echo "No index.Rmd to build"
  55. fi
  56. if [ -f "README.Rmd" ]; then
  57. Rscript -e 'devtools::build_readme(quiet = FALSE)'
  58. git add README.md && git commit -m 'Re-build README.Rmd (GitHub Actions)' || echo "No readme changes to commit"
  59. else
  60. echo "No README.Rmd to build"
  61. fi
  62. - name: URL redirects
  63. if: github.event_name == 'push'
  64. run: |
  65. Rscript -e 'pak::pkg_install("r-lib/urlchecker"); urlchecker::url_update()'
  66. git add -u && git commit -m 'Update links (GitHub Actions)' || echo "No link changes to commit"
  67. - name: Whitespace - Fix indents and trailing
  68. run: |
  69. # tabs to spaces and remove trailing whitespace
  70. transform_indent_two_spaces <- styler::create_style_guide(
  71. style_guide_name = "Indent with two spaces",
  72. style_guide_version = "1.0.0",
  73. indention = local({
  74. ts <- styler::tidyverse_style()$indention
  75. ts$unindent_fun_dec <- NULL
  76. ts$update_indention_ref_fun_dec <- NULL
  77. ts
  78. }),
  79. reindention = styler::specify_reindention(indention = 2, comments_only = FALSE)
  80. )
  81. styler::style_pkg(transformers = transform_indent_two_spaces)
  82. shell: Rscript {0}
  83. - name: Whitespace - Commit
  84. run: |
  85. git add -u && git commit -m 'Fix whitespace (GitHub Actions)' || echo 'No whitespace changes to commit'
  86. # When pushing to main causes package maintenance, create a pull request
  87. - name: Create Pull Request
  88. id: create-pull-request
  89. if: github.event_name == 'push'
  90. uses: peter-evans/create-pull-request@v3
  91. with:
  92. base: main
  93. branch: auto-pkg-maintenance
  94. commit-message: "Package maintenance (Github Actions)"
  95. title: "Automated package maintenance"
  96. body: >
  97. Automated package maintenance changes from
  98. <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}>
  99. - name: Notify Pull Request
  100. if: steps.create-pull-request.outputs.pull-request-operation
  101. run: |
  102. echo "::notice title=Package Maintenance:: Pull request #${{ steps.create-pull-request.outputs.pull-request-number }} ${{ steps.create-pull-request.outputs.pull-request-operation }}: ${{ steps.create-pull-request.outputs.pull-request-url }}"
  103. # If we're in a PR, then push back to the PR branch
  104. - name: Git Push (PR)
  105. uses: r-lib/actions/pr-push@v1
  106. if: github.event_name == 'pull_request'
  107. with:
  108. repo-token: ${{ secrets.GITHUB_TOKEN }}
  109. - name: Lint Package
  110. if: github.event_name == 'pull_request'
  111. run: |
  112. # lint package and add notice-style file annotations
  113. Sys.setlocale(locale = "C")
  114. Sys.setenv(R_CLI_NUM_COLORS = 1)
  115. lints <- lintr::lint_package(cache = FALSE)
  116. informal_linters <- c(
  117. "closed_curly_linter",
  118. "commas_linter",
  119. "function_left_parentheses_linter",
  120. "line_length_linter",
  121. "object_length_linter",
  122. "object_name_linter",
  123. "open_curly_linter",
  124. "paren_brace_linter",
  125. "pipe_continuation_linter",
  126. "single_quotes_linter",
  127. "spaces_inside_linter",
  128. "spaces_left_parentheses_linter",
  129. "trailing_blank_lines_linter",
  130. "trailing_whitespace_linter"
  131. )
  132. for (lint in lints) {
  133. msg <- sprintf(
  134. "\n::%s file=%s,line=%d,col=%d,endColumn=%d,title=%s::%s",
  135. if (lint$linter %in% informal_linters) "notice" else "warning",
  136. lint$filename,
  137. lint$line_number,
  138. lint$ranges[[1]][[1]],
  139. lint$ranges[[1]][[2]],
  140. paste("lintr", lint$type, lint$linter, sep = " - "),
  141. # print lintr message as GHA-compatible multiline log message
  142. paste(capture.output(print(lint)), collapse = "%0A")
  143. )
  144. cat(msg)
  145. }
  146. shell: Rscript {0}