Issue
I have a basic git repo set up with github actions to build and deploy (HTML and TS files mainly).
However I have to use in some API Keys that needs to be secret.
So I figure out to use GITHUB SECRETS for them.
How can I access GITHUB SECRETS in my js (or TS) files so it can build with github actions properly?
Solution
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
.
Answered By - scthi Answer Checked By - Pedro (WPSolving Volunteer)