Skip to content

Update publications #40

Update publications

Update publications #40

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@v2
- 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@10db75894f6d53fc01c3bb0995e95bd03e583a62
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@v2
- 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}