name: deploy-contracts
on:
  schedule:
    - cron: "*/15 * * * *"
  workflow_dispatch:

jobs:
  deploy-contracts:
    runs-on: ubuntu-latest
    env:
      API_SERVER: https://stacks-node-api.xenon.blockstack.org
      CONTRACT_PRIVATE_KEY: ${{ secrets.CONTRACT_PRIVATE_KEY }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set Node Version
        uses: actions/setup-node@v2-beta
        with:
          node-version: 12.16.1
      - name: Restore lerna cache
        id: lerna-cache
        uses: actions/cache@v2
        with:
          path: |
            node_modules
            */*/node_modules
          key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
      - name: Install monorepo deps
        run: yarn --frozen-lockfile
        if: steps.lerna-cache.outputs.cache-hit != 'true'
      - name: Bootstrap
        run: yarn lerna bootstrap
      - name: Build RPC Client
        run: yarn lerna run build --stream --scope @stacks/rpc-client
      - name: Link packages
        run: yarn lerna link
      - name: Deploy contracts
        run: yarn deploy-contracts