name: Static analysis

on:
  push:
    branches:
      - master
      - develop
  pull_request:
  workflow_dispatch:

env:
  PYTEST_ADDOPTS: "--color=yes"

jobs:
  slither:
    name: Slither run
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Fetch history
        run: git fetch

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: '16.x'

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install Dependencies
        # only install dependencies if there was a change in the deps
        # if: steps.yarn-cache.outputs.cache-hit != 'true'
        run: yarn install

      - name: Build
        run: yarn build

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      - name: Install Slither
        run: pip3 install slither-analyzer

      - name: Run analysis
        working-directory: ./packages/contracts
        shell: bash
        run: yarn test:slither
        continue-on-error: false
