Run Python on Github Actions

How to run a python script on Github Actions on a cron or on pusn
Python
Github
Author

Isaac Flath

Published

August 10, 2022

Today I Learned

How to run a python script on a cron using github actions, or on push of a branch.

Key parts of workflow.yaml

Define the how the job runs and what the triggers are

name: myWorkflow
on:
   push:
      branches: [main]
    schedule:
      - cron: "0 0 * * *" 

Define system to run on.

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

Checkout the github repo you are in (so you can access the files)

      - name: checkout repo content
        uses: actions/checkout@v2

Setup Python 3

      - uses: actions/setup-python@v3
        with:
          python-version: "3.9"
          architecture: "x64"

Install dependencies as needed and run a python script in the repository

      - name: Install Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -Uq git+https://github.com/fastai/fastcore.git
      - name: execute py script
        run: |
          python run.py