actions / actions/toolkit

getInput not working anymore on nodejs

Open
#1,576 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Description
If i follow the steps to create a git hub action in node js (https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action) the getInput method returns an empty string. If i check all the created environment variables no 'INPUT_' variable is set. I would assume that some used dependency causing this error as it was working two weeks ago, but as i am not too deep into this library, you can probably find and fix this more easily.

To Reproduce
create action.yml

name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  time: # id of output
    description: 'The time we greeted you'
runs:
  using: 'node20'
  main: 'index.js'

create package.json

{
  "name": "tmp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@actions/core": "^1.10.1",
    "@actions/github": "^5.1.1"
  }
}

create index.js

const core = require('@actions/core');
const github = require('@actions/github');

try {
    // `who-to-greet` input defined in action metadata file
    const nameToGreet = core.getInput('who-to-greet');
    console.log(`Hello ${nameToGreet}!`);
} catch (error) {
    core.setFailed(error.message);
}

run application
npm install
node ./index.js

Take a look at the output. You will see Hello ! instead of Hello World!

Expected behaviour
See the message Hello World! with the action property set.

Environment:

  • OS: osx Ventura 13.6.1
  • Node: v20.1.0

Also tested on another mac, which was also failing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported action.yml, package.json, and index.js reproduction, then run npm install and node ./index.js as described. Compare that local execution with the GitHub Actions example linked in the report and verify whether getInput receives the action input there. Done means establishing the expected behavior and either correcting it or documenting the required execution context.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
ci-cd, devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.