on:
  workflow_dispatch:

name: Build electrs

jobs:

  build-electrs:
    name: Build Electrs
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-18.04, macos-11]
    env:
      ELECTRS_TAG: "v0.9.11"

    steps:
      - name: Check out Electrs
        uses: actions/checkout@master
        with:
          repository: romanz/electrs
          ref: ${{ env.ELECTRS_TAG }}
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo build --release
      - name: downcase runner.os
        run: echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]' | echo RUNNER_OS_LOWER=$(</dev/stdin) >>${GITHUB_ENV}
      - name: Upload libs
        uses: actions/upload-artifact@v2
        with:
          name: electrs_${{ env.RUNNER_OS_LOWER }}_${{ env.ELECTRS_TAG }}
          path: target/release/electrs


  build-electrs-esplora:
    name: Build Electrs Esplora
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-18.04, macos-11]
    env:
      ELECTRS_COMMIT: "a33e97e1a1fc63fa9c20a116bb92579bbf43b254"

    steps:
      - name: Check out Electrs
        uses: actions/checkout@master
        with:
          repository: Blockstream/electrs
          ref: ${{ env.ELECTRS_COMMIT }}
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo build --release
      - name: downcase runner.os
        run: echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]' | echo RUNNER_OS_LOWER=$(</dev/stdin) >>${GITHUB_ENV}
      - name: Upload libs
        uses: actions/upload-artifact@v2
        with:
          name: electrs_${{ env.RUNNER_OS_LOWER }}_esplora_${{ env.ELECTRS_COMMIT }}
          path: target/release/electrs
