DEV Community

Michael
Michael

Posted on

1 1

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay