Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the replacement for core.setOutput? #1218

Open
collin-miller opened this issue Oct 21, 2022 · 12 comments
Open

What is the replacement for core.setOutput? #1218

collin-miller opened this issue Oct 21, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@collin-miller
Copy link

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 collin-miller added the bug Something isn't working label Oct 21, 2022
@andyhasit
Copy link

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

@fmulero
Copy link

fmulero commented Oct 26, 2022

It seems fixed in version 1.10.0 #1178

@atoomic
Copy link

atoomic commented Oct 31, 2022

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

@mboudreau
Copy link

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?

@mrfelton
Copy link

Also still seeing this issue with the latest release.

@ataylorme
Copy link

It seems fixed in version 1.10.0 #1178

#1178 was merged on September 29 in b00a9fd033f4b30f2355acd212f531ecbbb9b38f

The @actions/core@1.1.0 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?

@bendrucker
Copy link

This is definitively fixed in @actions/core@1.10.0 as described in the blog post

npm info @actions/core

@actions/core@1.10.0 | 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 <chrispat@github.com>
- bryanmacfarlane <bryanmacf@gmail.com>
- hross <hross@github.com>
- thboop <thboop@github.com>
- konradpabjan <konradpabjan@github.com>

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

published 2 months ago by thboop <thboop@github.com>

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.

redian added a commit to redian/tar-action that referenced this issue Jan 5, 2023
In version 1.10.0 of `@actions/core` they have fixed the warning we are getting for set-output in our github actions.

As per per this PR actions/toolkit#1178
And as discussed here actions/toolkit#1218
sadikassistivlabs added a commit to sadikassistivlabs/issue-bot that referenced this issue Jan 12, 2023
@atoomic
Copy link

atoomic commented Feb 20, 2023

note that #1336 should provide a fix for it

@paolorevillosa
Copy link

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

@rentziass
Copy link
Member

@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?

@gugaiz
Copy link

gugaiz commented Apr 25, 2024

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

@mukundmckinsey
Copy link

mukundmckinsey commented Sep 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests