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

Javascript actions without checking in node_modules #100

Closed
thomaseizinger opened this issue Aug 30, 2019 · 5 comments
Closed

Javascript actions without checking in node_modules #100

thomaseizinger opened this issue Aug 30, 2019 · 5 comments
Assignees

Comments

@thomaseizinger
Copy link

From the example actions like labeler, I get the impression that the idea is to check node_modules into VCS so that the runner can resolve the dependencies of the action at runtime.

Instead of doing that, I'd much rather use a tool like webpack to bundle everything up that is necessary and only check in the generated file.
However, it seems that "@actions/github" is not compatible with that approach. My action fails at runtime because it cannot import the event.json file: https://github.com/thomaseizinger/actions-playground/runs/207679280

For now, I resorted to not use the "@actions/" dependencies and code the requests myself since they are fairly trivial.

IMO, it would be good to have examples that use webpack and a zero-dependency JavaScript file for actions.
The project I am currently working on is here: https://github.com/thomaseizinger/assign-pr-creator-action

@damccorm
Copy link
Contributor

Yeah, our recommendation here is still a little bit in flux (see actions/typescript-action#4) - when that's settled we'll probably have some better examples. The reason this failed for you is because we have a dynamic require, I added #101 to get rid of that. Once that's gone, the basic config should work.

@damccorm damccorm self-assigned this Aug 30, 2019
@thomaseizinger
Copy link
Author

Ah yeah, thanks!
I figured it would be the dynamic require :)

Thanks for sending a PR that quickly!
Since the issue you linked is already tracking this, I'll close this one!

@yoavain
Copy link

yoavain commented Sep 23, 2019

You can use my action here as reference:
Setup-CSC project
You can see changes from version 4 to version 5 there.

In my opinion best practice is:

  • not to check-in node_modules at all
  • use webpack to create a single file bundle under lib
  • remove the git-diff from the action (that makes sure lib files are committed)
  • instead, use husky, pre-commit hook to compile, webpack, test & git add bundle files from lib

@thomaseizinger
Copy link
Author

instead, use husky, pre-commit hook to compile, webpack, test & git add bundle files from lib

That is certainly better than checking in node_modules!
Ideally, I would want to release a to GPR/npm on tagged commits and have other people use this package. That would be the cleanest approach IMO.

@yoavain
Copy link

yoavain commented Sep 24, 2019

One more advantage of using webpack is the size of the code base, which improves performance for anyone using your action. When I replaced node_modules with webpack, source code zip size reduced from ~900K to ~150K

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

No branches or pull requests

3 participants