Getting path from a node action?

I’m trying to figure out how to get access to the workspace when writing an action in Node.js. 

I know there’s a github.workspace thing, but I can’t find any docs on how to get access to that inside Node

Meanwhile I wrote an action that tries to use process.cwd():

   const pkgPath = `${process.cwd()}/package.json`;
   console.log('cwd', process.cwd(), pkgPath);

The output is this:

> cwd /home/runner/work/RepoName/RepoName /home/runner/work/RepoName/RepoName/.github/actions/my-action/dist/package.json

So somehow process.cwd() on it’s own outputs
> /home/runner/work/RepoName/RepoName

Which is the path I’m after…

But ${process.cwd()}/package.json outputs
> /home/runner/work/RepoName/RepoName/.github/actions/my-action/dist/package.json

With the path including the full path to the action.

I also see that job has a working_directory property but can’t find a good example of how to use it.

Any ideas?

It turns out the way to do this is just from environment variables:

process.env.GITHUB_WORKSPACE

I was confused by the toolkit - I tried

const github = rrequire('@actions/github');

console.log(github.workspace);

It’s obvious in hindsight :grimacing:

Still think the behaviour of process.cwd() is odd tho…