name: Deploy Contract
on:
  pull_request:
    branches:
      - main

jobs:
  cleanup-runs:
    runs-on: ubuntu-latest
    steps:
      - uses: rokroskar/workflow-run-cleanup-action@master
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
    if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"

  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.3.4
      - name: Use Node.js
        uses: actions/setup-node@v2.4.1
        with:
          node-version: '12.x'
      - name: Install dependencies
        run: npm install
      - uses: technote-space/get-diff-action@v5
        id: git_diff
        with:
          SUFFIX_FILTER: |
            .go
            .mod
            .sum
            .sol
      - name: Test contract
        run: |
          sudo make contract-tools
          sudo make test-contract
        if: "env.GIT_DIFF != ''"
