Closed 2bndy5 closed 2 months ago
I looked into this. It might be possible with a thin TS wrapper that (collects all the action inputs and then) calls into the rust run_main()
entrypoint. One of the other problems is with how to create output variables using @action/core
(from octokit ecosystem).
I'm not going to persuing this. The napi-rs project is setup to create libraries installed via npm only. I don't think its engineered to be used as an executable wrapper.
It would probably be easier to write a javascript action using dart's JS interoperability (generates javascript code from dart code). But I pretty much abandoned the cpp_linter_dart experiment when I learned the glory of rust.
I'm reopening this because I think I found a way to do this. I'm still investigating, but I have a branch that employs the neon package to generate a native node.js module from the cpp-linter lib... See node-binding/ directory in the new branch.
The tricky parts are
npm publish
command. I think that's what the neon CLI repo seems to do for releases.@actions/core
package (which is used to get action inputs). Again the neon docs are vague here. There seems to be a way to import node.js builtin functions, but it doesn't talk about using third-party libraries from npm. I think I need to publish the native module as a separate package, and then I would publish another pure JS package that imports the native module and @actions/core
package.It took me a while to figure out all the steps performed in publishing platform-specific packages, but it works now. See npmjs page.
Going forward I think I can create another package (call it @cpp-linter/gh-action
) that doesn't require a special install step and uses the @cpp-linter/cpp-linter
pkg as a dependency. My aim is to have something like the following (in cpp-linter-action/action.yml):
- uses: cpp-linter/cpp_linter_rs/gh-action@v2.0.0
with:
version: ${{ inputs.version }}
thread-comments: ${{ inputs.thread-comments }}
# ...
Recently, I discovered napi-rs which generates bindings from rust code to WASM targets. I believe it could be used in conjunction with github's octokit library[^1] because it would be installable via
npm
.[^1]: The official API used to implement native actions agnostic of the runner's OS, not for composite or docker actions