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

Fix MODULE_NOT_FOUND #5

Merged
merged 2 commits into from
Apr 17, 2023
Merged

Fix MODULE_NOT_FOUND #5

merged 2 commits into from
Apr 17, 2023

Conversation

dekimsey
Copy link
Contributor

@dekimsey dekimsey commented Apr 15, 2023

Description

By default the working directory of the composite action is the calling workflows's context. This means a relative require like what was done here isn't reading the action's embedded main.js but instead trying to read main.js in the caller's workflow.

This presented as an error message like such:

Error: Cannot find module '/home/runner/work/eng-serv-cron/eng-serv-cron/main.js'
Require stack:
- /home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/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/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15186:27)
    at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15143:16), <anonymous>:3:8)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15144:12)
    at main (/home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15236:26)
    at /home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15217:1
    at /home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js:15268:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js'
  ]
}
Error: Unhandled error: Error: Cannot find module '/home/runner/work/eng-serv-cron/eng-serv-cron/main.js'
Require stack:
- /home/runner/work/_actions/actions/github-script/d7906e4ad0b1822421a7e6a35d5ca353c962f410/dist/index.js

This wasn't caught during testing because GHA requires one to check the testing repo out before being able to run a local action. This masked the behavior as our checkout directory was always the same as the action we were testing.

I believe it was missed in the integration tests because those were tested when the main.js content was embedded in the action.yml.

Resolution

  • This PR fixes the original issue by using absolute pathing to load the main.js from the action's source tree as originally intended.
  • We also add a test to validate this will not occur in the future. The workflow must load a hard-coded uses, so we execute against main after a PR is closed. This allows us to validate the action will work in the exact same way our calling workflows might use it.
  • Submitted a PR to document this in github/actions-script#368.

Note: github.action_path would be the correct Node variable to retrieve the action's source directory, but there's discussion about this being broken for the moment. Instead we'll use process.env.GITHUB_ACTION_PATH, until actions/runner#2517 is fixed.

@dekimsey dekimsey added the bug Something isn't working label Apr 15, 2023
@dekimsey dekimsey requested review from jeanneryan and a team April 15, 2023 20:20
@dekimsey dekimsey self-assigned this Apr 15, 2023
@dekimsey dekimsey requested review from shore and removed request for shore April 15, 2023 20:20
By default the working directory of the composite action is the calling
workflows's context. This means a relative require like what was done here
isn't reading the action's main.yml.

This wasn't caught during testing because GHA requires one to check the testing
repo out before being able to run a local action. This masked the behavior.

I believe it was missed in the integration tests because those were tested when
the main.js was _embedded_ in the action.yml. Hilarious.
@dekimsey dekimsey force-pushed the composte-actions-have-special-paths branch from ade03ee to 18c0cb3 Compare April 15, 2023 20:22
Copy link

@jeanneryan jeanneryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dekimsey dekimsey merged commit 5f2be72 into main Apr 17, 2023
@dekimsey dekimsey deleted the composte-actions-have-special-paths branch April 17, 2023 15:35
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

Successfully merging this pull request may close these issues.

2 participants