Usually Python is not the preferred option for GitHub actions due to it being limited by the use of Docker, which produces large images even for relatively simple programs and even with optimizations such as multi-stage builds.
Fortunately, the composite action type allows for blazing fast execution, because there’s no need to build a Dockerfile. For example, my CloudFlare cache purge action runs in up to 2 seconds, while similar Docker actions would take more than 15-20s.
In order to utilise the composite action type for Python scripts the below is the bare minimum thing needed in your action.yml
:
runs:
using: "composite"
steps:
- run: python ${{ github.action_path }}/script.py
shell: bash
If the script imports non-default packages, you can easily python -m pip install
in runs.steps
.
If the action needs input
, the easiest way is to pass them as parameters to your script:
runs:
using: "composite"
steps:
- run: python ${{ github.action_path }}/script.py ${{ inputs.aninput }}
shell: bash
To perform composite logic with inputs, the easiest way is to ditch inputs alltogether and use env
in your action definition instead. Note that when using env instead of input you also have to code the logic for required/optional inputs, as this will not be provided from GitHub Actions anymore.