⚖️ Register Validator: Mike #339
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Register validator | |
on: | |
issues: | |
types: [ labeled, unlabeled ] | |
concurrency: | |
group: register-validator-${{ github.event.issue.number }} | |
cancel-in-progress: true | |
jobs: | |
resolve-context: | |
if: | | |
!github.event.issue.pull_request && | |
contains(github.event.issue.labels.*.name, 'register-validator') && | |
!contains(github.event.issue.labels.*.name, 'invalid') | |
runs-on: ubuntu-22.04 | |
outputs: | |
network: ${{ fromJson(steps.parse-issue.outputs.jsonString).network }} | |
gentx: ${{ steps.extract-gentx.outputs.gentx }} | |
delegator_addr: ${{ fromJson(steps.parse-issue.outputs.jsonString).delegator_addr }} | |
moniker: ${{ steps.extract-gentx.outputs.moniker }} | |
register-config: ${{ steps.register-config.outputs.config }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Parse issue form content | |
id: parse-issue | |
uses: stefanbuck/github-issue-parser@v3 | |
with: | |
issue-body: ${{ github.event.issue.body }} | |
template-path: .github/ISSUE_TEMPLATE/register-validator.yml | |
- name: Extract gentx | |
id: extract-gentx | |
env: | |
# GENTX_MD needs some sorcery as it is not well extracted from the form issue. | |
GENTX_MD: ${{ fromJson(steps.parse-issue.outputs.jsonString).gentx }} | |
run: | | |
set -eo pipefail | |
gentx=$(echo "$GENTX_MD" | tail -n +2 | sed '$d' | jq -c '.') | |
moniker=$(echo "$gentx" | jq -r '.body.messages[0].description.moniker') | |
echo "moniker=${moniker}" >> $GITHUB_OUTPUT | |
echo "gentx=${gentx}" >> $GITHUB_OUTPUT | |
- name: Get network register config | |
id: register-config | |
run: | | |
set -eo pipefail | |
config=$(cat chains/${{ fromJson(steps.parse-issue.outputs.jsonString).network }}/register-config.json | jq -c '.') | |
echo "config=${config}" >> $GITHUB_OUTPUT | |
check: | |
needs: | |
- resolve-context | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Setup jq | |
run: | | |
sudo apt install -y jq | |
- name: Check gentx | |
id: check-gentx | |
env: | |
GENTX: ${{ needs.resolve-context.outputs.gentx }} | |
run: | | |
set -e | |
echo "🧐 Checking gentx" | |
startTime=$(date --date="${{ fromJson(needs.resolve-context.outputs.register-config).start-date }}" +%s) | |
endTime=$(date --date="${{ fromJson(needs.resolve-context.outputs.register-config).end-date }}" +%s) | |
now=$(date +%s) | |
if [[ $now < $startTime ]]; then | |
echo error='Register process is not open yet for this network.' >> $GITHUB_OUTPUT | |
exit 1 | |
elif [[ $now > $endTime ]]; then | |
echo error='Register process is closed for this network.' >> $GITHUB_OUTPUT | |
exit 1 | |
fi | |
delegationAmount=$(echo "$GENTX" | jq -r '.body.messages[0].value.amount') | |
delegationDenom=$(echo "$GENTX" | jq -r '.body.messages[0].value.denom') | |
if [ "${{ fromJson(needs.resolve-context.outputs.register-config).delegation.amount }}" != "$delegationAmount" ]; then | |
echo error='Invalid delegation amount.' >> $GITHUB_OUTPUT | |
exit 1 | |
elif [ "${{ fromJson(needs.resolve-context.outputs.register-config).delegation.denom }}" != "$delegationDenom" ]; then | |
echo error='Invalid delegation denom.' >> $GITHUB_OUTPUT | |
exit 1 | |
fi | |
echo "👍 gentx seems right." | |
- name: Mark issue invalid | |
if: ${{ failure() }} | |
uses: andymckay/labeler@master | |
with: | |
repo-token: ${{ secrets.OPS_TOKEN }} | |
add-labels: "invalid" | |
- name: Add failure comment | |
if: ${{ failure() }} | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.OPS_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
😢 I couldn't process your request: `${{ steps.check-gentx.outputs.error }}` | |
process: | |
needs: | |
- resolve-context | |
- check | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Import GPG key | |
uses: crazy-max/ghaction-import-gpg@v6 | |
with: | |
gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} | |
git_config_global: true | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
- name: Process gentx | |
id: add-gentx | |
env: | |
GENTX: ${{ needs.resolve-context.outputs.gentx }} | |
DELEGATOR_ADDR: ${{ needs.resolve-context.outputs.delegator_addr }} | |
NODE_HOME: /tmp/node | |
run: | | |
mkdir -p chains/${{ needs.resolve-context.outputs.network }}/gentx | |
echo "$GENTX" > chains/${{ needs.resolve-context.outputs.network }}/gentx/gentx-${{ github.event.issue.number }}.json | |
mkdir -p $NODE_HOME | |
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` init --home $NODE_HOME whatever | |
cp chains/${{ needs.resolve-context.outputs.network }}/genesis.json $NODE_HOME/config/genesis.json | |
delegator_balance="`expr ${{ fromJson(needs.resolve-context.outputs.register-config).delegation.amount }} + 200000`${{ fromJson(needs.resolve-context.outputs.register-config).delegation.denom }}" | |
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` genesis add-genesis-account --home $NODE_HOME $DELEGATOR_ADDR $delegator_balance | |
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME -v $PWD/chains/${{ needs.resolve-context.outputs.network }}/gentx:/gentx axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` genesis collect-gentxs --home $NODE_HOME --gentx-dir /gentx | |
cp $NODE_HOME/config/genesis.json chains/${{ needs.resolve-context.outputs.network }}/genesis.json | |
- name: Prepare commit message | |
id: commit-message | |
run: | | |
type=feat | |
scope="${{ needs.resolve-context.outputs.network }}" | |
description="register validator gentx ${{ needs.resolve-context.outputs.moniker }}" | |
body="Closes #${{ github.event.issue.number }}" | |
line1="$type($scope): $description" | |
line1=$(echo "$line1" | awk -v len=90 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }' ) | |
message="$line1\n\n$body" | |
message="${message//'%'/'%25'}" | |
message="${message//$'\n'/'%0A'}" | |
message="${message//$'\r'/'%0D'}" | |
echo "message=${message}" >> $GITHUB_OUTPUT | |
- name: Create Pull Request | |
id: open-pr | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
commit-message: | | |
${{ steps.commit-message.outputs.message }} | |
committer: ${{ vars.BOT_GIT_COMMITTER_NAME }} <${{ vars.BOT_GIT_COMMITTER_EMAIL }}> | |
author: ${{ vars.BOT_GIT_AUTHOR_NAME }} <${{ vars.BOT_GIT_AUTHOR_EMAIL }}> | |
token: ${{ secrets.OPS_TOKEN }} | |
branch: feat/${{ github.event.issue.number }}-register-${{ needs.resolve-context.outputs.network }} | |
title: '⚖️ Register `${{ needs.resolve-context.outputs.moniker }}` Validator' | |
body: | | |
Register [new validator](${{ github.event.issue.html_url }}) gentx on the ${{ needs.resolve-context.outputs.network }} network. | |
labels: "register-validator,chain: ⛓️ ${{ needs.resolve-context.outputs.network }}" | |
assignees: amimart,ccamel | |
reviewers: amimart,ccamel,tpelliet | |
- name: Link PR | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.OPS_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
😉 Here is the corresponding PR: ${{ steps.open-pr.outputs.pull-request-url }} | |
- name: Mark issue invalid | |
if: ${{ failure() }} | |
uses: andymckay/labeler@master | |
with: | |
repo-token: ${{ secrets.OPS_TOKEN }} | |
add-labels: "invalid" | |
- name: Add failure comment | |
if: ${{ failure() }} | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.OPS_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: 😢 I couldn't process your request... |