Can we directly write Python code under "run | " section in action.yml file
Asked Answered
D

1

10

In GitHub Actions, can we directly write python code under run | -section in action.yml file? Can I write GitHub Actions scripts in Python?

Darvon answered 18/3, 2021 at 9:45 Comment(0)
M
21

There is a built-in shell keyword for python.

steps:
  - name: Display the path
    run: |
      import os
      print(os.environ['PATH'])
    shell: python

Source: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-running-an-inline-python-script


You can also use a custom shell. GitHub Actions writes the value of run to a temporary file and passes it to the specified shell by replacing {0} with the file name of the temporary script.

steps:
  - name: Display the path
    run: |
      import os
      print(os.environ['PATH'])
    shell: python {0}
Mcgaha answered 18/3, 2021 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.