Option to select a specific version of a github pkg.

This commit is contained in:
Andrea Dell'Amico 2021-09-21 16:32:28 +02:00
parent 2073ac2388
commit 4a4eec4589
Signed by: andrea.dellamico
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 15 additions and 6 deletions

View File

@ -256,8 +256,9 @@ r_plugins_from_sources: []
# The 'repo' scope is required
# r_plugins_from_github_api_token: 'Put it into a vault file'
# The 'version' parameter is optional. The default is 'master'
r_plugins_from_github: []
# - { plugin_name: 'RFigisGeo', github_user: 'openfigis' }
# - { plugin_name: 'RFigisGeo', github_user: 'openfigis', version: 'v0.2-beta1' }
# - { plugin_name: 'rsdmx', github_user: 'opensdmx' }
#

View File

@ -85,7 +85,7 @@
- name: Install R packages from github
command: >
Rscript --slave --no-site-file --no-init-file --no-save --no-restore-history -e "if (! ('{{ item.plugin_name }}' %in% installed.packages()[,'Package'])) { require(devtools); require(methods) ; options(repos='{{ r_cran_mirror_site }}/') ; install_github('{{ item.github_user }}/{{ item.plugin_name }}'); print('Added'); } else { print('Already Installed'); }"
Rscript --slave --no-site-file --no-init-file --no-save --no-restore-history -e "if (! ('{{ item.plugin_name }}' %in% installed.packages()[,'Package'])) { require(devtools); require(methods) ; options(repos='{{ r_cran_mirror_site }}/') ; install_github('{{ item.github_user }}/{{ item.plugin_name }}', ref = {{ item.version | default('master') }}, upgrade='never'); print('Added'); } else { print('Already Installed'); }"
register: install_github_plugins_result
failed_when: "install_github_plugins_result.rc != 0 or 'had non-zero exit status' in install_github_plugins_result.stderr"
changed_when: "'Added' in install_github_plugins_result.stdout"

View File

@ -58,6 +58,7 @@ R_VERSIONED_PKGS_LIST=
GITHUB_PKGS_SKIP=0
R_PKGS_FROM_GITHUB_LIST_URL="{{ r_github_packages_list_url | default('') }}"
R_PKGS_GITHUB=
R_PKGS_ALWAYS_UPGRADE_GITHUB={{ r_github_always_upgrade | default(True) }}
trap "logger 'update_r_packages: trap intercepted, exiting.' ; cleanup" SIGHUP SIGINT SIGTERM
@ -70,7 +71,7 @@ function cleanup() {
function usage() {
if [ $PARAMS -ne 1 ] ; then
echo "Need at least an argument: 'upgrade' or 'install'."
echo "- 'upgrade' installs new packages and upgrades the existin ones when needed."
echo "- 'upgrade' installs new packages and upgrades the already installed ones."
echo "- 'install' installs new packages."
cleanup
exit 1
@ -281,11 +282,18 @@ function r_github_pkgs() {
logger "update_r_packages: Installing R packages from Github"
for l in $( cat $R_PKGS_GITHUB ) ; do
pkg=$( echo $l | cut -d "/" -f 2 )
if [ "$ACTION" == "upgrade" ] ; then
Rscript $RSCRIPT_OPTIONS -e "require(devtools); require(methods); require(jsonlite) ; package_to_install <- '$l' ; refs <- jsonlite::read_json(sprintf('https://api.github.com/repos/%s/releases', package_to_install)) ; ref_to_install <- 'master'; if(length(refs)>0) { ref_to_install <- refs[[1]][['tag_name']] } ; devtools::install_github(package_to_install, ref = ref_to_install, upgrade='never')"
github_pkg=$( echo $l | awk -F ":" '{ print $1 }' - )
github_pkg_version=$( echo $l | awk -F ":" '{ print $2 }' - )
if [ ! -z "$github_pkg_version" ] ; then
github_version_to_install="master"
else
github_version_to_install="$github_pkg_version"
fi
if [ "$ACTION" == "upgrade" -o "$R_PKGS_ALWAYS_UPGRADE_GITHUB" ] ; then
Rscript $RSCRIPT_OPTIONS -e "require(devtools); require(methods); require(jsonlite) ; package_to_install <- '$github_pkg' ; refs <- jsonlite::read_json(sprintf('https://api.github.com/repos/%s/releases', package_to_install)) ; ref_to_install <- '$github_pkg_version'; if(length(refs)>0) { ref_to_install <- refs[[1]][['tag_name']] } ; devtools::install_github(package_to_install, ref = ref_to_install, upgrade='never')"
else
Rscript $RSCRIPT_OPTIONS -e "if (! ('$pkg' %in% installed.packages()[,'Package'])) { require(devtools); require(methods); require(jsonlite) ; package_to_install <- '$l' ; refs <- jsonlite::read_json(sprintf('https://api.github.com/repos/%s/releases', package_to_install)) ; ref_to_install <- 'master'; if(length(refs)>0) { ref_to_install <- refs[[1]][['tag_name']] } ; devtools::install_github(package_to_install, ref = ref_to_install, upgrade='never') }"
Rscript $RSCRIPT_OPTIONS -e "if (! ('$pkg' %in% installed.packages()[,'Package'])) { require(devtools); require(methods); require(jsonlite) ; package_to_install <- '$github_pkg' ; refs <- jsonlite::read_json(sprintf('https://api.github.com/repos/%s/releases', package_to_install)) ; ref_to_install <- '$github_pkg_version'; if(length(refs)>0) { ref_to_install <- refs[[1]][['tag_name']] } ; devtools::install_github(package_to_install, ref = ref_to_install, upgrade='never') }"
fi
done
else