name: Upload Conan Dependencies

on:
  workflow_dispatch:
  pull_request:
    branches:
      - develop
    paths:
      - .github/workflows/upload_conan_deps.yml
      - conanfile.py
      - conan.lock
  push:
    branches:
      - develop
    paths:
      - .github/workflows/upload_conan_deps.yml
      - conanfile.py
      - conan.lock

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

jobs:
  upload-conan-deps:
    name: Build and Upload Conan Deps

    strategy:
      fail-fast: false
      matrix:
        os: [heavy, heavy-arm64]
        container: ['{ "image": "ghcr.io/xrplf/clio-ci:latest" }']
        compiler: ["gcc", "clang"]
        sanitizer_ext: [".asan", ".tsan", ".ubsan", ""]
        build_type: ["Release", "Debug"]
        # libbacktrace doesn't build on arm64 with gcc.tsan
        exclude:
          - os: heavy-arm64
            container: '{ "image": "ghcr.io/xrplf/clio-ci:latest" }'
            compiler: gcc
            sanitizer_ext: .tsan
            build_type: Release
          - os: heavy-arm64
            container: '{ "image": "ghcr.io/xrplf/clio-ci:latest" }'
            compiler: gcc
            sanitizer_ext: .tsan
            build_type: Debug
        include:
          - os: macos15
            container: ""
            compiler: default_apple_clang
            sanitizer_ext: ""
            build_type: Release

    runs-on: ${{ matrix.os }}
    container: ${{ matrix.container != '' && fromJson(matrix.container) || null }}

    env:
      CONAN_PROFILE: ${{ matrix.compiler }}${{ matrix.sanitizer_ext }}

    steps:
      - uses: actions/checkout@v4

      - name: Prepare runner
        uses: ./.github/actions/prepare_runner
        with:
          disable_ccache: true

      - name: Setup conan
        uses: ./.github/actions/setup_conan
        with:
          conan_profile: ${{ env.CONAN_PROFILE }}

      - name: Show conan profile
        run: conan profile show --profile:all ${{ env.CONAN_PROFILE }}

      - name: Run conan and cmake
        uses: ./.github/actions/generate
        with:
          conan_profile: ${{ env.CONAN_PROFILE }}
          conan_cache_hit: "false"
          build_type: ${{ matrix.build_type }}

      - name: Login to Conan
        if: github.event_name != 'pull_request'
        run: conan remote login -p ${{ secrets.CONAN_PASSWORD }} ripple ${{ secrets.CONAN_USERNAME }}

      - name: Upload Conan packages
        if: github.event_name != 'pull_request'
        run: conan upload "*" -r=ripple --confirm
