Given a .js file
const renderer = process.env.RENDERER;
if(!renderer) {
console.log('missing');
return;
}
console.log(renderer);
and a package.json
{
"scripts": {
"dev": "node app.js"
}
}
I want to call the npm script inside my Github actions workflow but I want to pass the environment variable to it
name: Do
on:
workflow_dispatch:
inputs:
renderer:
description: 'A,B,C,...'
required: true
type: string
jobs:
do:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 19.x
- name: Install dependencies
run: npm install
- name: Set environment variable for renderer
run: export RENDERER=${{ inputs.renderer }}
- name: Test output
run: npm run dev
When running the workflow the script writes
missing
to the console so it seems the npm script didn’t run with the environment variable.
How can I prepend RENDERER=${{ inputs.renderer }}
to npm run dev
?
2
Answers
The
|
character allows you to specify a multi-line command :Apart from
export
, there are two more alternatives:By specifying
RENDERER
using theenv
context:and, by specifying
RENDERER=${{ inputs.renderer }}
before the command itself: