# Runs a Jepsen test - cas-register (no nemesis) by default.
#   See inputs for various options.
#   Repo: https://github.com/tendermint/jepsen
#
# If you want to test a new breaking version of Tendermint, you'll need to
# update the Merkleeyes ABCI app and 'merkleeyesUrl' input accordingly. You can
# upload a new tarball to
# https://github.com/tendermint/jepsen/releases/tag/0.2.1.
#
# Manually triggered.
name: jepsen
on:
  workflow_dispatch:
    inputs:
      workload:
        description: 'Test workload to run: (cas-register | set)'
        required: true
        default: 'cas-register'
      nemesis:
        description: 'Nemesis to use: (none | clocks | single-partitions | half-partitions | ring-partitions | split-dup-validators | peekaboo-dup-validators | changing-validators | crash | truncate-tendermint | truncate-merkleeyes)'
        required: true
        default: 'none'
      dupOrSuperByzValidators:
        description: '"--dup-validators" (multiple validators share the same key) and(or) "--super-byzantine-validators" (byzantine validators have just shy of 2/3 the voting weight)'
        required: false
        default: ''
      concurrency:
        description: 'How many workers should we run? Must be an integer and >= 10, optionally followed by n (e.g. 3n) to multiply by the number of nodes.'
        required: true
        default: 10
      timeLimit:
        description: 'Excluding setup and teardown, how long should a test run for, in seconds?'
        required: true
        default: 60
      tendermintUrl:
        description: 'Where to grab the Tendermint tarball (w/ linux/amd64 binary)'
        required: true
        default: 'https://github.com/melekes/katas/releases/download/0.2.0/tendermint.tar.gz'
      merkleeyesUrl:
        description: 'Where to grab the Merkleeyes tarball (w/ linux/amd64 binary)'
        required: true
        default: 'https://github.com/tendermint/jepsen/releases/download/0.2.1/merkleeyes_0.1.7.tar.gz'

jobs:
  jepsen-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the Jepsen repository
        uses: actions/checkout@v2.3.4
        with:
          repository: 'tendermint/jepsen'

      - name: Start a Jepsen cluster in background
        working-directory: docker
        run: ./bin/up --daemon

      - name: Run the test
        run: docker exec -i jepsen-control bash -c 'source /root/.bashrc; cd /jepsen/tendermint; lein run test --nemesis ${{ github.event.inputs.nemesis }} --workload ${{ github.event.inputs.workload }} --concurrency ${{ github.event.inputs.concurrency }} --tendermint-url ${{ github.event.inputs.tendermintUrl }} --merkleeyes-url ${{ github.event.inputs.merkleeyesUrl }} --time-limit ${{ github.event.inputs.timeLimit }} ${{ github.event.inputs.dupOrSuperByzValidators }}'

      - name: Archive results
        uses: actions/upload-artifact@v2
        with:
          name: results
          path: tendermint/store/latest
          retention-days: 3
