Environment variables for web-ext

597 Views Asked by At

I'm using web-ext by mozilla to submit an extension to firefox addon store. The --help says this:

  --api-key            API key (JWT issuer) from addons.mozilla.org
                                                             [string] [required]
  --api-secret         API secret (JWT secret) from addons.mozilla.org
                                                             [string] [required]

Is there a way to use environment variables to set the values on my CI/CD environment?

API_KEY and API_SECRET give me Missing required arguments: api-key, api-secret

2

There are 2 best solutions below

1
Herman Starikov On BEST ANSWER

Indeed there is, but it's poorly documented.

WEB_EXT_API_KEY=your key
WEB_EXT_API_SECRET=your secret
0
PrettyCoffee On

I couldn't work out how to apply the env vars in the npm script, so here is my alternative solution if anyone else has the same problem :)

.env

WEB_EXT_API_KEY="your_api_key"
WEB_EXT_API_SECRET="your_api_secret"

scripts/sign.js

require('dotenv').config()
const { execSync } = require('child_process')

const run = (command) =>
  execSync(`npx ${command}`, {stdio: 'inherit'})

const parseArgs = (args) =>
  Object.keys(args).reduce(
    (result, arg) => `${result} ${arg} ${args[arg]}`
  , "")

const args = {
  "-s": "dist",
  "--api-key": process.env.WEB_EXT_API_KEY,
  "--api-secret": process.env.WEB_EXT_API_SECRET,
}

const command = `web-ext sign ${parseArgs(args)}`
run(command)

package.json

{
  ...
  "scripts": {
    ...
    "sign": "node scripts/sign.js"
  },
  "devDependencies": {
    "dotenv": "^16.0.2",
    ...
  }
}