name: Build SimApp
on:
  pull_request:
  merge_group:
  push:
    branches:
      - main
      - release/**
permissions:
  contents: read

concurrency:
  group: ci-${{ github.ref }}-build
  cancel-in-progress: true

jobs:
  build:
    runs-on: depot-ubuntu-22.04-4
    strategy:
      matrix:
        go-arch: ["amd64", "arm64"] # drop 32 bit support for now (and maybe forever)
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
      - name: install aarch64-gcc
        if: matrix.go-arch == 'arm64'
        run: sudo apt-get install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
        ###################
        #### Build App ####
        ###################
      - name: Build
        run: GOARCH=${{ matrix.go-arch }} make build
      - name: Build with legacy app.go
        run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS="legacy" make build
      # TODO re-add with comet v1
      - name: Build with BLS12381
        if: matrix.go-arch == 'amd64'
        run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS="bls12381" make build
      - name: Build with Secp_cgo
        if: matrix.go-arch == 'amd64'
        run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS="secp" make build
      - name: Build with legacy app.go and Secp_cgo
        if: matrix.go-arch == 'amd64'
        run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS="legacy,secp" make build
        ###################
        ## Build Tooling ##
        ###################
      - name: Build Cosmovisor
        run: GOARCH=${{ matrix.go-arch }} make cosmovisor
      - name: Build Confix
        run: GOARCH=${{ matrix.go-arch }} make confix

  build-poa:
    runs-on: depot-ubuntu-22.04-4
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
          cache: true
          cache-dependency-path: enterprise/poa/go.sum
      - uses: technote-space/get-diff-action@v6.1.2
        id: git_diff
        with:
          PATTERNS: |
            enterprise/poa/**/*.go
            enterprise/poa/go.mod
            enterprise/poa/go.sum
            enterprise/poa/Makefile
      - name: Build POA
        if: env.GIT_DIFF
        run: |
          cd enterprise/poa
          make build
      - name: Upload build artifact
        if: env.GIT_DIFF
        uses: actions/upload-artifact@v4
        with:
          name: poa-simd
          path: enterprise/poa/build/simd
