Automate release post publication #455
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
schedule: | |
- cron: 32 23 * * * | |
name: Automate release post publication | |
jobs: | |
automate-release-post: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
use-public-rspm: true | |
- uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
packages: | | |
gh | |
glue | |
purrr | |
lubridate | |
knitr | |
usethis | |
- name: Check for new releases | |
run: | | |
source("_scripts/create_release_post.R") | |
library(gh) | |
org <- "epiverse-trace" | |
repos <- gh::gh( | |
"/orgs/{org}/repos", | |
org = org, | |
per_page = 100 | |
) |> | |
purrr::discard(\(x) x$private) |> | |
purrr::keep(\(x) "r-package" %in% x$topics) |> | |
purrr::map_chr("full_name") | |
release_today <- repos |> | |
purrr::set_names() |> | |
purrr::map( | |
~ gh::gh("/repos/{full_name}/releases", full_name = .x, per_page = 1) | |
) |> | |
purrr::map(unlist, recursive = FALSE) |> | |
purrr::keep(~ isTRUE(difftime(lubridate::ymd_hms(.x$published_at), lubridate::now(), units = "days") > -1)) |> | |
# Drop release with patch number != 0. | |
# We use negation (discard not 0), rather than keeping 0, to address the case where patch number may be unspecified | |
purrr::discard(~ grepl("\\d+\\.\\d+\\.[1-9]\\d*$", .x$tag_name)) | |
if (!is.null(release_today)) { | |
release_today |> | |
purrr::iwalk(create_release_post) | |
} | |
shell: Rscript {0} | |
- uses: peter-evans/create-pull-request@10db75894f6d53fc01c3bb0995e95bd03e583a62 | |
id: cpr | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: Automated release blog post `${{ env.PACKAGE }}` - `${{ env.PACKAGE_VERSION }}` | |
committer: epiverse-trace-bot <[email protected]> | |
author: epiverse-trace-bot <[email protected]> | |
branch: automated-release-post | |
branch-suffix: timestamp | |
add-paths: posts | |
title: Automated release blog post `${{ env.PACKAGE }}` - `${{ env.PACKAGE_VERSION }}` | |
delete-branch: true |