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

How to use this in a composite action? #322

Open
PaulRBerg opened this issue Jan 7, 2023 · 4 comments
Open

How to use this in a composite action? #322

PaulRBerg opened this issue Jan 7, 2023 · 4 comments
Labels
question A question on how to use this action

Comments

@PaulRBerg
Copy link

I’m looking to create a composite action, and the task that I’m working on would be easiest to implement by doing some work in JavaScript and some other work in a Bash script. Can I use this action (github-script) to achieve this?

I added this to my action:

uses: "actions/github-script@v6"
with:
  script: |
    const script = require("./dist/index.js")
    script({core})

But then I got this error when I ran it:

Error: Cannot find module '/home/runner/work/v2-core/v2-core/dist/index.js'
Require stack:
- /home/runner/work/_actions/actions/github-script/v6/dist/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.apply (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13400:27)
    at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13356:16), <anonymous>:3:16)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13357:12)
    at main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13452:26)
    at Module.858 (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13429:1)
    at __webpack_require__ (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:[24](https://github.com/sablierhq/v2-core/actions/runs/3861794209/jobs/6583130559#step:3:26):[31](https://github.com/sablierhq/v2-core/actions/runs/3861794209/jobs/6583130559#step:3:33)) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/_actions/actions/github-script/v6/dist/index.js'
  ]
}

What am I doing wrong?

Side note - why not enable discussions in this repository?

@joshmgross
Copy link
Member

The path is relative to the current working directory, which isn't the same as the directory where the composite action was checked out.

I don't know the right path at the top of my head, but it might be inside runner.temp - https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context

why not enable discussions in this repository?

👍 Good idea, I've enabled discussions.

@joshmgross joshmgross added the question A question on how to use this action label Jan 10, 2023
@joshmgross
Copy link
Member

@PaulRBerg github.action_path might be what you're looking for:

The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action.
https://docs.github.com/actions/learn-github-actions/contexts

So maybe something like this will work:

uses: "actions/github-script@v6"
with:
  script: |
    const script = require("${{github.action_path}}/dist/index.js")
    script({core})

@PaulRBerg
Copy link
Author

Oh, yes. This was exactly what I needed. Thanks for digging this up, Josh!

@igorbrites
Copy link

@PaulRBerg github.action_path might be what you're looking for:

The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action.
https://docs.github.com/actions/learn-github-actions/contexts

So maybe something like this will work:

uses: "actions/github-script@v6"
with:
  script: |
    const script = require("${{github.action_path}}/dist/index.js")
    script({core})

Perfect answer, just what I was looking for, thanks @joshmgross!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question on how to use this action
Projects
None yet
Development

No branches or pull requests

3 participants