Skip to content

A project base for automating Python tasks using GitHub actions and Aiven for PostgreSQL

License

Notifications You must be signed in to change notification settings

Mulugruntz/gh-automation-base

Repository files navigation

gh-automation-base

GH_Automation_:: version

License MIT Python 3.11 Poetry Checked with mypy Code style: black Linting: Ruff

A project base for automating tasks in Python using GitHub actions and an Aiven for PostgreSQL database.

Setup (quick start)

  1. Create a new repository using this repository as a template.

  2. Create a new Aiven PostgreSQL service.

  3. Copy .env.example to .env and fill in the values.

  4. Install poetry and the dependencies (base + dev) using the following commands:

    pip install poetry
    poetry install --all-extras
  5. Initialize the database using the following command:

    make migration-init migration-apply
  6. Push to GitHub, set the repo secrets and enable GitHub actions.

  7. This will start populating your database with Quotes (example pipeline).

Make it your own

Create your Aiven service

  1. Create an Aiven account (or reuse an existing one) at aiven.io.
  2. Create a new PostgreSQL service. You can create a free one if you do not already have one.

Create your repository

  1. Create a new repository using this repository as a template.
  2. Set up your repo secrets using the values from your Aiven service.

Set up your local environment

  1. Install poetry and the dependencies (base + dev) using the following commands:

    pip install poetry
    poetry install --all-extras
  2. Copy .env.example to .env and fill in the values, using the values from your Aiven service.

Adapt the code to your needs

There are four files that will interest you:

  • gh_automation_base/pipelines/quotes.py: the example pipeline file.
    • Delete this file and create your own pipeline file.
  • gh_automation_base/cli.py: the CLI entrypoint.
    • Register your own endpoint here. You can delete the quotes endpoint.
  • migrations/*: the database migrations.
    • Declare your tables here. If you do not use the example pipeline, you should delete the quotes table migration file before running any migration command.
  • .github/workflows/run-task.yml: the GitHub action workflow file.
    • Modify the poetry run auto quotes command to call your own endpoint instead.
    • Change the cron schedule to your liking.

Initialize your database

After having created all the migrations you need (using make migration-new), you can initialize your database using the following command:

make migration-init migration-apply

Set up the GitHub Action

  1. Have GitHub call your endpoint in the workflow file here: poetry run auto <your-endpoint>.
  2. Push your code to your repository.

About

A project base for automating Python tasks using GitHub actions and Aiven for PostgreSQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published