From d80194e53087a64ca2127b43ebf20a08302ae8bd Mon Sep 17 00:00:00 2001 From: Daniel Kimsey <90741+dekimsey@users.noreply.github.com> Date: Mon, 17 Apr 2023 09:27:21 -0500 Subject: [PATCH] doc: Explain differencs in CWD when run in a composite action This documents an easy to make mistake regarding how to require a resource from the action's source. When a relative path is used, the CWD is the workflow's not the composite action's. This surfaces to calling workflows as a `MODULE_NOT_FOUND` error. --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 29e294565..41f06d7f3 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,23 @@ Additionally, you'll want to use the [checkout action](https://github.com/actions/checkout) to make sure your script file is available. +### Running in Composite Actions + +When used from a composite-action the current working directory is the invoking workflow, +*not* the composite action's. Be sure to use an absolute path to any of the action's +resources in this case like so: + +```yaml +name: My Composite Action Using Github Scripts +runs: + using: "composite" + steps: + - uses: actions/github-script@v6 + script: | + const script = require(process.env.GITHUB_ACTION_PATH + '/my-action-main.js') + console.log(script({context, core}) +``` + ### Run a separate file with an async function You can also use async functions in this manner, as long as you `await` it in