name: Integration Fixed Price Sale

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always
  SOLANA_VERSION: 1.9.5
  RUST_TOOLCHAIN: stable

jobs:
  changes:
    runs-on: ubuntu-latest
    # Set job outputs to values from filter step
    outputs:
      core: ${{ steps.filter.outputs.core }}
      package: ${{ steps.filter.outputs.package }}
      workflow: ${{ steps.filter.outputs.workflow }}
    steps:
    - uses: actions/checkout@v2
    # For pull requests it's not necessary to checkout the code
    - uses: dorny/paths-filter@v2
      id: filter
      with:
        filters: |
          core:
            - 'core/**'
          package:
            - 'fixed-price-sale/**'
          workflow:
            - '.github/workflows/integration-fixed-price-sale.yml '
  build-and-integration-test-fixed-price-sale:
    runs-on: ubuntu-latest
    env:
      cache_id: program-fixed-price-sale
    needs: changes
    if: ${{ needs.changes.outputs.core == 'true' || needs.changes.outputs.package == 'true' || needs.changes.outputs.workflow == 'true' }}
    steps:
      # Setup Deps
      - uses: actions/checkout@v2
      - uses: ./.github/actions/install-linux-build-deps
      - uses: ./.github/actions/install-solana
        with:
          solana_version: ${{ env.SOLANA_VERSION }}
      - uses: ./.github/actions/install-rust
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}

      # Restore Cache from previous build/test
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            ./rust/target
          key:
            ${{ env.cache_id }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{
            env.RUSTC_HASH }}

      # Build Rust Programs
      - uses: ./.github/actions/build-fixed-price-sale
      - uses: ./.github/actions/build-token-metadata

      # Install JS SDK deps
      - uses: ./.github/actions/yarn-install-and-build
        with:
          cache_id: sdk-fixed-price-sale
          working_dir: ./fixed-price-sale/js

      # Run integration test
      - name: start-local-test-validator
        working-directory: ./fixed-price-sale/js
        run: DEBUG=amman* yarn amman:start

      - name: integration-test-fixed-price-sale-program
        id: run_integration_test
        working-directory: ./fixed-price-sale/js
        run: DEBUG=mpl* yarn test
