DEV Community

Michael
Michael

Posted on

How to append to GitHub Env via JavaScript Action

Prerequsite

Sauce

DIY

const fs = require('fs');

fs.appendFileSync(process.env["GITHUB_ENV"], "test_var=true");
Enter fullscreen mode Exit fullscreen mode

Core method

const core = require('@actions/core');

core.exportVariable("test_var", "true")
Enter fullscreen mode Exit fullscreen mode

Outcome

Image description

This also works for path & step summary :)

const fs = require("fs");

export function appendEnv(key, value) {
  fs.appendFileSync(process.env["GITHUB_ENV"], `${key}=${value}`);
}

export function appendPath(path) {
  fs.appendFileSync(process.env["GITHUB_PATH"], path);
}

export function appendStepSummary(content) {
  fs.appendFileSync(process.env["GITHUB_STEP_SUMMARY"], content);
}
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)