-
Notifications
You must be signed in to change notification settings - Fork 6
132 lines (108 loc) · 4.18 KB
/
update-publications.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
on:
workflow_dispatch:
schedule:
- cron: '0 5 1 * *'
name: Update publications
jobs:
update-bibtex:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
install-r: false
use-public-rspm: true
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- uses: r-lib/actions/setup-renv@v2
- name: Create bibtex file with selected entries
run: |
last_comment_pubs <- gh::gh(
"/repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
.accept = "application/vnd.github.v3.full+json"
) |>
purrr::keep(~ .x$user$login == "github-actions[bot]") |>
tail(1) |>
purrr::map_chr("body_html") |>
xml2::read_html()
last_comment_pubs |>
xml2::xml_find_first("//details") |>
xml2::xml_text() |>
write("bibentries_previous_month.bib")
bibentries_previous_month <- bibtex::read.bib("bibentries_previous_month.bib")
selected <- last_comment_pubs |>
xml2::xml_find_first("//ul") |>
xml2::xml_find_all("//input") |>
xml2::xml_has_attr("checked")
selected_bibentries <- bibentries_previous_month[selected]
bib_new <- vapply(selected_bibentries, format, style = "Bibtex", character(1))
bib_old <- readLines("_data/papers.bib")
bib <- paste(c(bib_old, bib_new), collapse = "\n")
write(bib, "_data/papers.bib")
shell: Rscript {0}
- uses: peter-evans/create-pull-request@v5
id: cpr
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Automated update of team publications
committer: epiforecasts-bot <[email protected]>
author: epiforecasts-bot <[email protected]>
branch: pubs
branch-suffix: timestamp
add-paths: _data/papers.bib
title: Automated update of team publications
delete-branch: true
fetch-new-papers:
needs: update-bibtex
if: always()
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
install-r: false
use-public-rspm: true
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- uses: r-lib/actions/setup-renv@v2
- name: Post a comment listing new papers
run: |
options(width = 10000) # do not hard-wrap formatted citations
source("_automation/get_new_papers.R")
month_1st <- format(lubridate::floor_date(lubridate::today()-1, "month"))
new_papers <- get_new_papers_team(from_date = month_1st)
if (nrow(new_papers) > 0) {
bibentries_new <- create_bibentries(new_papers)
saveRDS(bibentries_new, paste0("bibentries_previous_month.rds"))
bibentries_new_checklist <- paste("- [ ]", vapply(bibentries_new, format, character(1)))
bibentries_comment <- paste(
c(
"Papers published last month:",
bibentries_new_checklist,
"<details>",
"",
"```",
vapply(bibentries_new, format, character(1), "bibtex"),
"```",
"</details>"
),
collapse = "\n"
)
gh::gh(
"POST /repos/{gh_repo}/issues/{issue_number}/comments",
gh_repo = "${{ github.repository }}",
issue_number = 3,
body = bibentries_comment
)
}
shell: Rscript {0}