XRP로 코드 기여자에게 자동으로 지불 - DEV: Github Actions Hackathon

A 1080p version of this video is available on Cinnamon

이것은 제가 IBM Developer Twitch channel에서 했던 라이브 코딩 세션의 녹화본입니다. 동료와 합류했습니다.

우리는 부활하기로 결정했습니다. 우리는 그 코드를 끝내거나 PayID 해커톤에 제출하지 않았습니다. 그래서 우리는 IBM Cloud Functions의 서버리스 기능에서 Github Webhook에 의해 실행되는 기능에서 Github Action으로 재구성하기로 결정했습니다.

이것은 곧 끝나는 것과 잘 어울렸습니다.

코딩 세션에서 Si와 저는 Github Actions가 무엇이며 어떻게 정의되는지 살펴보았습니다. 즉, github repo/.github/workflows에는 호출할 워크플로우를 정의하는 YAML 파일을 넣을 수 있는 특정 디렉토리가 있습니다.

워크플로는 실행될 환경을 설명하고 실행할 여러 단계를 정의합니다. 각 단계는 기존 작업을 사용합니다. 예를 들어 초기 작업 흐름은 다음과 같습니다.

name: PayID Action

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

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    # 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
      with:
        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
      env:
        PAYID_WALLET_SECRET: ${{ secrets.PAYID_WALLET_SECRET }}
      run: |
        python pay_contributor.py

이 기능을 Github Action으로 만들 때 마음에 들었던 주요 기능 중 하나는 Github에 비밀을 저장하고 액세스할 수 있다는 것입니다. 이 경우 지불을 승인하는 트랜잭션에 서명할 수 있도록 XRP 지갑의 비밀 키를 안전하게 저장해야 합니다.
pay_contributor.py에 대한 코드는 저장소에서 찾을 수 있습니다.


망치족지 / payid_xrp_action


모든 커밋에 대해 기여자에게 XRP로 지불하는 Github Action





payid_xrp_action


뭐?


모든 커밋에 대해 기여자에게 XRP로 지불하는 Github Action
이것은 누군가 푸시할 때마다 지불할 금액을 정의할 수 있음을 의미합니다.
저장소에 커밋합니다.
지불을 보낼 주소는 PayIds을 통해 조회됩니다.
커밋 메시지에서.

그것을 설정하는 방법?


예시 워크플로:
name: Pay contributors

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

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

    - 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
      with:
        commit_log: ${{ env.commit_log }}
        wallet_secret: ${{ secrets.PAYID_WALLET_SECRET }}
        amount: 1000000

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'
branding:
  icon: dollar-sign
  color: green
inputs:
  amount:
    description: 'Amount of XRP in drops to pay each PayId found'
    default: 1000000
  commit_log:
    description: 'The commit message(s) to scan for PayIds'
    required: true
  wallet_secret:
    descrption: 'The secret key of the XRP wallet to pay from'
    required: true
  max_payout: 
    description: 'Maximum number of drops to pay out'
    default: 10000000
  environment:
    description: 'Environment to use, TESTNET or LIVENET'
    default: 'TESTNET'
  server:
    description: 'XRP Ledger server to use'
    default: 'test.xrp.xpring.io:50051'
runs:
  using: 'docker'
  image: 'Dockerfile'

이것은 조치가 취할 입력과 실행 방법을 정의합니다. Github 작업은 자바스크립트와 도커의 두 가지 런타임만 지원합니다. 물론 docker를 사용하면 원하는 런타임을 만들 수 있습니다. 위에서 볼 수 있듯이 마지막 줄에서 Dockerfile을 참조합니다.

우리의 경우 Dockerfile은 다음과 같습니다.

FROM python:3.7-slim

WORKDIR /app

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 pypi.python.org -r requirements.txt \
    && apt-get purge -y --auto-remove gcc libgmp3-dev python3-dev

ENTRYPOINT ["python"]

CMD ["/app/pay_contributor.py"]

암호화 루틴을 위한 일부 라이브러리가 필요한 일부 Python 종속성(xpring 라이브러리)을 설치해야 하므로 여러 시스템 패키지 및 컴파일러를 설치해야 합니다. gcc libgmp3-dev python3-dev .

이 모든 것을 종합하면 누구나 사용할 수 있도록 Github Actions 마켓플레이스에 이 작업을 게시할 수 있습니다.



https://github.com/marketplace/actions/automatically-pay-contributors-in-xrp-via-payid

해커톤 출품작



Github 액션 해커톤의 실제 제출물은 다음과 같습니다.

메인테이너 머스트해브 카테고리:





Wacky Wildcards 카테고리의 경우:




비디오를 즐겼기를 바랍니다. 저는 매주 Twitch에서 스트리밍하며 일반적으로 IBMDeveloper Twitch stream schedule에서 확인하거나 Twitter에서 저를 팔로우할 수 있습니다: .

좋은 웹페이지 즐겨찾기