自动增加R软件包的版本 [英] Automating version increase of R packages

查看:114
本文介绍了自动增加R软件包的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我正在开发R软件包,我想在每次构建时自动增加版本.我希望能够将我的结果与软件包版本相关联.现在,我正在使用自己的 ugly 函数来执行此操作.

我的问题是:有没有更好的方法?或者,我应该避免这样做吗?

另一个选项

我想到的另一种选择是使用"devtools :: install_github"安装我的软件包(托管在github中),然后将其结果保存(或添加到绘图中)保存在已安装的Description文件中的GithubSHA1. /p>

例如,我可以为"devtools"软件包获得类似的版本和GithubSHA1:

read.dcf(file=system.file("DESCRIPTION", package="devtools"), 
         fields=c("Version", "GithubSHA1"))
 ##      Version    GithubSHA1                                
 ## [1,] "1.5.0.99" "3ae58a2a2232240e67b898f875b8da5e57d1b3a8"

到目前为止我的尝试

我编写了以下函数来生成具有更新的版本和日期的新的Description文件. (增加主版本是我不介意每手增加的内容)

 incVer <- function(pkg, folder=".", increase="patch"){
    ## Read DESCRIPTION from installed package ´pkg´ and make new one on the specified
    ## ´folder´. Two options for ´increase´ are "patch" and "minor"
    f <- read.dcf(file=system.file("DESCRIPTION", package=pkg),
                  fields=c("Package", "Type", "Title", "Version", "Date", 
                           "Author", "Maintainer", "Description", "License", 
                           "Depends", "Imports", "Suggests"))
    curVer <- package_version(f[4])
    if(increase == "patch") {
        curVer[[1,3]] <- ifelse(is.na(curVer$patchlevel), 1, curVer$patchlevel + 1)

    } else if (increase == "minor") {
        curVer[[1,2]] <- ifelse(is.na(curVer$minor), 1, curVer$minor + 1)
        curVer[[1,3]] <- 0
    } else {
        stop(paste("Can not identify the increase argument: " , increase))
    }

    f[4] <- toString(curVer)
    ## Update also the date
    f[5] <- format (Sys.time(), "%Y-%m-%d")
    write.dcf(f, file=paste(folder, "DESCRIPTION", sep="/"))
}
 

解决方案

如果使用的是git,则可以使用git标记创建版本字符串.这就是我们生成igraph库的版本字符串的方式:

git describe HEAD --tags | rev | sed 's/g-/./' | sed 's/-/+/' | rev

它为您提供了这样的格式:

0.8.0-pre+131.ca78343

0.8.0-pre是当前分支上的最后一个标签. (最新发布的版本是0.7.1,我们在release标签之后立即创建一个-pre标签.)131是自上一个标签以来的提交次数. ca78343是最后一次提交的十六进制ID的前七个字符.

这很好,除了R软件包中不能包含这样的版本字符串,R不允许这样做.因此,对于R,我们使用以下脚本转换此版本字符串: https://github .com/igraph/igraph/blob/develop/interfaces/R/tools/convertversion.sh

基本上,它创建一个版本号,该版本号大于上一个发布的版本,而小于下一个版本(-pre标记中的版本).从0.8.0-pre+131.ca78343它创建

0.7.999-131

其中,131是自上一发行版以来的提交次数.

我将DESCRIPTION文件的生成放入了一个Makefile中.这将替换日期和版本号:

VERSION=$(shell ./tools/convertversion.sh)

igraph/DESCRIPTION: src/DESCRIPTION version_number
        sed 's/^Version: .*$$/Version: '$(VERSION)'/' $<     | \
        sed 's/^Date: .*$$/Date: '`date "+%Y-%m-%d"`'/' > $@

这非常方便,除了添加release标签和 -pre标签.

顺便说一句.这主要是由我的朋友和igraph共同开发者TamásNepusz解决的,所以功劳是他的.

Problem

I am developing an R package and I want to increase the version automatically each time I build it. I want that to be able to associate my results to package versions. For now I was using my own ugly function to do that.

My question is: is there a way to do it better? Or, should I avoid doing that in general?

Another option

Another option I was thinking of is to install my package (hosted in github) using ´devtools::install_github´ and then save with my results (or adding to plots) the GithubSHA1 that is saved in the installed DESCRIPTION file.

For example I can get the version and GithubSHA1 like that for the ´devtools´ package:

read.dcf(file=system.file("DESCRIPTION", package="devtools"), 
         fields=c("Version", "GithubSHA1"))
 ##      Version    GithubSHA1                                
 ## [1,] "1.5.0.99" "3ae58a2a2232240e67b898f875b8da5e57d1b3a8"

My tries so far

I wrote the following function to produce a new DESCRIPTION file, with updated version and date. (Increasing the major version is something I don't mind increasing per hand)

incVer <- function(pkg, folder=".", increase="patch"){
    ## Read DESCRIPTION from installed package ´pkg´ and make new one on the specified
    ## ´folder´. Two options for ´increase´ are "patch" and "minor"
    f <- read.dcf(file=system.file("DESCRIPTION", package=pkg),
                  fields=c("Package", "Type", "Title", "Version", "Date", 
                           "Author", "Maintainer", "Description", "License", 
                           "Depends", "Imports", "Suggests"))
    curVer <- package_version(f[4])
    if(increase == "patch") {
        curVer[[1,3]] <- ifelse(is.na(curVer$patchlevel), 1, curVer$patchlevel + 1)

    } else if (increase == "minor") {
        curVer[[1,2]] <- ifelse(is.na(curVer$minor), 1, curVer$minor + 1)
        curVer[[1,3]] <- 0
    } else {
        stop(paste("Can not identify the increase argument: " , increase))
    }

    f[4] <- toString(curVer)
    ## Update also the date
    f[5] <- format (Sys.time(), "%Y-%m-%d")
    write.dcf(f, file=paste(folder, "DESCRIPTION", sep="/"))
}

解决方案

If you are using git, then you can use git tags to create a version string. This is how we generate the version string of our igraph library:

git describe HEAD --tags | rev | sed 's/g-/./' | sed 's/-/+/' | rev

It gives you a format like this:

0.8.0-pre+131.ca78343

0.8.0-pre is the last tag on the current branch. (The last released version was 0.7.1, and we create a -pre tag immediately after the release tag.) 131 is the number of commits since the last tag. ca78343 is the first seven character of the hex id of the last commit.

This would be great, except that you cannot have version strings like this in R packages, R does not allow it. So for R we transform this version string using the following script: https://github.com/igraph/igraph/blob/develop/interfaces/R/tools/convertversion.sh

Essentially it creates a version number that is larger than the last released version and smaller than the next versions (the one in the -pre tag). From 0.8.0-pre+131.ca78343 it creates

0.7.999-131

where 131 is the number of commits since the last release.

I put the generation of the DESCRIPTION file in a Makefile. This replaces the date, and the version number:

VERSION=$(shell ./tools/convertversion.sh)

igraph/DESCRIPTION: src/DESCRIPTION version_number
        sed 's/^Version: .*$$/Version: '$(VERSION)'/' $<     | \
        sed 's/^Date: .*$$/Date: '`date "+%Y-%m-%d"`'/' > $@

This is quite convenient, you don't need to do anything, except for adding the release tags and the -pre tags.

Btw. this was mostly worked out by my friend and igraph co-developer, Tamás Nepusz, so the credit is his.

这篇关于自动增加R软件包的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆