You can pass-in Secrets as ENV variables.
Example:
...
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Use Node 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install Dependencies (prod)
run: yarn install --frozen-lockfile --production
- name: Run Tests (JEST)
run: yarn test --ci --silent --testPathIgnorePatterns=experimental
env:
CI: true
API_KEY: ${{ secrets.API_KEY }}
In Node.js you can access it via process.env.API_KEY.
You can pass-in Secrets as ENV variables.
Example:
...
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Use Node 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install Dependencies (prod)
run: yarn install --frozen-lockfile --production
- name: Run Tests (JEST)
run: yarn test --ci --silent --testPathIgnorePatterns=experimental
env:
CI: true
API_KEY: ${{ secrets.API_KEY }}
In Node.js you can access it via process.env.API_KEY.
I Find a way to achieve it although it might not be the best (And I'm definitly not bash expert)
So create a setEnv.sh file
mkdir env
echo "export const environment = { firebase_api_key : '$1' }" > env/env.ts
That take as your API key as first parameter, create a env folder and save TS code with your api key.
Then add this line
- run: sh setEnvironment.sh ${{ secrets.FIREBASE_API_KEY }}
Into your github action script, which will execute your script and set the Secret Key.
You'll now just have to use environment.firebase_api_key in your code.
Note: Your build needs to encrypt your key otherwise it will be exposed. But this can be usefull for example if you use API keys on your website and you also want your website code to be available in public on Github, without those plain keys.
How do I get my local code to use a github secret after I make/run the action for it?
Using GitHub Secrets without using GitHub Actions
Is storing credentials in Github Secrets considered safe?
It is safe to use secret in Action in a public repo?
Videos
Here's the YAML in my .github/workflows folder. I can see in the output that the key gets masked as "***" as expected. Now how do I actually reference it in my code and actually start... using it locally? My understanding is when using github secrets, the plaintext of the key is never referenced directly, just the environment variable that github uses. I'm just learning about this but it's not like any secret management tool I've ever used before.
name: secrets
on: push
jobs:
secrets-action:
runs-on: windows-latest
steps:
- shell: pwsh
env:
ENV_KEY_DEV: ${{ secrets.ENV_KEY_DEV }}
run: env