Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Release setup-python as an npm package #38

@peter-evans

Description

@peter-evans

I have a Javascript action that executes Python. It would be great if I could add @actions/setup-python as a dependency and call it from my Javascript action.

In order to make it work for now I converted parts of this action into a setupPython function that I've included with my action. Below is a simplified snippet of what I'm doing now. Full source code here.

async function run() {
  try {
    const src = __dirname + "/src";

    // Setup Python from the tool cache
    setupPython("3.8.0", "x64");

    // Install requirements
    await exec.exec("pip", [
      "install",
      "--requirement",
      `${src}/requirements.txt`
    ]);

    // Execute python script
    await exec.exec("python", [`${src}/create-pull-request.py`]);
  } catch (error) {
    core.setFailed(error.message);
  }
}

Here is a python-action template that also demonstrates what I'm doing in the snippet above.

Why call Python from a Javascript action?
The reason I ended up doing this and not writing the whole action in Javascript requires a bit of history and explanation. I wrote the action during GitHub Actions beta v1 when it was just container actions. When Actions v2 arrived the choices were Javascript or Docker container actions. I want the action to be multi-platform and runnable on any virtual machine, so I have no choice but to wrap it with a Javascript action as I'm doing, or convert the whole action to Javascript.

Even if Docker container actions worked on all platforms I think I would still choose to wrap Python in Javascript like this. The two issues I don't like about container actions are:

  • When using image: 'Dockerfile' it's slow because the image is built from scratch every time the workflow runs.
  • When using image: 'docker://my-namespace/my-image:1.0.0' it cannot be forked easily because the reference to the public Docker image remains. Being able to fork GitHub actions is important for security conscious users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions