Skip to content

Commit

Permalink
Merge pull request #1386 from quarto-dev/issue/10277
Browse files Browse the repository at this point in the history
Script to automate release notes
  • Loading branch information
cwickham authored Oct 23, 2024
2 parents d2e9d52 + d4966f0 commit 937b2cd
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 26 deletions.
23 changes: 22 additions & 1 deletion docs/download/_download-older.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,25 @@
- id: version10
title: v1.0.38
date: 2022/08/04
url: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.0.38
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.0.38
- id: version11
title: v1.1.189
date: 2022/09/04
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.1.189
changelog: "[Release Notes](changelog/1.1/)"
- id: version12
title: v1.2.475
date: 2023/03/22
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.2.475
changelog: "[Release Notes](changelog/1.2/)"
- id: version13
title: v1.3.450
date: 2023/08/23
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.3.450
changelog: "[Release Notes](changelog/1.3/)"
- id: version14
title: v1.4.557
date: 2024/06/27
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.4.557
changelog: "[Release Notes](changelog/1.4/)"

27 changes: 2 additions & 25 deletions docs/download/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,8 @@ editor: source
image: /images/hero_right.png
listing:
id: download-older
contents:
- id: version14
title: v1.4.557
date: 2024/06/27
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.4.557
changelog: "[Release Notes](changelog/1.4/)"
- id: version13
title: v1.3.450
date: 2023/08/23
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.3.450
changelog: "[Release Notes](changelog/1.3/)"
- id: version12
title: v1.2.475
date: 2023/03/22
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.2.475
changelog: "[Release Notes](changelog/1.2/)"
- id: version11
title: v1.1.189
date: 2022/09/04
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.1.189
changelog: "[Release Notes](changelog/1.1/)"
- id: version10
title: v1.0.38
date: 2022/08/04
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v1.0.38
contents: /_download-older.yml
sort: "date desc"
fields:
- title
- changelog
Expand Down
98 changes: 98 additions & 0 deletions tools/release-notes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
library(fs)
library(stringr)
library(glue)
library(jsonlite)
library(gh)

downloads <- path("docs", "download")

# Current versions -------------------------------------------------------

# Based on updated download files
new_release <- read_json(path(downloads, "_download.json"))$version
new_prerelease <- read_json(path(downloads, "_prerelease.json"))$version

# Old version from Git history -------------------------------------------

# Need version at two commits ago
previous_commit <- gh("https://api.github.com/repos/:owner/:repo/commits",
owner = "quarto-dev", repo = "quarto-web",
path = "docs/download/_download.json",
per_page = 2)

previous_commit_ref <- previous_commit[[2]]$sha

previous_contents <- gh("/repos/{owner}/{repo}/contents/{path}",
owner = "quarto-dev", repo = "quarto-web",
path = "docs/download/_download.json",
ref = previous_commit_ref,
.accept = "application/vnd.github.raw+json")
previous_contents_json <- parse_json(previous_contents$message)

old_release <- previous_contents_json$version
old_release_date <- previous_contents_json$created

# Version numbers
extract_major <- function(x){
str_extract(x, "(\\d+)\\.(\\d+)")
}

new_release_major <- extract_major(new_release)
new_prerelease_major <- extract_major(new_prerelease)
major_version <- extract_major(old_release)

cat("Release:", old_release, "->", new_release, "\n")
cat("Prerelease:", major_version, "->", new_prerelease_major, "\n")

# Create new changelog content -------------------------------------------

changelog_url <- paste0("https://github.com/quarto-dev/quarto-cli/releases/download/v",
old_release, "/changelog.md")
changelog_dir <- dir_create(path(downloads, "changelog", major_version))

download_status <- download.file(changelog_url, path(changelog_dir,
"_changelog", ext = "md"))
stopifnot(!download_status)

glue("
---
title: {major_version} Release Notes
format: html
---
{{{{< include _changelog.md >}}}}
") |>
writeLines(path(changelog_dir, "index", ext = "qmd"))

# Increment versions of aliases ------------------------------------------

release_page <- path(downloads, "release", ext = "qmd")
prerelease_page <- path(downloads, "prerelease", ext = "qmd")

aliases <- paste0("changelog/",
c(major_version, new_release_major, new_prerelease_major),
"/")

readLines(release_page) |>
str_replace(aliases[1], aliases[2]) |>
writeLines(release_page)

readLines(prerelease_page) |>
str_replace(aliases[2], aliases[3]) |>
writeLines(prerelease_page)

# Update listing ------------------------------------------------

old_abbr <- str_split(major_version, "\\.")[[1]] |> paste0(collapse = "")

# Add new item to download-older listing in docs/download/index.qmd

glue('
\n- id: version{ old_abbr }
title: { old_release }
date: { format(as.Date(old_release_date), "%Y/%m/%d") }
path: https://github.com/quarto-dev/quarto-cli/releases/tag/v{ old_release }
changelog: "[Release Notes](changelog/{ major_version }/)"
') |>
cat(file = path(downloads, "_download-older.yml"), append = TRUE)

0 comments on commit 937b2cd

Please sign in to comment.