-
Notifications
You must be signed in to change notification settings - Fork 410
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
Is there any possibility to use file as a script? #38
Comments
End up with following solution:
Also note that in this case need to throw external variables inside script through Js script may be safely wrapped into async function to get correct syntax and avoid errors:
But in this case you won't be able to retrieve any |
Using files instead of strings would be nice. Will save a lot of code in my .yml files and allows me to re-use scripts I already use for other stuff. I made a local PR to add file support. I'm testing it now and will create a PR here tomorrow. |
Having arbitrary code to run inside to the yaml file, it is not a good idea, for many reasons:
IMO yaml is good to contain declarative statements only and it should be as concise as possible. Having file as an input should be coming from the design review, not from customer feedback. |
In fairness, it is true when you selling your product, and there are customers. Otherwise, when you building some tool for yourself and publishing to help others - it is not really fair to say like that :) |
My fault, I completely missed this action is experimental indeed as stated in the README.md file. I take it back :) |
@lukka We're not going to remove the ability to inline the script—we've seen that there's a huge demand for it in development lifecycle flows where a user just wants to write one file that accomplishes the task of something like commenting on an issue. Also, I use it myself a huge amount in quick one-off workflows that I don't want to put much effort into 😆 That said, I also think there's value in being able to run a file, and I plan on adding this soon. |
The more I think about it, the less I'm convinced that adding this is necessary. If you want to run a file instead of a plain script, it can be done this way: uses: actions/github-script@v0.9.0
with:
script: |
const path = require('path')
return require(path.resolve('my-script.js'))({context}) And then, in your file: module.exports = ({context}) => {
return context.payload.client_payload.value
} It's also safe to use a module exporting an async function in this way as long as you |
@jclem I think any solution would work, as long as it is documented. So, yours actually looks great, but I'd add it to the readme. |
@extempl Thanks—does this seem clear? https://github.com/actions/github-script#run-a-separate-file |
In the meantime, I'm going to go ahead and close this issue. While it's not quite as simple on the user-side as adding a file as an input to the Action, it has the benefit of:
|
Yes, the only thing is missing I think, is the note about mandatory checkout |
Good call, I will add that. |
@jclem Can you please explain how exactly can people use it? |
Maybe using
cat file
or something?If no, is it possible to add?
Because it is not that easy to write normal js code inside yaml.
The text was updated successfully, but these errors were encountered: