name: Anchor Build

on:
  schedule:
    - cron: '0 0 1 * *'

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      
      - name: Install dependencies
        run: |
          sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
          export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
          solana -V
          rustc -V
          sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev libssl-dev
          cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
          avm install latest
          avm use latest
          declare -a StringArray=(
            "basics/checking-accounts/anchor"
            "basics/close-account/anchor"
            "basics/counter/anchor"
            "basics/create-account/anchor"
            "basics/hello-solana/anchor"
            "basics/pda-rent-payer/anchor"
            "basics/processing-instructions/anchor"
            "basics/program-derived-addresses/anchor"
            "basics/realloc/anchor"
            "basics/rent/anchor"
            "basics/repository-layout/anchor"
            "basics/transfer-sol/anchor"
            "compression/cnft-vault/anchor"
            "oracles/pyth/anchor"
            "tokens/create-token/anchor"
            "tokens/nft-minter/anchor"
            "tokens/pda-mint-authority/anchor"
            "tokens/spl-token-minter/anchor"
            "tokens/token-2022/basics/anchor"
            "tokens/transfer-tokens/anchor"
            "basics/account-data/anchor"
          )
          for val in "${StringArray[@]}"; do
             echo "Building $val..."
             cd $val
             anchor build
             cd - > /dev/null
          done
        shell: bash
