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.
If you plan to collaborate on your Python project, GitHub provides excellent features for managing contributions. By using pull requests, collaborators can suggest changes and receive feedback before merging their code. Additionally, enabling branch protection rules ensures the main
branch remains stable. You can also use labels and milestones to track progress and prioritize tasks. For long-term projects, consider adding detailed documentation using GitHub Pages. This converts markdown files into a professional-looking website. Another useful feature is issue tracking, which allows you to report bugs, request features, or assign tasks to contributors. For projects with multiple contributors, using GitHub Discussions can foster community engagement and provide a space for questions and ideas. You might also want to configure branch naming conventions and commit message guidelines for cleaner version control. Furthermore, adding a .gitignore
file ensures sensitive data, temporary files, or environment-specific configurations aren’t accidentally pushed to the repository. Continuous integration (CI) ensures every pull request is tested automatically, providing confidence that the new code won’t break existing functionality. Finally, consider setting up automated deployment workflows to publish changes to production environments upon successful tests. With these best practices, your Python project will be well-maintained, organized, and collaborative.