Skip to main content

dandori: GitHub Actions with Python

dandori runs on your Actions, and automate workflow with using Python.

Current Status is Super Early Alpha. DO NOT USE IT in your production repository.

How to Use

First, You need to define workflow. You can hook any events without manual/scheduled workflow such as pull_request, push or pull_request_review.

name: dandori_action
on: [pull_request, issue_comment]

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - run: pip install dandori
      - run: dandori run
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Next, you can write your Python script or package on your repo, like dandori_handler.py or 'dandori_handlers/'. dandori automatically import your code and run handler functions defined in your code:

## dandori_handler.py

def handle_pull_request(ctx):
    if ctx.gh.payload.action == 'synchronize':
        ctx.gh.create_comment("You pushed new commits!!")


def handle_pull_request_comment(ctx):
    """It's a special handler type, issue_comment event on PR"""
    comment_body = ctx.gh.comment_body().strip()
    if comment_body.startswith('/some-command'):
        some_code_as_you_like()

If you want more than one file, you need to make a package:

## handlers/__init__.py
# Must be relative imports
from .pull_request import handle_pull_request
from .issue import handle_issue

## handlers/pull_request.py
def handle_pull_request(ctx):
    ...

## -- handlers/issue.py
def handle_issue(ctx):
    ...

Configuration

dandori supports pyproject.toml, or make any toml file as you like (default is dandori.toml).

In pyproject.toml, write config in tool.dandori section:

# pyproject.toml
[tool.dandori]
handlers = ['path/to/handler']

In independent toml file, write config in dandori section:

# dandori.toml
[dandori]
handlers = ['path/to/handler']

Use case

Share CI code with multiple repo:

name: dandori_action
on: [pull_request, issue_comment]

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/checkout@v2
        with:
          repository: your/dandori-handler
          ref: v1  # something you need
          ssh-key: ${{ secrets.your_repo_key }}
          path: dandori-handler
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - run: pip install dandori
      - run: dandori run -f dandori-handler/dandori.toml
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Use third party package in handler

Your handler module or package will be imported dynamically, so you can install any library in the "(virtual)env" same as dandori installed.

Most simple cale, install dandori with other library:

# Install libraries with pip
- run: pip install dandori requests python-dateutil

If you want use just a "command" and not to use global env, use ctx.ops.run_venv():

def handle_pull_request(ctx):
    ctx.ops.run_venv(["pip", "install", "twine"])
    ctx.ops.run_venv(['twine', 'upload', 'dist/*'])

Or dynamically install it and use it:

import importlib

def handle_pull_request(ctx):
    ctx.ops.run(["pip", "install", "requests"])
    requests = importlib.import_module('requests')

Metadata

Release files for dandori 0.1.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dandori 0.1.26
File Size Uploaded
dandori-0.1.26.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dandori 0.1.26
File Interpreter ABI Platform
dandori-0.1.26-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / dandori-0.1.26.tar.gz

Download URL dandori-0.1.26.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1b773e3fb4487844f09affa29ff24e59b4f1b28a390311adf76679e3ff4079ec
BLAKE2b-256 checksum
How to use checksums
ba42095c56c68c4faa9c645321275addbbcd26bbe3f0bf29219e819f857e8662
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / dandori-0.1.26-py3-none-any.whl

Download URL dandori-0.1.26-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d96e6cf3146c659fa496b19dfbb72a01e8a5639d90c1798fcaab39ae60c92c6
BLAKE2b-256 checksum
How to use checksums
a8afad5bfe46236ddb66f40122c1746adc243790cb9ae48f91f6852434c24f3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.1.26 This release

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page