0

I'm trying to run an action that requires JSONs for authentication within my R Script.

I have stored these two JSON as Github Secrets Action:

GMAIL_ADDRESS
GMAIL_SECRET_API

This is my main.yml section that calls these two JSONs

 # Run R script
    - name: execute r script # email-from-r.R
      env:
        GMAIL_SERVICE: ${{ secrets.GMAIL_SECRET_API }}
        GMAIL_ADDRESS: ${{ secrets.GMAIL_ADDRESS }}      
      run: Rscript mailer.R

And in my script I'm recalling these two files with this:

GMAIL_SERVICE <- Sys.getenv("GMAIL_SECRET_API")

GMAIL_ADDRESS <- Sys.getenv("GMAIL_ADDRESS")

The workflow runs but returns this error:

Error: Error: Must supply either `key` and `secret` or `path`
Execution halted
Error: Process completed with exit code 1.

I'm quite sure that the problem is that I'm not getting the two JSONs correctly from the Secrets.

Here is my full code for the script:

library(gmailr)
library(googleAnalyticsR)
library(googledrive)
library(lubridate)
library(scales)
library(tidyverse)
library(gt)
library(googleAuthR)


GMAIL_SERVICE <- Sys.getenv("GMAIL_SECRET_API")

GMAIL_ADDRESS <- Sys.getenv("GMAIL_ADDRESS")



gmailr::gm_auth_configure(path = GMAIL_SERVICE ,
                          appname = "gmailr")


gmailr::gm_auth(email = GMAIL_ADDRESS,
                path = GMAIL_SERVICE,
                scopes = "full")





TEST <-
    gm_mime() %>%
    gm_to(c(GMAIL_ADDRESS)) %>%
    gm_from(GMAIL_ADDRESS) %>%
    gm_subject(paste0("TEEEEEEEEEST", "BOOOOOOM", "-", "TEEEEEST")) %>%
    gm_text_body("TEEEEEEEST")


gm_send_message(TEST)



date <- gm_date(TEST)

date_2 <- Sys.time()

log <- paste0("The mail has been successfully sent on: ", date)

write.csv(log, file = paste0("data/Log_", date_2, ".csv"))
Andrea
  • 105
  • 10
  • 1
    I don't think the `GMAIL_SERVICE <- Sys.getenv("GMAIL_SECRET_API")` will work in your script, as you set the env variable with the `GMAIL_SERVICE` name in your workflow. Therefore, it should be `GMAIL_SERVICE <- Sys.getenv("GMAIL_SERVICE")` instead. – GuiFalourd Sep 28 '22 at 18:27
  • Thank you @GuiFalourd, I changed the var to match the env variable: `GMAIL_SECRET_API <- Sys.getenv("GMAIL_SECRET_API")` `GMAIL_ADDRESS <- Sys.getenv("GMAIL_ADDRESS")` But I still get the same error. Is there a way to check if the JSON is imported correctly inside the environment? – Andrea Sep 29 '22 at 07:46
  • You could try printing the github context in the workflow before calling the script. But I'm pretty sure it will only print `* * *` (except if you use a workaround to check the value, which is not recommended as it will expose the secret). You could maybe try with a hardcoded json value first just to check if the error is the same. – GuiFalourd Sep 29 '22 at 09:20

0 Answers0