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.
How can I use Github secrets in JS files
Using GitHub Secrets without using GitHub Actions
How do I get my local code to use a github secret after I make/run the action for it?
How to automate GitHub secrets?
Videos
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.
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: envSeems the set secrets can't be read as json, so i just took the secret.json to a new private repository, then i placed its raw.githubusercontent.com/Username/main/secret.json?token=*** url (the url had the token query too) in a secret variable called GOOGLE_API_URL then in my action i just created a steps to download and set the credentials like this:
- name: Download credentials
env:
TOKEN: ${{ secrets.GOOGLE_API_URL }}
run: |
credentials=$(curl -s $TOKEN)
echo "Downloaded credentials: $credentials"
- name: Set credentials env var
run: |
GOOGLE_APPLICATION_CREDENTIALS=$credentials
echo "Credentials env var: $GOOGLE_APPLICATION_CREDENTIALS"
Figured it out. Google needs to document this better.
const GOOGLE_TRANSLATE = new GoogleTranslate(
{
projectId: process.env.GOOGLE_PROJECT_ID,
credentials: {
client_email: auth.client_email,
private_key: auth.private_key,
}
},
)