toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

What is the replacement for `core.setOutput`?

Open collin-miller opened this issue 2 years ago • 12 comments

Describe the bug I am receiving warnings on my actions for using the setOutput method on the core object. The documentation suggests this method used to pass variables between actions is deprecated. Is there a replacement coming for this behavior? If not do you have a migration guide?

collin-miller avatar Oct 21 '22 15:10 collin-miller

I'm using this in the interim.

const os = require("os")
const fs = require("fs")

function setOutput(key, value) {
  // Temporary hack until core actions library catches up with github new recommendations
  const output = process.env['GITHUB_OUTPUT']
  fs.appendFileSync(output, `${key}=${value}${os.EOL}`)
}

andyhasit avatar Oct 24 '22 11:10 andyhasit

It seems fixed in version 1.10.0 #1178

fmulero avatar Oct 26 '22 18:10 fmulero

Just noticed the same warnings which point to recommendations from https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Current notification message:

The 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/

The current function logic is in packages/core/src/core.ts

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))
}

atoomic avatar Oct 31 '22 16:10 atoomic

Is there any updates on this? I've updated @actions/core to the latest version as mentioned in the blog, but I'm still seeing this warning everywhere. Does the runner need to update to? Why would you show this warning if the runner is still the old version that doesn't support the new method yet?

mboudreau avatar Nov 24 '22 00:11 mboudreau

Also still seeing this issue with the latest release.

mrfelton avatar Nov 24 '22 10:11 mrfelton

It seems fixed in version 1.10.0 https://github.com/actions/toolkit/pull/1178

#1178 was merged on September 29 in b00a9fd033f4b30f2355acd212f531ecbbb9b38f

The @actions/[email protected] tag was created on September 5, which is prior.

It seems there hasn't been a release with the setOutput improvement. Perhaps @jclem can advise on when there will be a new release?

ataylorme avatar Dec 14 '22 14:12 ataylorme

This is definitively fixed in @actions/[email protected] as described in the blog post

npm info @actions/core

@actions/[email protected] | MIT | deps: 2 | versions: 25
Actions core lib
https://github.com/actions/toolkit/tree/main/packages/core

keywords: github, actions, core

dist
.tarball: https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz
.shasum: 44551c3c71163949a2f06e94d9ca2157a0cfac4f
.integrity: sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==
.unpackedSize: 78.1 kB

dependencies:
@actions/http-client: ^2.0.1
uuid: ^8.3.2

maintainers:
- chrispat <[email protected]>
- bryanmacfarlane <[email protected]>
- hross <[email protected]>
- thboop <[email protected]>
- konradpabjan <[email protected]>

dist-tags:
latest: 1.10.0
preview: 1.6.0-beta.0

published 2 months ago by thboop <[email protected]>

And then you can dig into the package contents and find:

function setOutput(name, value) {
    const filePath = process.env['GITHUB_OUTPUT'] || '';
    if (filePath) {
        return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
    }
    process.stdout.write(os.EOL);
    command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
}

So v1 of @actions/core works with the new file commands where available, falling back to the old echo commands for backward compatibility.

bendrucker avatar Dec 21 '22 19:12 bendrucker

note that https://github.com/actions/toolkit/issues/1336 should provide a fix for it

atoomic avatar Feb 20 '23 17:02 atoomic

Just noticed the same warnings which point to recommendations from https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Current notification message:

The 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/

The current function logic is in packages/core/src/core.ts

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))
}

its not working for me, already upgrade my action/core to latest, warning still shown

paolorevillosa avatar Feb 22 '23 07:02 paolorevillosa

@paolorevillosa this was fixed in actions/core 1.10.0 as @bendrucker said. You should only be seeing those warnings if:

  • GITHUB_OUTPUT is not set
  • something in the job issuing the command using STDOUT (i.e. echo "::set-output name={name}::{value}")

Can you verify that's not the case please? Is your action public?

rentziass avatar May 19 '23 13:05 rentziass

I am using actions/core version 1.10.1 and I am still getting the deprecation warning. You can see the code here

gugaiz avatar Apr 25 '24 13:04 gugaiz

I was able to fix it in a github workflow step as below as suggested in docs

    - name: Get Id Token
      uses: actions/github-script@v7
      with:
        script: |
          let id_token = await core.getIDToken()
          core.exportVariable("ID_TOKEN", id_token);
    - name: Read env
      shell: bash
      run: echo ${{ env.ID_TOKEN }}

mukundmckinsey avatar Sep 21 '24 04:09 mukundmckinsey