on:
  pull_request:
    paths:
      - .github/workflows/ci-aptos-contract.yml
      - target_chains/aptos/contracts/**
  push:
    branches:
      - main

name: Aptos Contract

jobs:
  aptos-tests:
    name: Aptos tests
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: target_chains/aptos/contracts/
    steps:
      - uses: actions/checkout@v3

      - name: Download CLI
        run: wget https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v6.1.1/aptos-cli-6.1.1-Ubuntu-22.04-x86_64.zip

      - name: Unzip CLI
        run: unzip aptos-cli-6.1.1-Ubuntu-22.04-x86_64.zip

      - name: Install movefmt
        run: ./aptos update movefmt

      - name: Check Formatting
        run: ./aptos move fmt
        if: success() || failure()

      - name: Lint
        run: ./aptos move lint --check-test-code --dev
        if: success() || failure()

      - name: Run tests
        run: ./aptos move test
        if: success() || failure()
