Skip to content

Instantly share code, notes, and snippets.

@DariuszPorowski
Last active November 19, 2025 03:57
Show Gist options
  • Select an option

  • Save DariuszPorowski/f5dc63e845fc79a1d46ca3d016539164 to your computer and use it in GitHub Desktop.

Select an option

Save DariuszPorowski/f5dc63e845fc79a1d46ca3d016539164 to your computer and use it in GitHub Desktop.

ESM GitHub Script Action

https://github.com/actions/github-script?tab=readme-ov-file#use-esm-import

Workflow

- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
  with:
    github-token: ${{ github.token }}
    script: |
      const { default: script } = await import(`${process.env.GITHUB_WORKSPACE}/.github/scripts/my_script.mjs`)
      await script({context, github, core})

Script

// @ts-check

import path from "path";

/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
export default async ({ context, github, core }) => {
  try {
    const workDir = core.getInput("WORKDIR", { required: true });
    const filename = core.getInput("FILENAME") || "todo.txt";
    const filePath = core.toPlatformPath(path.join(workDir, filename));

    core.info(filePath);
  } catch (error) {
    core.setFailed(error.message);
  }
};

package.json

{
  "type": "module",
  "devDependencies": {
    "@actions/github-script": "github:actions/github-script"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment