Automating Python Script using GitHub Action

Birappa Goudanavar
The Data Analyst Toolkit
2 min readJun 23, 2023

Are you thinking of automating Python script? If yes you are in the right place. I will explain how to automate the scripts using GitHub Action.

What is GitHub Action? GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

name: run main.py
#Replace your python file name above

on:
schedule:
- cron: '0 8 * * *' # At 00:00 on Monday

env:
#Place your environment Variables here

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner

- name: setup python
uses: actions/setup-python@v4
with:
python-version: '3.9' # install the python version needed

- name: install python packages
run: |
pip install #Python Packages
#Install all the modules here

- name: execute py script # run main.py
env:
SOME_SECRET: ${{ secrets.SOME_SECRET }}
run: python main.py

- name: commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git diff-index --quiet HEAD || (git commit -a -m "updated logs" --allow-empty)

- name: push changes
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main

After completing these steps you can find Actions Option at the top of your repository, where you can see the logs and events that are executed.

Contact me on Upwork, if you are in need of a freelancer Click. Thanks

--

--