firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Usage with CI/CD systems (e.g. GitHub actions) #66

Closed tzvc closed 4 years ago

tzvc commented 4 years ago

Hey there 👋

I'm trying to set up continuous integration with this using GitHub actions and I'm hitting a roadblock regarding the credentials.

The library require a secret credential file to be loaded. However, GitHub Actions (and many other CI/CD system) only support secrets in the form of environment variables.

I was therefore wondering: Is there a way to initialize the library using environment variables instead of the credentials file ?

Cheers ❤️

mbleigh commented 4 years ago

Unfortunately a file-based key is the only credential available; however I've worked around this in similar situations by putting the key into a GitHub Actions secret and writing it to a temp file that I then use in subsequent execs:

const core = require("@actions/core");

const tmp = require("tmp");
const { writeSync } = require("fs");

tmpFile = tmp.fileSync();
writeSync(tmpFile.fd, core.getInput("service_account_key"), {
  encoding: "utf8"
});

console.log('File now available at:', tmpFile.name);