name: Conan Packaging

on:
  push:
    branches: ["main"]
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"
      - "v[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
  pull_request:

jobs:
  conan:
    name: conan packaging and publication on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        build_type: ["Release"]
        fpic: ["True", "False"]

    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: install conan
        run: |
          python3 -m pip install --upgrade pip wheel
          python3 -m pip install conan
          conan remote add astro-informatics \
            https://api.bintray.com/conan/astro-informatics/astro-informatics

      - name: create stable or testing package
        shell: bash
        run: |
          if [ "${{ github.ref }}" = "refs/tags/v1.3.0" ]; then
            channel="stable"
          else
            channel="testing"
          fi
          conan create . astro-informatics/${channel} \
              --build missing                         \
              -o so3:fPIC=${{matrix.fpic}}            \
              -s build_type=${{matrix.build_type}}    \

      - name: upload to bintray
        if: ${{ startsWith(github.ref, 'refs/tags') }}
        shell: bash
        env:
          CONAN_PASSWORD: ${{secrets.BINTRAY_TOKEN}}
          CONAN_LOGIN_USERNAME: astroinformaticsci
          CONAN_REMOTE_URL: https://api.bintray.com/conan/astro-informatics/astro-informatics
        run: conan upload so3/1.3.0 -c --all -r=astro-informatics
