📐
GitHub Actions を使って GitHub Issue を電卓にする
GitHub Actions を上手く使うと、GitHub Issue を電卓にすることができます。
以下は、1 + 2 * (3 + 4) / 5 = 3.8
を Issue を使って計算したものです。
これを実現するためには、以下のような workflow を用意すればよいです。
.github/workflows/dentaku.yml
name: Dentaku
on:
issues:
types: opened
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: calculate
run: |
ans=$(echo "${{ github.event.issue.title }}" | bc -l)
echo "::set-output name=ANS::${ans}"
- uses: actions-ecosystem/action-create-comment@v1
with:
github_token: ${{ secrets.github_token }}
body: |
${{ steps.calculate.outputs.ANS }}
bc コマンド を使って文字列から計算を行い、その結果を workflow の機能である set-output コマンド を用いてグローバルに使えるようにするのがポイントです。
普通の電卓に飽きた時に使ってみてください。
Discussion