From ba09dc7285851421fcfd2c240fbe3465d4589dad Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Tue, 13 Jul 2021 16:00:49 +0300 Subject: [PATCH 1/6] Add a .gitlab-ci.yml --- .Rbuildignore | 1 + .gitlab-ci.yml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.Rbuildignore b/.Rbuildignore index 0ce2805..66ec51f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ci-rs.R ci.sh bootstrap.R tests.dockerfile +^\.gitlab-ci\.yml$ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..17d9b0e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,20 @@ +image: + name: 996097627176.dkr.ecr.us-east-1.amazonaws.com/rstudio-worker + entrypoint: [""] + +stages: + - test + - deploy + +test: + stage: test + script: + - Rscript -e 'install.packages("rzapierci"); rzapierci::check_package()' + +deploy: + stage: deploy + only: + - main + - master + script: + - Rscript -e 'install.packages("rzapierci"); rzapierci::deploy_package()' From 0184af973ad9baaed60196cf5197f7df54b9b03b Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Wed, 14 Jul 2021 11:59:57 +0300 Subject: [PATCH 2/6] Skip secrets-requiring tests on CI --- tests/testthat/test_connection_to_redshift.R | 12 +++++++----- tests/testthat/test_ctas.R | 18 ++++++++++-------- tests/testthat/test_get_column_names.R | 3 +++ tests/testthat/test_spectrum_tools.R | 1 + 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/testthat/test_connection_to_redshift.R b/tests/testthat/test_connection_to_redshift.R index 096f92c..7e36e89 100644 --- a/tests/testthat/test_connection_to_redshift.R +++ b/tests/testthat/test_connection_to_redshift.R @@ -3,9 +3,11 @@ context("Test that we can make a connection to Redshift") zapieR::make_db_connections() test_that( - "We can make a connection to Redshift", - expect_equal( - nrow(DBI::dbGetQuery(rs$con, "select * from event limit 1")), - 1 - ) + "We can make a connection to Redshift", { + skip_on_ci() + expect_equal( + nrow(DBI::dbGetQuery(rs$con, "select * from event limit 1")), + 1 + ) + } ) diff --git a/tests/testthat/test_ctas.R b/tests/testthat/test_ctas.R index f44d2ed..164e725 100644 --- a/tests/testthat/test_ctas.R +++ b/tests/testthat/test_ctas.R @@ -2,16 +2,18 @@ context("ctas()") test_that( "ctas works for temp table", { - ttn <- temp_table_name() - zapieR::rs_db("select 1 as foo") %>% - ctas(ttn, temp = TRUE) - expect_equivalent(zapieR::rs_db(ttn) %>% + skip_on_ci() + ttn <- temp_table_name() + zapieR::rs_db("select 1 as foo") %>% + ctas(ttn, temp = TRUE) + expect_equivalent(zapieR::rs_db(ttn) %>% collect, data.frame(foo=1L)) - DBI::dbExecute(zapieR::rs_db()$con, glue::glue("drop table {ttn}")) -}) + DBI::dbExecute(zapieR::rs_db()$con, glue::glue("drop table {ttn}")) + }) test_that( "ctas works for non-temp table", { + skip_on_ci() ttn <- temp_table_name() zapieR::rs_db("select 1 as foo") %>% ctas(ttn, temp = FALSE) @@ -22,6 +24,7 @@ test_that( test_that( "ctas works for view", { + skip_on_ci() ttn <- temp_table_name() ttvn <- temp_table_name() zapieR::rs_db("select 1 as foo") %>% @@ -36,9 +39,8 @@ test_that( test_that( "ctas works for in_schema", { + skip_on_ci() zapieR::rs_db("select * from iris") %>% ctas(dbplyr::in_schema("staging","redshiftToolsIris"), temp = FALSE) expect_gte(zapieR::rs_db("Select count(*) as n from staging.redshiftToolsIris") %>% pull(n),1) }) - - diff --git a/tests/testthat/test_get_column_names.R b/tests/testthat/test_get_column_names.R index 2dbee34..2e37947 100644 --- a/tests/testthat/test_get_column_names.R +++ b/tests/testthat/test_get_column_names.R @@ -4,6 +4,7 @@ ttn <- temp_table_name() on.exit(try(DBI::dbExecute(zapieR::rs_db()$con, glue::glue("DROP TABLE {ttn}"))), add = TRUE) test_that("can get column names from empty & populated table", { + skip_on_ci() rs_create_table(cars, zapieR::rs_db()$con, table_name = ttn) expect_equivalent(get_column_names(con = zapieR::rs_db()$con, ttn), c("speed", "dist")) rs_replace_table(data = cars, dbcon = zapieR::rs_db()$con, table_name = ttn, bucket = "zapier-data-science-storage") @@ -11,11 +12,13 @@ test_that("can get column names from empty & populated table", { }) test_that("can get column names from populated table with schema", { + skip_on_ci() rs_replace_table(data = cars, dbcon = zapieR::rs_db()$con, table_name = ttn, bucket = "zapier-data-science-storage") expect_equivalent(get_column_names(con = zapieR::rs_db()$con, dbplyr::in_schema("public", ttn)), c("speed", "dist")) }) test_that("can get column names from temp table", { + skip_on_ci() ttn2 <- temp_table_name() zapieR::rs_db(ttn) %>% ctas(ttn2, temp = TRUE) diff --git a/tests/testthat/test_spectrum_tools.R b/tests/testthat/test_spectrum_tools.R index 664485e..3f68190 100644 --- a/tests/testthat/test_spectrum_tools.R +++ b/tests/testthat/test_spectrum_tools.R @@ -7,6 +7,7 @@ d1 <- cars d1$moo <- lubridate::today() test_that("Don't allow a partionless schema with type date", { + skip_on_ci() expect_error( create_external_table(con = rs$con, d = d1, table_name = dbplyr::in_schema("external_testing", "moo"), location = "nope") ) From f6d3255dd25de05b8a5c304fef158425c06411fe Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Wed, 14 Jul 2021 12:45:28 +0300 Subject: [PATCH 3/6] More skips and reorganize some testing code --- tests/testthat/test_connection_to_redshift.R | 3 +-- tests/testthat/test_redshift_utils.R | 1 + tests/testthat/test_rs_upsert_table.R | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test_connection_to_redshift.R b/tests/testthat/test_connection_to_redshift.R index 7e36e89..caa8282 100644 --- a/tests/testthat/test_connection_to_redshift.R +++ b/tests/testthat/test_connection_to_redshift.R @@ -1,10 +1,9 @@ context("Test that we can make a connection to Redshift") -zapieR::make_db_connections() - test_that( "We can make a connection to Redshift", { skip_on_ci() + zapieR::make_db_connections() expect_equal( nrow(DBI::dbGetQuery(rs$con, "select * from event limit 1")), 1 diff --git a/tests/testthat/test_redshift_utils.R b/tests/testthat/test_redshift_utils.R index 7a07f40..8ff7b62 100644 --- a/tests/testthat/test_redshift_utils.R +++ b/tests/testthat/test_redshift_utils.R @@ -1,6 +1,7 @@ context("redshift-utils.R") test_that("can decompose in_schema", { + skip_on_ci() eg <- redshiftTools::decompose_in_schema(dbplyr::in_schema("s", "t")) expect_equal(attr(eg, "table_name"), "t") expect_equal(attr(eg, "schema_name"), "s") diff --git a/tests/testthat/test_rs_upsert_table.R b/tests/testthat/test_rs_upsert_table.R index f87f4e7..8914dfe 100644 --- a/tests/testthat/test_rs_upsert_table.R +++ b/tests/testthat/test_rs_upsert_table.R @@ -1,8 +1,8 @@ context("rs_upsert_table()") -zapieR::make_db_connections() - test_that("We can insert a row into an existing table", { + skip_on_ci() + zapieR::make_db_connections() test_table <- dbplyr::in_schema("staging","redshiftToolsIris") test_table_char <- schema_to_character(test_table) get_n <- function() { @@ -14,12 +14,12 @@ test_that("We can insert a row into an existing table", { }) ## These tests are commented out because they are destructive -DBI::dbGetQuery(conn = rs$con, statement = "drop table if exists mtcars_with_id;") -mtcars_with_id <- cbind(id = 1:nrow(mtcars), mtcars) -rs_create_table( - .data = mtcars_with_id, - dbcon = rs$con, table_name = "mtcars_with_id" -) +# DBI::dbGetQuery(conn = rs$con, statement = "drop table if exists mtcars_with_id;") +# mtcars_with_id <- cbind(id = 1:nrow(mtcars), mtcars) +# rs_create_table( +# .data = mtcars_with_id, +# dbcon = rs$con, table_name = "mtcars_with_id" +# ) # test_that( # "When the table exists but is empty, rs_upsert_table works", { From d2bad7771972a0f7f100415cb35573c4592be285 Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Wed, 14 Jul 2021 12:59:15 +0300 Subject: [PATCH 4/6] Remove old CI stuff --- .Rbuildignore | 4 ---- ci.sh | 25 ------------------------- tests.dockerfile | 17 ----------------- 3 files changed, 46 deletions(-) delete mode 100755 ci.sh delete mode 100644 tests.dockerfile diff --git a/.Rbuildignore b/.Rbuildignore index 66ec51f..a62766e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,8 +2,4 @@ ^\.Rproj\.user$ README.Rmd ^.*.log -ci-rs.R -ci.sh -bootstrap.R -tests.dockerfile ^\.gitlab-ci\.yml$ diff --git a/ci.sh b/ci.sh deleted file mode 100755 index f0b4bf3..0000000 --- a/ci.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -TAG=redshifttools -PKG=redshiftTools -DATE=$(date +%Y-%m-%d) -VERSION=$(grep Version: DESCRIPTION | awk '{print $2}') - -export PATH=~/.local/bin:$PATH - -docker images | grep ${TAG} | awk '{print $3}' | xargs docker rmi -f || true - -docker build -f tests.dockerfile -t ${TAG} . - -echo AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} > .env -echo AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} >> .env -echo AWS_DEFAULT_REGION=us-east-1 >> .env - -docker run --env-file .env ${TAG} - -clean_branch=$(echo $GIT_BRANCH | sed 's.origin/..g') - -docker run ${TAG} /root/.local/bin/aws s3 cp ${PKG}_${VERSION}.tar.gz s3://zapier-data-packages/${PKG}/${PKG}_${VERSION}_${clean_branch}_latest.tar.gz -docker run ${TAG} /root/.local/bin/aws s3 cp ${PKG}_${VERSION}.tar.gz s3://zapier-data-packages/${PKG}/${PKG}_${VERSION}_${clean_branch}_${DATE}.tar.gz diff --git a/tests.dockerfile b/tests.dockerfile deleted file mode 100644 index db90afa..0000000 --- a/tests.dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM 996097627176.dkr.ecr.us-east-1.amazonaws.com/data-zapier-nightly:latest - -ENV ENVIRONMENT=production -ENV PKG=redshiftTools -ENV VERSION=0.1.2 -ENV TARBALL=${PKG}_${VERSION}.tar.gz -ENV REDSHIFT_ROLE='arn:aws:iam::996097627176:role/production-redshift' - -ADD . /code -WORKDIR /code - -RUN R CMD build . -RUN R CMD INSTALL ${TARBALL} - -RUN mv ${TARBALL} / && rm -rf * && mv /${TARBALL} . - -CMD R CMD check ${TARBALL} \ No newline at end of file From aacddebe03365d4e13bd308ee54e9ebd8db95a72 Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Wed, 14 Jul 2021 12:59:25 +0300 Subject: [PATCH 5/6] Allow 3 WARNINGs --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17d9b0e..35534dc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ stages: test: stage: test script: - - Rscript -e 'install.packages("rzapierci"); rzapierci::check_package()' + - Rscript -e 'install.packages("rzapierci"); rzapierci::check_package(allowed_warnings = 3L)' deploy: stage: deploy From d86cb2bd1bf065b47a3c274e72f155a5cf08dc41 Mon Sep 17 00:00:00 2001 From: Ilari Scheinin Date: Wed, 14 Jul 2021 13:14:11 +0300 Subject: [PATCH 6/6] Deploy also from prod --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35534dc..2eefcb3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,5 +16,6 @@ deploy: only: - main - master + - prod script: - Rscript -e 'install.packages("rzapierci"); rzapierci::deploy_package()'