1

Every time we use core.exportVariable which, as far as I know, is the canonical way to export a variable in @action/core and, consequently, in github-script, you get an error such as this one:

Warning: The set-env command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

That link leads to an explanation of environment files, which, well, are files. Problem is files do not seem to have such a great support in github-script. There's the @actions/io package, but there's no way to create a file with that.

So is there something I'm missing, or there is effectively no way to create an environment file form inside a github-script step?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86

1 Answers1

1

You no longer need the actions/github-script nor any other special API to export an environment variable. According to the Environment Files documentation, you can simply write to the $GITHUB_ENV file directly from the workflow step like this:

steps:
  - name: Set environment variable
    run: echo "{name}={value}" >> $GITHUB_ENV

The step will expose given environment variable to subsequent steps in the currently executing workflow job.

Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51
  • Except, as I say above, if the environment variable is generated from within a github-script step, there's actually no way to export it or to write it to a file. – jjmerelo Nov 03 '20 at 06:47