pa11y / pa11y-ci

Pa11y CI is a CI-centric accessibility test runner, built using Pa11y
https://pa11y.org
GNU Lesser General Public License v3.0
520 stars 64 forks source link

Option to pass environment variable in .pa11yci file #193

Closed mudit94 closed 11 months ago

mudit94 commented 1 year ago

Hi Team, I am looking for a way to be able to use environment variables in pa11yci file so that credentials need not be hardcoded

aarongoldenthal commented 1 year ago

Hi @mudit94,

Pa11y CI will actually accept either a JSON or JavaScript formatted configuration file. By default (i.e. if the --config CLI argument is not specified), it will try .pa11yci, then .pa11yci.js, then .pa11yci.json (per the code here if that's helpful).

So, the easiest route is to declare variables with your credentials, then use a JavaScript formatted config file to pull them, something like (assuming the AUTH_TOKEN environment variable has an auth token):

.pa11yci.js:

module.exports = {
{
  defaults: {
    headers: {
      'auth-token': process.env.AUTH_TOKEN
    }
  },
  urls: [...]
}

There are other tricks for variable substitution (e.g. something like sed in Linux), but that's nearly as clean.

mudit94 commented 1 year ago

I want to use the variable in actions to be able to perform login operation. Do you have a sample code?

aarongoldenthal commented 1 year ago

@mudit94 How specifically are you trying to login? Is it with some kind of access token in the headers as shown above, using actions to fill out form fields, or something else?

danyalaytekin commented 11 months ago

Thanks for your help here @aarongoldenthal. I've also added #197 to the list for release 3.1. @mudit94, I'll close this now as it's been a while, but please reopen if you'd like to continue the conversation.