toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

Replace deprecated `set-output` command with environment file

Open jongwooo opened this issue 2 years ago • 13 comments

Describe the enhancement In workflow, set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information, see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

jongwooo avatar Feb 08 '23 04:02 jongwooo

Does anyone find a fix for this?

paolorevillosa avatar Feb 22 '23 07:02 paolorevillosa

@paolorevillosa See actions/toolkit#1337

jongwooo avatar Feb 22 '23 13:02 jongwooo

@paolorevillosa Oh I just saw your comment #1218 , what I mentioned above was for workflow and I didn't find a solution for core.setOutput in actions/core. If I find a solution, I'll share it with you.

jongwooo avatar Feb 22 '23 13:02 jongwooo

I'm experiencing this as well, it seems that the setOutput function in core does both the new way, and then the old way. Perhaps for backwards compatibility? Regardless, it would be good to get some clarification if there are plans to remove the old way from this library, and if we can just ignore the warning.

ksaunders avatar Apr 10 '23 16:04 ksaunders

@ksaunders the code I'm reading only does it one of the ways. But it keeps running it the old way for one of my actions. Code I'm seeing 1.10.0:

export function setOutput(name: string, value: any): void {
  const filePath = process.env['GITHUB_OUTPUT'] || ''
  if (filePath) {
    return issueFileCommand('OUTPUT', prepareKeyValueMessage(name, value))
  }

  process.stdout.write(os.EOL)
  issueCommand('set-output', {name}, toCommandValue(value))
}

so if process.env['GITHUB_OUTPUT'] is empty it does it the old way with issueCommand('set-output']), but if its not empty it does it the new way.

One of my actions must be evaluating process.env['GITHUB_OUTPUT'] to empty as I'm using actions/core 1.10.0 and still getting the set-output warning.

Seems frustrating that the library which we're supposed to use will sometimes try it in a deprecated way. I'm also pretty bad at debugging github actions so I'm drawing a blank why my action would evaluate the GITHUB_OUTPUT as not there?

twohlix avatar May 11 '23 22:05 twohlix

Hey @twohlix 👋 you're correct in that old behaviour is still present in actions/core for backwards compatibility reasons. Runner should be setting GITHUB_OUTPUT in your jobs, would you able to please validate the env variable is there and is not being unset/overwritten? You should only get a warning if one of this is true:

  • actions/core < 1.10.0
  • GITHUB_OUTPUT is not set
  • something is issuing the command using STDOUT (i.e. echo "::set-output name={name}::{value}")

Does your action have any other dependencies that could affect this? Also if your action is public I'd be happy to have a look :)

rentziass avatar May 19 '23 13:05 rentziass

I see <1.10.0 mentioned, but there is no version since: https://www.npmjs.com/package/@actions/core?activeTab=versions.

While I agree that the code inside of @actions/core is correct on main, the code you're referring to was never released, as far as I can tell.

~~Incorrect (1.10.0): https://github.com/actions/toolkit/blob/%40actions/core%401.1.0/packages/core/src/core.ts~~ (see below) Correct, but unreleased: https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L192

So I think we can clear this up if GitHub makes a new release of @actions/core, and I update the dependency here.

ksaunders avatar May 19 '23 13:05 ksaunders

Actually, I must be wrong, because manually inspecting the package shows that it's correct code. I linked the 1.1.0 tag, not the 1.10.0 tag. So I am mistaken. I'll keep looking. We use 1.10.0 here, which is why I am so confused.

ksaunders avatar May 19 '23 13:05 ksaunders

@ksaunders are you 100% sure the warning is coming from your action and not something else within the job? If your action is public also happy to have a look!

rentziass avatar May 19 '23 13:05 rentziass

As it turns out, it was a build issue. For some reason the Vercel ncc bundler we were using would not recompile the setOutput function when we updated to 1.10.0 until I blew away the dist folder entirely, now I have manually verified the code.

Sorry for the wild goose chase folks. Thanks for the help. 1.10.0 LGTM.

ksaunders avatar May 19 '23 14:05 ksaunders

Does your action have any other dependencies that could affect this? Also if your action is public I'd be happy to have a look :)

I figured out my issue. Was indeed related to a dependency in the action preventing a real upgrade from being packaged. Apologies for the false alarm.

twohlix avatar May 22 '23 02:05 twohlix

@rentziass my action is using core.setOutput which then raise some warnings what are the suggested alternate to write some output instead? console.log? other?

view https://github.com/perl-actions/install-with-cpm/blob/f1a3c07b144a476307db782753096b2c7690d968/index.js#L30

Reported to the action repo as https://github.com/perl-actions/install-with-cpm/issues/15

async function install_cpm(install_to) {
  const version = core.getInput("version");
  const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`;

  core.setOutput(`Get cpm from ${url}`);

  const cpmScript = await tc.downloadTool(url);

  core.setOutput("cpm", cpmScript);

here is an example usage where the deprecation warning is visible https://github.com/cpanel/Test2-Harness-Renderer-JUnit/actions/runs/7390262832

thanks

atoomic avatar Jan 02 '24 21:01 atoomic

note: I just fixed it using core.info instead

atoomic avatar Jan 02 '24 22:01 atoomic