Running Python code on Github (https://github.com/Inderjeetdev/chatbot):
1) In project folder create a file named script.py with actual code of Python, need to be run, example as following code:
print(“Hello, World!”)
2) Create a file named requirements.txt. It includes names of dependencies which github will use automatically, add code in it as follows:
torch
transformers
3) You can add another file named README.md with simple text explaining details of your project.
4) In your project create folders .github/workflows/ and inside it create a file run-python.yml. It will automatically use ubunu OS, setup Python, install dependences from requirements.txt file and will run python code in script.py file. Whenever you push changes to the repository (especially the main
branch) or open a pull request targeting the main
branch, the workflow is triggered automatically. Add following code in it:
name: Run Python Script
on:
push:
branches:
– main
pull_request:
branches:
– main
jobs:
run-script:
runs-on: ubuntu-latest
steps:
– name: Checkout repository
uses: actions/checkout@v2
– name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ‘3.x’
– name: Install dependencies
run: |
python -m pip install –upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
– name: Run script
run: python script.py
To run the code click on ‘Actions’ tab and it will show workflows run already. Click on one of them and see details. Then click on Job name. It will show you all the steps performed by .yml file, which include installing dependencies and below it you can see project output, etc.