github-action-utils icon indicating copy to clipboard operation
github-action-utils copied to clipboard

Detect if the script is running in github action environment

Open oxygen-dioxide opened this issue 3 years ago • 1 comments

If I'm developing a script that runs either locally or in github action, I may want to detect whether it is running in github action environment, because some functions in github-action-utils is unusable locally. Although I can detect the environment by using try-catch, I still want a more Pythonic solution in the github-action-utils module. For example, a is_github_action() function that returns a bool.

oxygen-dioxide avatar Mar 13 '23 10:03 oxygen-dioxide

You can use GITHUB_ACTIONS or CI (Always set to true when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions.) environment variables to check if you code is running locally or via GitHub Actions.

ref: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

This is the recommended way provided by GitHub.

saadmk11 avatar Mar 20 '23 07:03 saadmk11