1

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

Herman Starikov
  • 2,636
  • 15
  • 26

2 Answers2

1

Indeed there is, but it's poorly documented.

WEB_EXT_API_KEY=your key
WEB_EXT_API_SECRET=your secret
Herman Starikov
  • 2,636
  • 15
  • 26
  • Thank you! Very useful to wrap `--chromium-binary` as well, with the use of `WEB_EXT_CHROMIUM_BINARY`. – vintprox May 17 '22 at 11:06
0

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",
    ...
  }
}