Skip to content

Commit 6af10a5

Browse files
Add extra workflows
1 parent b44acbe commit 6af10a5

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
# Adapted from Epiverse packages: https://github.com/epiverse-trace
4+
on:
5+
pull_request:
6+
paths:
7+
- 'DESCRIPTION'
8+
9+
name: Analyze dependency changes
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
pull-requests: write
17+
18+
jobs:
19+
dependency-changes:
20+
runs-on: ubuntu-latest
21+
env:
22+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23+
steps:
24+
- name: Setup R
25+
uses: r-lib/actions/setup-r@v2
26+
with:
27+
use-public-rspm: true
28+
29+
- name: Install dependencies
30+
uses: r-lib/actions/setup-r-dependencies@v2
31+
with:
32+
packages: any::pak, glue, gh
33+
34+
- name: Analyze dependency changes
35+
shell: Rscript {0}
36+
run: |
37+
deps_base <- pak::pkg_deps("${{ github.repository }}@${{ github.base_ref }}", dependencies = TRUE) |>
38+
subset(!directpkg) |>
39+
subset(is.na(priority))
40+
# We install from PR number rather than branch to deal with the case
41+
# of PR coming from forks
42+
deps_head <- pak::pkg_deps("${{ github.repository }}#${{ github.event.number }}", dependencies = TRUE) |>
43+
subset(!directpkg) |>
44+
subset(is.na(priority))
45+
46+
deps_added <- deps_head |>
47+
subset(!ref %in% deps_base$ref)
48+
49+
deps_removed <- deps_base |>
50+
subset(!ref %in% deps_head$ref)
51+
52+
if (nrow(deps_added) + nrow(deps_removed) > 0) {
53+
54+
message("Dependencies have changed! Analyzing...")
55+
56+
if (nrow(deps_added) > 0) {
57+
nudge <- "Reach out on slack (`#code-review` or `#help` channels) to double check if there are base R alternatives to the new dependencies.\n"
58+
} else {
59+
nudge <- ""
60+
}
61+
62+
msg <- glue::glue(
63+
.sep = "\n",
64+
"This pull request:",
65+
"- Adds {nrow(deps_added)} new dependencies (direct and indirect)",
66+
"- Adds {length(unique(deps_added$sysreqs))} new system dependencies",
67+
"- Removes {nrow(deps_removed)} existing dependencies (direct and indirect)",
68+
"- Removes {length(unique(deps_removed$sysreqs))} existing system dependencies",
69+
"",
70+
nudge,
71+
"(Note that results may be inaccurate if you branched from an outdated version of the target branch.)"
72+
)
73+
74+
message("Posting results as a pull request comment.")
75+
76+
gh::gh(
77+
"POST /repos/{repo}/issues/{issue_number}/comments",
78+
repo = "${{ github.repository }}",
79+
issue_number = "${{ github.event.number }}",
80+
body = msg
81+
)
82+
83+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Adapted from Epiverse packages: https://github.com/epiverse-trace
2+
# Reproduce locally by running:
3+
# ```r
4+
# pak::pak(c("any::rmarkdown", "any::usethis", "."))
5+
# writeLines(
6+
# knitr::knit_expand(
7+
# "README.Rmd",
8+
# packagename = read.dcf("DESCRIPTION", "Package"),
9+
# gh_repo = usethis:::github_remote_list()$repo_spec
10+
# ),
11+
# "README_expanded.Rmd"
12+
# )
13+
# rmarkdown::render(
14+
# "README_expanded.Rmd",
15+
# output_file = "README.md",
16+
# output_dir = "."
17+
# )
18+
# unlink("README_expanded.Rmd")
19+
# ```
20+
name: render-readme
21+
22+
# Controls when the action will run. Triggers include:
23+
#
24+
# - button trigger from github action page
25+
# - on changes to readme.Rmd
26+
27+
on:
28+
workflow_dispatch:
29+
push:
30+
branches:
31+
# This may seem like a no-op but it prevents triggering on tags
32+
# We use '**' rather '*' to accomodate names like 'dev/branch-1'
33+
- '**'
34+
paths:
35+
- 'README.Rmd'
36+
- '.github/workflows/render_readme.yml'
37+
38+
concurrency:
39+
group: ${{ github.workflow }}-${{ github.ref }}
40+
cancel-in-progress: true
41+
42+
permissions:
43+
contents: write
44+
45+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
46+
jobs:
47+
render-readme:
48+
runs-on: ubuntu-latest
49+
env:
50+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
51+
steps:
52+
- name: Checkout repos
53+
uses: actions/checkout@v4
54+
55+
- name: Setup R
56+
uses: r-lib/actions/setup-r@v2
57+
with:
58+
use-public-rspm: true
59+
60+
- name: Setup pandoc
61+
uses: r-lib/actions/setup-pandoc@v2
62+
63+
- name: Install dependencies
64+
uses: r-lib/actions/setup-r-dependencies@v2
65+
with:
66+
extra-packages: any::rmarkdown, local::.
67+
68+
- name: Compile the readme
69+
run: |
70+
writeLines(
71+
knitr::knit_expand(
72+
"README.Rmd",
73+
packagename = read.dcf("DESCRIPTION", "Package"),
74+
gh_repo = Sys.getenv("GITHUB_REPOSITORY")
75+
),
76+
"README_expanded.Rmd"
77+
)
78+
rmarkdown::render(
79+
"README_expanded.Rmd",
80+
output_file = "README.md",
81+
output_dir = "."
82+
)
83+
shell: Rscript {0}
84+
85+
- name: Commit files
86+
run: |
87+
git config --local user.email "action@github.com"
88+
git config --local user.name "GitHub Action"
89+
git add README.md
90+
# Also add README figures if they exist
91+
if [ -d man/figures ]
92+
then
93+
git add man/figures/
94+
fi
95+
git diff-index --quiet HEAD || git commit -m "Automatic readme update"
96+
git pull --rebase origin ${{ github.ref.name }}
97+
git push origin || echo "No changes to push"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Adapted from Epiverse packages: https://github.com/epiverse-trace
2+
name: Update copyright year(s) in license file
3+
4+
on:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: '0 3 1 1 *'
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
run:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- uses: FantasticFiasco/action-update-license-year@v3
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
path: |
24+
LICENSE.md
25+
prBody: >
26+
This PR updates the copyright license for this new year! If you're reading this while you're celebrating, enjoy! Don't worry about this one :blush:
27+
28+
![Happy new year!](https://media.giphy.com/media/HyDfNCZlTn5iU/giphy.gif?cid=ecf05e4777yl7dbo1xfha6bx1z5lrl13uq7biv6rs9dqsyoh&ep=v1_gifs_search&rid=giphy.gif&ct=g)
29+
- uses: FantasticFiasco/action-update-license-year@v3
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
path: |
33+
LICENSE
34+
prBody: >
35+
This PR updates the copyright license for this new year! If you're reading this while you're celebrating, enjoy! Don't worry about this one :blush:
36+
37+
![Happy new year!](https://media.giphy.com/media/HyDfNCZlTn5iU/giphy.gif?cid=ecf05e4777yl7dbo1xfha6bx1z5lrl13uq7biv6rs9dqsyoh&ep=v1_gifs_search&rid=giphy.gif&ct=g)
38+
transform: (?<=YEAR:\s)(?<from>\d{4})?-?(\d{4})?

0 commit comments

Comments
 (0)