diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7d9b351 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,20 @@ +name: append daily CI data + +on: push +jobs: + run_container: + runs-on: ubuntu-latest + container: + image: kasiatemp/ng-update:shiny + env: + SHINY_ACC_NAME=${{secrets.SHINY_ACC_NAME}} + TOKEN=${{secrets.TOKEN}} + SECRET=${{secrets.SECRET}} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + ref: 'main' + - name: Deploy app + run: | + bash Rscript deploy.R diff --git a/.github/workflows/schedule.yaml b/.github/workflows/schedule.yml similarity index 100% rename from .github/workflows/schedule.yaml rename to .github/workflows/schedule.yml diff --git a/.gitignore b/.gitignore index 756ed73..985cc5c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ carbon-intensity-app.Rproj rsconnect/ .DS_Store +.Renviron diff --git a/deploy.R b/deploy.R new file mode 100644 index 0000000..f1e2f1a --- /dev/null +++ b/deploy.R @@ -0,0 +1,20 @@ +library(rsconnect) +# a function to stop the script when one of the variables cannot be found. and to strip quotation marks from the secrets when you supplied them. (maybe it is just easier to never use them) +error_on_missing_name <- function(name) { + var <- Sys.getenv(name, unset = NA) + if (is.na(var)) { + stop(paste0("cannot find ", name, " !"), call. = FALSE) + } + gsub("\"", '', var) +} + +# Authenticate +setAccountInfo( + name = error_on_missing_name("SHINY_ACC_NAME"), + token = error_on_missing_name("TOKEN"), + secret = error_on_missing_name("SECRET") +) + +# Deploy the application. +deployApp(appName = "carbon-intensity-app", + appTitle = "Carbon Intensity App")