DEV Community

Play Button Pause Button
Matt Hamilton
Matt Hamilton

Posted on

Automatically Paying Code Contributors with XRP - DEV: Github Actions Hackathon

A 1080p version of this video is available on Cinnamon

This is the recording of a live coding session I did on the IBM Developer Twitch channel. I was joined by my colleague Si Metson.

We decided to revive an idea we had for a previous hackathon, to be able to trigger payments to developers when they commit code to Github. We never finished that code or submitted it to the PayID hackathon in the end. So we decided to reformulate it from being a serverless function on IBM Cloud Functions and fired by a Github webhook, to being a Github Action.

This fitted in nicely with the Github Actions Hackathon that was ending soon.

In the coding session Si and I looked at what Github Actions are, and how they are defined. In short, there is a specific directory in a github repo /.github/workflows in which you can put a YAML file defining a workflow to be called.

The workflow outlines an environment on which it will run and defines a number of steps to be run. Each step uses an existing action. So for example the initial workflow we had was this:

name: PayID Action

  # Trigger the workflow on push or pull request,
  # but only for the master branch
      - master

    runs-on: ubuntu-latest

    # Check out the code
    - uses: actions/checkout@v2

    # Set up a python environment to run code in  
    - name: Set up Python
      uses: actions/setup-python@v2
        python-version: '3.x'

    # Install our python dependancies
    - name: Install dependencies
      run: |
        pip install -r requirements.txt

    # Get the latest commit message
    - name: get commit message
      run: |
        echo ::set-env name=commitmsg::$(git log --format=%B -n 1 ${{ github.event.after }})

    # Debugging: show the commit message
    - name: show commit message
      run : echo $commitmsg

    # Run our python code and set an environment variable
    # with contents of a secret from the Github secret vault
    # for this repo
    - name: Run PayID
      run: |
Enter fullscreen mode Exit fullscreen mode

One of the key features we liked about creating this functionality as a Github Action is that we can store and access secrets in Github. In this case we need to securely store the secret key for our XRP wallet in order to be able to sign a transaction authorising a payment to be made.

The code for can be found in the repository:

GitHub logo hammertoe / payid_xrp_action

A Github Action that pays a contributor in XRP for every commit



A Github Action that pays a contributor in XRP for every commit This means you can define an amount to be paid every time someone pushes commits to you repository.

The address to send the payment to is looked up via PayIds in the commit messages.

How to set it up?

An example workflow:

name: Pay contributors

  # Trigger the workflow on push or pull request,
  # but only for the master branch
      - master

    runs-on: ubuntu-latest

    - name: Checkout code
      uses: actions/checkout@v2

    - name: get commit message
      run: |
        echo ::set-env name=commit_log::$(git log --format=%B ${{ github.event.before }}..${{ github.event.after }})

    - name: Run PayID
      uses: hammertoe/payid_xrp_action@master
        commit_log: ${{ env.commit_log }}
        wallet_secret: ${{ secrets.PAYID_WALLET_SECRET }}
        amount: 1000000
Enter fullscreen mode Exit fullscreen mode

The above workflow will pay each PayId…

Beyond what we achieved in the video, I went on to convert the workflow to instead of calling the python directly, to refer to the python code as an action itself. The action is then defined in an action.yaml file:

name: 'Automatically pay Contributors in XRP via PayId'
description: 'Scan commit messages for PayId and make payment to that PayId in XRP on push'
author: 'Matt Hamilton'
  icon: dollar-sign
  color: green
    description: 'Amount of XRP in drops to pay each PayId found'
    default: 1000000
    description: 'The commit message(s) to scan for PayIds'
    required: true
    descrption: 'The secret key of the XRP wallet to pay from'
    required: true
    description: 'Maximum number of drops to pay out'
    default: 10000000
    description: 'Environment to use, TESTNET or LIVENET'
    default: 'TESTNET'
    description: 'XRP Ledger server to use'
    default: ''
  using: 'docker'
  image: 'Dockerfile'
Enter fullscreen mode Exit fullscreen mode

This defines the inputs that the action will take, and how it should be run. Github actions supports just two runtimes: javascript and docker. With docker of course you can create whatever runtime you want. So as you see above, on the last line, we refer to a Dockerfile.

In our case the Dockerfile looks like:

FROM python:3.7-slim


ADD . /app

RUN apt-get update \
    && apt-get install -y --no-install-recommends gcc libgmp3-dev python3-dev \
    && rm -rf /var/lib/apt/lists/* \
    && pip install --trusted-host -r requirements.txt \
    && apt-get purge -y --auto-remove gcc libgmp3-dev python3-dev

ENTRYPOINT ["python"]

CMD ["/app/"]
Enter fullscreen mode Exit fullscreen mode

As we need to install some python dependencies (the xpring library) that need some libraries for cryptographic routines, we need to install a number of system packages and compiler: gcc libgmp3-dev python3-dev.

Putting this all together, we can then publish this action on the Github Actions marketplace so it is available for anyone to use:

Screenshot of entry in Github Actions marketplace

Hackathon Entries

The actual submissions for the Github actions hackathon are:

For the category Maintainer Must-Haves:

For the category Wacky Wildcards:

I hope you enjoyed the video, I stream on Twitch weekly and you can usually find out when on the IBMDeveloper Twitch stream schedule or follow me on Twitter: @hammertoe.

Top comments (0)