Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pak when package installation is not found #284

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7b933ef
Setup pak
schloerke Mar 18, 2021
93362ed
Use local lib path for pak that is ignored for regular execution
schloerke Mar 18, 2021
0114221
Fix pkgs to be installed
schloerke Mar 18, 2021
fdf66eb
Install pak before packages. If no install file exists, use pak to in…
schloerke Mar 18, 2021
bb51c28
Ignore lib folder
schloerke Mar 18, 2021
5d590b2
Remove gsl install
schloerke Mar 18, 2021
c722231
remove pdftools install
schloerke Mar 18, 2021
4adbd13
remove ragg install
schloerke Mar 18, 2021
727e2ca
remove rDEA install and test
schloerke Mar 18, 2021
e9eae2d
remove redland install
schloerke Mar 18, 2021
0f30a34
remove rgeos install
schloerke Mar 18, 2021
2190bfa
remove rgl
schloerke Mar 18, 2021
066f585
remove Rglpk
schloerke Mar 18, 2021
8e9d0e3
remove Rmpfr install
schloerke Mar 18, 2021
18fa843
remove rsvg install
schloerke Mar 18, 2021
02ea033
remove tesseract
schloerke Mar 18, 2021
c5864a7
remove textshaping
schloerke Mar 18, 2021
3314d33
Remove tiff
schloerke Mar 18, 2021
e922be7
remove units and udunits2
schloerke Mar 18, 2021
d56ca26
remove V8 install
schloerke Mar 18, 2021
62018f8
Rename pak install pkg file
schloerke Mar 18, 2021
fdc6291
Create test-pkgs.yaml
schloerke Mar 18, 2021
09bf627
Don't forget to checkout the repo. Run on `pak` branch
schloerke Mar 18, 2021
8499d49
try using an object and no an array
schloerke Mar 18, 2021
28c3722
Use a matrix like the example
schloerke Mar 18, 2021
79d5525
Revert to original single name setup. Say `test` needs `packages`
schloerke Mar 18, 2021
8fcb11a
Use hosted docker images
schloerke Mar 18, 2021
3bd9e30
formatting
schloerke Mar 18, 2021
f7ec94a
Merge branch 'master' into pak
schloerke Mar 18, 2021
e2dc63e
Test using focal
schloerke Mar 18, 2021
a903ac8
Delete .travis.yml
schloerke Mar 18, 2021
c39737d
xenial is missing libpcre2. Build local docker files to test latest
schloerke Mar 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/test-pkgs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
push:
branches:
- master
- pak
pull_request:
branches:
- master

name: Test packages

jobs:
packages:
runs-on: ubuntu-latest
outputs:
pkg_names: ${{ steps.set_pkg_names.outputs.pkg_names }}
steps:
- uses: actions/checkout@v2
- id: set_pkg_names
# https://stackoverflow.com/a/32354503/591574
run: |
PKGS=`ls packages | jq -R '[.]' | jq -s -c 'add'`
echo "::set-output name=pkg_names::$PKGS"
- name: debug
run: |
echo "${{ steps.set_pkg_names.outputs.pkg_names }}"

test:
runs-on: ubuntu-latest

name: ${{ matrix.pkg }} - ${{ matrix.docker_type }}

needs:
- packages
strategy:
fail-fast: false

# Test using independent docker containers
# Isolated testing so that a prior package doesn't "help" another package
matrix:
# Dynamic pkg names from the `./packages` folder
# https://github.blog/changelog/2020-04-15-github-actions-new-workflow-features/
pkg: ${{ fromJson(needs.packages.outputs.pkg_names) }}
docker_type:
- focal
- xenial

steps:
- uses: actions/checkout@v2

- name: Build docker image
run: |
make docker-build-${{ matrix.docker_type }}

# Use dockerhub image
- name: "Test package: ${{ matrix.pkg }}"
run: |
make test-${{ matrix.docker_type }}-${{ matrix.pkg }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vagrant/
pak/lib
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions Dockerfile.xenial
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN apt-get update -qq && \
libgsl0-dev \
libmysqlclient-dev \
libnetcdf-dev \
libpcre2-dev \
libprocps4-dev \
libproj-dev \
libprotoc-dev \
Expand Down
30 changes: 20 additions & 10 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,33 @@ DIR=`dirname $0`

PACKAGES=$@

echo " ***** SETUP..." | purple
# make sure apt-get is up to date
apt-get update -qq

# install pak if it doesn't already exist
echo " ***** INSTALL PAK..." | purple
Rscript "$DIR/pak/setup.R"

for PACKAGE in $PACKAGES; do

PACKAGE_DIR=$DIR/packages/$PACKAGE

if [ -f $PACKAGE_DIR/install ]; then
echo " ***** PACKAGE $PACKAGE" | purple
echo " ***** PACKAGE $PACKAGE" | purple

echo " ***** INSTALLING..." | purple
echo " ***** INSTALLING..." | purple
if [ -f $PACKAGE_DIR/install ]; then
bash $PACKAGE_DIR/install
else
Rscript "$DIR/pak/install_sys_reqs.R" $PACKAGE
fi

return_code=$?
if [[ $return_code != 0 ]] ; then
echo "$PACKAGE... FAILED" | red
exit $return_code
else
echo "$PACKAGE... SUCCESS" | green
fi
return_code=$?
if [[ $return_code != 0 ]] ; then
echo "$PACKAGE... FAILED" | red
exit $return_code
else
echo "$PACKAGE... SUCCESS" | green
fi
done

Expand Down
6 changes: 0 additions & 6 deletions packages/Rglpk/install

This file was deleted.

1 change: 1 addition & 0 deletions packages/Rglpk/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to keep folder alive
6 changes: 0 additions & 6 deletions packages/Rmpfr/install

This file was deleted.

1 change: 0 additions & 1 deletion packages/V8/install

This file was deleted.

1 change: 1 addition & 0 deletions packages/gsl/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to keep folder alive
6 changes: 0 additions & 6 deletions packages/pdftools/install

This file was deleted.

4 changes: 0 additions & 4 deletions packages/rDEA/install

This file was deleted.

1 change: 1 addition & 0 deletions packages/rDEA/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to keep folder alive
2 changes: 0 additions & 2 deletions packages/rDEA/test.R

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ragg/install

This file was deleted.

7 changes: 0 additions & 7 deletions packages/redland/install

This file was deleted.

6 changes: 0 additions & 6 deletions packages/rgeos/install

This file was deleted.

6 changes: 0 additions & 6 deletions packages/rgl/install

This file was deleted.

1 change: 1 addition & 0 deletions packages/rgl/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to keep folder alive
6 changes: 0 additions & 6 deletions packages/rsvg/install

This file was deleted.

7 changes: 0 additions & 7 deletions packages/tesseract/install

This file was deleted.

6 changes: 0 additions & 6 deletions packages/textshaping/install

This file was deleted.

3 changes: 0 additions & 3 deletions packages/textshaping/test.R

This file was deleted.

6 changes: 0 additions & 6 deletions packages/tiff/install

This file was deleted.

1 change: 1 addition & 0 deletions packages/tiff/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to keep folder alive
6 changes: 0 additions & 6 deletions packages/udunits2/install

This file was deleted.

6 changes: 0 additions & 6 deletions packages/units/install

This file was deleted.

44 changes: 44 additions & 0 deletions pak/install_sys_reqs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Returns the file currently being sourced or run with Rscript
thisFile <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
needle <- "--file="
match <- grep(needle, cmdArgs)
if (length(match) > 0) {
# Rscript
return(normalizePath(sub(needle, "", cmdArgs[match])))
} else {
# 'source'd via R console
return(normalizePath(sys.frames()[[1]]$ofile))
}
}
# set to `pak` folder
setwd(dirname(thisFile()))

os <- tryCatch({
system("lsb_release -sc", intern = TRUE)
}, error = function(e) {
"local"
})

args <- commandArgs(TRUE)
if (length(args) > 0) {
pkgs <- args

# Must match install file
lib <- file.path("lib", os, paste0(R.Version()$major, ".", R.Version()$minor))
# Load pak from our tmp lib
require("pak", character.only = TRUE, lib.loc = lib, quietly = TRUE)
# Prepend the pak lib path for sys req installation
# No pkg is actually being installed in this step
.libPaths(
c(
lib,
.libPaths()
)
)

lapply(pkgs, function(pkg) {
pak::pkg_system_requirements(pkg, execute = TRUE, sudo = TRUE)
})
}
invisible()
40 changes: 40 additions & 0 deletions pak/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Returns the file currently being sourced or run with Rscript
thisFile <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
needle <- "--file="
match <- grep(needle, cmdArgs)
if (length(match) > 0) {
# Rscript
return(normalizePath(sub(needle, "", cmdArgs[match])))
} else {
# 'source'd via R console
return(normalizePath(sys.frames()[[1]]$ofile))
}
}
# set to `pak` folder
setwd(dirname(thisFile()))

os <- tryCatch({
system("lsb_release -sc", intern = TRUE)
}, error = function(e) {
"local"
})

# Must match install file
lib <- file.path("lib", os, paste0(R.Version()$major, ".", R.Version()$minor))
if (!dir.exists(lib)) {
dir.create(lib, recursive = TRUE)
}

if (system.file(package = "pak", lib.loc = lib) == "") {
# install latest
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/", lib = lib)
# quick test
require("pak", character.only = TRUE, lib.loc = lib, quietly = FALSE)

} else {
# Load pak from our tmp lib
require("pak", character.only = TRUE, lib.loc = lib, quietly = TRUE)
# update to latest version
pak::pak_update()
}
46 changes: 27 additions & 19 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ color_text () {
echo -e -n "\033[0m" # clear the color
}

echo " ***** SETUP..." | purple
# make sure apt-get is up to date
apt-get update -qq

# install ts command (used later in this script)
apt-get install -qq -y moreutils

Expand All @@ -25,34 +29,38 @@ else
PACKAGES=$@
fi

# install pak if it doesn't already exist
echo " ***** INSTALL PAK..." | purple
Rscript "$DIR/pak/setup.R" | ts

for PACKAGE in $PACKAGES; do

PACKAGE_DIR=$DIR/packages/$PACKAGE

if [ -f $PACKAGE_DIR/install ]; then
echo " ***** PACKAGE $PACKAGE" | purple
echo " ***** PACKAGE $PACKAGE" | purple

echo " ***** INSTALLING..." | purple
echo " ***** INSTALLING $PACKAGE..." | purple
if [ -f $PACKAGE_DIR/install ]; then
bash $PACKAGE_DIR/install | ts
else
Rscript "$DIR/pak/install_sys_reqs.R" $PACKAGE | ts
fi

echo " ***** TESTING..." | purple
if [ -f $PACKAGE_DIR/test.R ]; then
sudo R --verbose -f $PACKAGE_DIR/test.R
else
sudo R -e "install.packages('$PACKAGE', repos='http://cran.rstudio.com/'); library('$PACKAGE')"
fi

return_code=$?
if [[ $return_code != 0 ]] ; then
echo "$PACKAGE... FAILED" | red
exit $return_code
else
echo "$PACKAGE... SUCCESS" | green
fi
echo " ***** TESTING $PACKAGE..." | purple
if [ -f $PACKAGE_DIR/test.R ]; then
sudo R --verbose -f $PACKAGE_DIR/test.R
else
echo "Unable to find '$PACKAGE' in $DIR/packages, exiting..." | red
exit 1
sudo R -e "install.packages('$PACKAGE', repos='http://cran.rstudio.com/'); library('$PACKAGE')"
fi

return_code=$?
if [[ $return_code != 0 ]] ; then
echo "$PACKAGE... FAILED" | red
exit $return_code
else
echo "$PACKAGE... SUCCESS" | green
fi

done

exit 0