forked from remindmodel/remind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request remindmodel#1871 from dklein-pik/develop
Add scripts for preparing a release
- Loading branch information
Showing
5 changed files
with
179 additions
and
9 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
#' construct list of input data files | ||
#' @param cfg list of configs | ||
#' @param remindPath path to REMIND main folder | ||
|
||
defineInputData <- function(cfg, remindPath = ".") { | ||
|
||
regicode <- madrat::regionscode(file.path(remindPath, cfg$regionmapping)) | ||
cfg$input <- c(paste0("rev",cfg$inputRevision,"_",regicode,"_", tolower(cfg$model_name),".tgz"), | ||
paste0("rev",cfg$inputRevision,"_",regicode,ifelse(cfg$extramappings_historic == "","",paste0("-", madrat::regionscode(cfg$extramappings_historic))),"_", tolower(cfg$validationmodel_name),".tgz"), | ||
paste0("CESparametersAndGDX_",cfg$CESandGDXversion,".tgz")) | ||
|
||
# Specify for each element of input_new whether to stop if the respective file could not be downloaded | ||
cfg$stopOnMissing <- c(TRUE, FALSE, TRUE) | ||
return(cfg) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This script is part of a longer workflow. | ||
# Before running this script please perform the steps described here | ||
# https://gitlab.pik-potsdam.de/REMIND/remind-rse/-/wikis/How-to-create-a-REMIND-release | ||
|
||
# in your fork switch to develop and execute this script in the main folder Rscript scripts/utils/postRelease.R | ||
|
||
postRelease <- function() { | ||
gert::git_fetch("upstream") | ||
gert::git_merge("upstream/master") | ||
|
||
pattern <- "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)." | ||
stopifnot(any(grepl(pattern, readLines("CHANGELOG.md"), fixed = TRUE))) | ||
textToAdd <- paste("", | ||
"", | ||
"", | ||
"## [Unreleased]", | ||
"", | ||
"### input data/calibration", | ||
"", | ||
"### changed", | ||
"-", | ||
"", | ||
"### added", | ||
"-", | ||
"", | ||
"### removed", | ||
"-", | ||
"", | ||
"### fixed", | ||
"-", | ||
sep = "\n") | ||
|
||
readLines("CHANGELOG.md") |> | ||
sub(pattern = pattern, replacement = paste0(pattern, textToAdd), fixed = TRUE) |> | ||
writeLines("CHANGELOG.md") | ||
|
||
message("Please perform the following step manually:\n", | ||
"git add -p\n", | ||
"--> When done press ENTER to commit, push and create PR") | ||
gms::getLine() | ||
|
||
gert::git_commit("merge master into develop") | ||
gert::git_push() | ||
# gh pr create --help | ||
# --base branch The branch into which you want your code merged | ||
# --head branch The branch that contains commits for your pull request (default [current branch]) | ||
system(paste0("gh pr create --base develop --title 'merge master into develop' --body ''")) | ||
} | ||
|
||
postRelease() | ||
message("warnings:") | ||
print(warnings()) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# This script is part of a longer workflow. | ||
# Before running this script please perform the steps described here | ||
# https://gitlab.pik-potsdam.de/REMIND/remind-rse/-/wikis/How-to-create-a-REMIND-release | ||
|
||
# in your fork switch to temporary branch (e.g. release-candidate) and | ||
# execute this script in the main folder Rscript scripts/utils/release.R x.y.z | ||
|
||
release <- function(newVersion) { | ||
if (Sys.which("sbatch") == "") { | ||
stop("release must be created on cluster") | ||
} | ||
|
||
releaseDate <- format(Sys.time(), "%Y-%m-%d") | ||
|
||
# Get old version from CITATION.cff | ||
oldVersion <- readLines("CITATION.cff") |> | ||
grep(pattern = "^version: (.*)$", value = TRUE) |> | ||
sub(pattern = "^version: (.*)$", replacement = "\\1") |> | ||
sub(pattern = "dev", replacement = "") | ||
|
||
# Update CHANGELOG.md | ||
githubUrl <- "https://github.com/remindmodel/remind/compare/" | ||
readLines("CHANGELOG.md") |> | ||
# Add version and date of new release | ||
sub(pattern = "## [Unreleased]", replacement = paste0("## [", newVersion, "] - ", releaseDate), fixed = TRUE) |> | ||
# Add two lines with github links that compare versions | ||
sub(pattern = paste0("\\[Unreleased\\]: ", githubUrl, "v(.+)\\.\\.\\.develop"), | ||
replacement = paste0("[Unreleased]: ", githubUrl, "v", newVersion, "...develop\n", | ||
"[", newVersion, "]: ", githubUrl, "v\\1...v", newVersion)) |> | ||
writeLines("CHANGELOG.md") | ||
|
||
# Update version and release date in CITATION.cff | ||
readLines("CITATION.cff") |> | ||
sub(pattern = "^version:.*$", replacement = paste("version:", newVersion)) |> | ||
sub(pattern = "^date-released:.*$", replacement = paste("date-released:", releaseDate)) |> | ||
writeLines("CITATION.cff") | ||
|
||
# Update version in README.md | ||
readLines("README.md") |> | ||
gsub(pattern = oldVersion, replacement = newVersion) |> | ||
writeLines("README.md") | ||
|
||
# Create documentation | ||
message("creating documentation using goxygen...") | ||
goxygen::goxygen(unitPattern = c("\\[","\\]"), | ||
includeCore = TRUE, | ||
output = "html", | ||
max_num_edge_labels = "adjust", | ||
max_num_nodes_for_edge_labels = 15, | ||
startType = NULL) | ||
|
||
# Upload html documentation to RSE server | ||
message("uploading documentation to RSE server") | ||
exitCode <- system(paste0("rsync -e ssh -avz doc/html/* ", | ||
"[email protected]:/webservice/doc/remind/", newVersion)) | ||
stopifnot(exitCode == 0) | ||
|
||
# Upload input data to RSE server | ||
message("Uploading input data to RSE server") | ||
source("config/default.cfg") | ||
cfg <- defineInputData(cfg) | ||
# Keep mandatory input files only | ||
cfg$input <- cfg$input[cfg$stopOnMissing] | ||
gms::publish_data(cfg,target = "[email protected]:/remind/public") | ||
|
||
message("If not already done please perform the two following steps manually now:\n", | ||
"1. CHANGELOG.md: sort lines in each category: input data/calibration, changed, added, removed, fixed; remove empty categories\n", | ||
"2. git add -p\n", | ||
"--> When done press ENTER to commit, push and create PR") | ||
gms::getLine() | ||
|
||
message("Committing and pushing changes") | ||
gert::git_commit(paste("remind release", newVersion)) | ||
gert::git_push() | ||
|
||
message("Creating tag") | ||
tag <- paste0("v",newVersion) | ||
git_tag_create(name = tag, message = "new tag", repo = ".") | ||
git_tag_push(name = tag, repo = ".") | ||
|
||
message("Creating a PR on GitHub") | ||
# gh pr create --help | ||
# --base branch The branch into which you want your code merged | ||
# --head branch The branch that contains commits for your pull request (default [current branch]) | ||
system(paste0("gh pr create --base master --title 'remind release ", newVersion, "' --body ''")) | ||
} | ||
|
||
# Source function definition of defineInputData() | ||
source("scripts/start/defineInputData.R") | ||
|
||
# Ask user for release version | ||
arguments <- commandArgs(TRUE) | ||
if (length(arguments) != 1) { | ||
stop("Please pass the new version number, e.g. `Rscript scripts/utils/release.R 0.8.15`") | ||
} | ||
|
||
release(arguments) | ||
message("warnings:") | ||
print(warnings()) |