name: "Builds and tests"
on:
  pull_request:
  push:
    branches:
      - main
    tags:
      - v*
env:
  # Shared variables
  CI_TASK_DIR: ${{ github.workspace }}
  CI_ARTIFACTS_DIR: ${{ github.workspace }}/artifacts
  EXPECTED_TENSORFLOW_VERSION: "TensorFlow: v2.9.1-11-gf8242ebc005"
  STT_PROD_MODEL: https://github.com/coqui-ai/STT/releases/download/v0.10.0-alpha.7/output_graph.tflite
  BAZEL_CACHE: ${{ secrets.BAZEL_CACHE }}

  # macOS specific
  MACOSX_DEPLOYMENT_TARGET: "10.10"
  CI_NODE_MODULES_NTH: 1

  # Windows specific
  CI_MSYS_VERSION: MSYS_NT-10.0-17763
defaults:
  run:
    shell: bash
jobs:
  create-release:
    name: "Create release for tag"
    runs-on: ubuntu-20.04
    outputs:
      release-tag: ${{ steps.check-version.outputs.release-tag }}
      is-prerelease: ${{ steps.check-version.outputs.is-prerelease }}
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Check VERSION file matches pushed Git tag and check if prerelease
        id: check-version
        run: |
          set -xe
          if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
            echo "Should never happen (this job only runs on tag pushes)"
            exit 1
          fi

          VERSION="v$(cat VERSION)"
          if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
            echo "Pushed tag does not match VERSION file. Aborting release."
            exit 1
          fi

          # Tag for this release (version with leading v)
          tag=$(echo "${{ github.ref }}" | sed -e 's|^refs/tags/||')
          echo "release-tag=${tag}" >> $GITHUB_OUTPUT

          # Version without leading v
          version=$(cat VERSION)
          echo "version=${version}" >> $GITHUB_OUTPUT

          # Is this a prerelease or not?
          pip install semver
          cat <<EOF | python - "${{ github.ref }}"
          import sys
          import os
          import semver
          ref = sys.argv[1]
          prefix = "refs/tags/v"
          assert ref.startswith(prefix)
          parsed = semver.parse_version_info(ref[len(prefix):])
          with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
              print("is-prerelease={}".format("true" if parsed.prerelease else "false"), file=fh)
              print("release-notes-file={}".format("" if parsed.prerelease else "RELEASE_NOTES.md"), file=fh)
          EOF
      - uses: softprops/action-gh-release@v1
        with:
          body_path: ${{ steps.check-version.outputs.release-notes-file }}
          prerelease: ${{ steps.check-version.outputs.is-prerelease }}
          name: ${{ format('Coqui STT {0}', steps.check-version.outputs.version) }}
  # Linux jobs
  swig_Windows_crosscompiled:
    name: "Lin|Build SWIG for Windows"
    runs-on: ubuntu-20.04
    env:
      swig_hash: "90cdbee6a69d13b39d734083b9f91069533b0d7b"
    steps:
      - uses: actions/checkout@v3
        with:
          repository: "swig/swig"
          ref: ${{ env.swig_hash }}
      - run: |
          mkdir -p build-static/
      - uses: actions/cache@v3
        id: swig-build-cache
        with:
          path: build-static/
          key: swig-win-3-${{ env.swig_hash }}
      - run: |
          sudo apt-get install -y --no-install-recommends autoconf automake bison build-essential mingw-w64
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          curl -sSL https://github.com/coqui-ai/STT/releases/download/v0.10.0-alpha.7/pcre-8.43.tar.gz > pcre-8.43.tar.gz
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          ./Tools/pcre-build.sh --host=x86_64-w64-mingw32
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          sh autogen.sh
          CFLAGS="-static-libgcc -static-libstdc++" \
          CXXFLAGS="-static-libgcc -static-libstdc++" \
          ./configure \
            --host=x86_64-w64-mingw32 \
            --prefix=`pwd`/build-static/ \
            --program-prefix=ds-
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make -j
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make install
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}
          path: ${{ github.workspace }}/build-static/
  swig_Linux:
    name: "Lin|Build SWIG"
    runs-on: ubuntu-20.04
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    env:
      swig_hash: "90cdbee6a69d13b39d734083b9f91069533b0d7b"
    steps:
      - uses: actions/checkout@v3
        with:
          repository: "swig/swig"
          ref: ${{ env.swig_hash }}
      - run: |
          mkdir -p build-static/
      - uses: actions/cache@v3
        id: swig-build-cache
        with:
          path: build-static/
          key: swig-4-${{ runner.os }}-${{ env.swig_hash }}
      - run: |
          curl -sSL https://github.com/coqui-ai/STT/releases/download/v0.10.0-alpha.7/pcre-8.43.tar.gz > pcre-8.43.tar.gz
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          ./Tools/pcre-build.sh
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          sh autogen.sh
          ./configure \
            --prefix=${{ github.workspace }}/build-static/ \
            --program-prefix=ds-
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make -j
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make install
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}
          path: ${{ github.workspace }}/build-static/
  libsox3_Linux:
    name: "Lin|Build libsox3"
    runs-on: ubuntu-20.04
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    steps:
      - run: |
          curl -sSL https://github.com/coqui-ai/STT/releases/download/v0.10.0-alpha.7/sox-14.4.2.tar.bz2 | tar xjf -
      - run: |
          mkdir -p sox-build/
      - uses: actions/cache@v3
        id: sox-build-cache
        with:
          path: sox-build/
          key: sox-1-${{ runner.os }}-${{ env.sox_hash }}
      - name: Configure
        run: |
          cd sox-14.4.2
          ./configure \
            --with-dyn-default --enable-dl-sndfile --enable-dl-amrnb \
            --without-magic --without-png --without-ladspa --without-mad \
            --without-id3tag --without-lame --without-twolame \
            --without-libltdl --disable-openmp --disable-dependency-tracking \
            --with-gsm=no --with-lpc10=no --with-oss=no \
            --prefix=${{ github.workspace }}/sox-build/
        if: steps.sox-build-cache.outputs.cache-hit != 'true'
      - name: Make
        run: |
          cd sox-14.4.2
          make -j
        if: steps.sox-build-cache.outputs.cache-hit != 'true'
      - name: Make install
        run: |
          cd sox-14.4.2
          make install
        if: steps.sox-build-cache.outputs.cache-hit != 'true'
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}
          path: ${{ github.workspace }}/sox-build/
  build-ctc-decoder-Linux:
    name: "Lin|Build CTC decoder Python package"
    needs: [ swig_Linux ]
    runs-on: ubuntu-20.04
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - name: Make decoder package
        run: |
          # Setup venv
          /opt/_internal/cpython-${{ matrix.python-version }}*/bin/python -m venv /tmp/venv-${{ matrix.python-version }}
          source /tmp/venv-${{ matrix.python-version }}/bin/activate

          # Check versions
          python --version
          pip --version

          # Build decoder package
          NUMPY_BUILD_VERSION="${{ steps.get_numpy.outputs.build_version }}" \
          NUMPY_DEP_VERSION="${{ steps.get_numpy.outputs.dep_version }}" \
          make -C native_client/ctcdecode/ \
            NUM_PROCESSES=$(nproc) \
            bindings
      - name: Auditwheel repair
        run: |
          auditwheel repair native_client/ctcdecode/dist/*.whl
      - uses: actions/upload-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.python-version }}.whl"
          path: ${{ github.workspace }}/wheelhouse/*.whl
  train-test-model-Linux:
    name: "Lin|Train a test model"
    needs: [ "build-ctc-decoder-Linux" ]
    runs-on: ubuntu-20.04
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-3.7.whl"
      - run: |
          python --version
          pip --version
      - run: |
          pip install --upgrade pip setuptools wheel
      - run: |
          pip install coqui_stt_ctcdecoder-*-cp37-cp37m-*_x86_64.whl
          DS_NODECODER=y pip install --upgrade .
      - run: |
          # Easier to rename to that we can exercize the LDC93S1 importer code to
          # generate the CSV file.
          echo "Moving ${{ matrix.samplerate }} to LDC93S1.wav"
          mv data/smoke_test/LDC93S1_pcms16le_1_${{ matrix.samplerate}}.wav data/smoke_test/LDC93S1.wav

          ./bin/run-ci-ldc93s1_new.sh 249 ${{ matrix.samplerate}}
          ./bin/run-ci-ldc93s1_tflite.sh ${{ matrix.samplerate}}
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          ./convert_graphdef_memmapped_format --in_graph=/tmp/train/output_graph.pb --out_graph=/tmp/train/output_graph.pbmm
      - run: |
          tar -cf - \
            -C /tmp/ckpt/ . \
            | xz -9 -T0 > /tmp/checkpoint.tar.xz
      - run: |
          mkdir -p ${{ github.workspace }}/tmp/
          cp /tmp/train*/output_graph.* /tmp/checkpoint.tar.xz ${{ github.workspace }}/tmp/
      - run: |
          ls -hal /tmp/ ${{ github.workspace }}/tmp/
      - uses: actions/upload-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ github.workspace }}/tmp/output_graph.tflite
      - uses: actions/upload-artifact@v3
        with:
          name: "test-checkpoint.${{ matrix.samplerate }}.zip"
          path: ${{ github.workspace }}/tmp/checkpoint.tar.xz
  build-lib-Linux:
    name: "Lin|Build libstt+client"
    runs-on: ubuntu-20.04
    needs: [libsox3_Linux]
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - name: Install dependencies
        run: |
          apt-get update
          apt-get install -y --no-install-recommends xz-utils zip liblzma-dev libbz2-dev
      - name: Setup venv
        run: |
          /opt/python/cp37-cp37m/bin/python -m venv /tmp/venv
          echo "/tmp/venv/bin" >> $GITHUB_PATH
      - uses: actions/download-artifact@v3
        with:
          name: "libsox3_Linux"
          path: ${{ github.workspace }}/sox-build/
      - run: ./ci_scripts/tf-setup.sh
      - run: ./ci_scripts/host-build.sh
      - run: ./ci_scripts/package.sh
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.Linux.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.Linux.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
  build-python-Linux:
    name: "Lin|Build Python bindings"
    runs-on: ubuntu-20.04
    needs: [build-lib-Linux, swig_Linux]
    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Linux.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - name: Install dependencies
        run: |
          apt-get update
          apt-get install -y --no-install-recommends xz-utils liblzma-dev libbz2-dev
      - name: Extract native_client.tar.xz
        run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - name: Setup venv
        run: |
          /opt/_internal/cpython-${{ matrix.python-version }}*/bin/python -m venv /tmp/venv-${{ matrix.python-version }}
          echo "/tmp/venv-${{ matrix.python-version }}/bin" >> $GITHUB_PATH
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - uses: ./.github/actions/python-build
        with:
          numpy_build: "${{ steps.get_numpy.outputs.build_version }}"
          numpy_dep: "${{ steps.get_numpy.outputs.dep_version }}"
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-Linux.whl"
          path: ${{ github.workspace }}/native_client/python/dist/*.whl
  build-nodejs-Linux:
    name: "Lin|Build NodeJS and ElectronJS"
    runs-on: ubuntu-20.04
    needs: [ build-lib-Linux, swig_Linux ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Linux.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/cache@v3
        id: node-headers-cache
        with:
          path: native_client/javascript/headers/nodejs/
          key: node-headers-12.7.0_17.0.1
      - uses: actions/cache@v3
        id: electron-headers-cache
        with:
          path: native_client/javascript/headers/electronjs/
          key: electron-headers-12.0.0_16.0.0
      - uses: ./.github/actions/node-build
        with:
          nodejs_versions: "12.7.0 13.0.0 14.0.0 15.0.0 16.0.0 17.0.1"
          electronjs_versions: "12.0.0 13.0.0 14.0.0 15.0.0 16.0.0"
      - uses: actions/upload-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_amd64.tar.gz"
          path: ${{ github.workspace }}/native_client/javascript/wrapper.tar.gz
      - uses: actions/upload-artifact@v3
        with:
          name: "stt_intermediate-tflite-Linux.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  build-wasm:
    name: "Wasm|Build libstt"
    runs-on: ubuntu-20.04
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install dependencies
        run: |
          apt-get update
          apt-get install -y --no-install-recommends xz-utils zip liblzma-dev libbz2-dev
      - name: Setup venv
        run: |
          /opt/python/cp37-cp37m/bin/python -m venv /tmp/venv
          echo "/tmp/venv/bin" >> $GITHUB_PATH
      - run: ./ci_scripts/tf-setup.sh
      - run: ./ci_scripts/wasm-build.sh
      - run: ./ci_scripts/wasm-package.sh
      - run: BAZEL_WASM_EXTRA_FLAGS="--//native_client:wasm_emit=es6" ./ci_scripts/wasm-build.sh
      - run: make -C native_client/wasm clean pack
        shell: bash
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.wasm.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.wasm.es6.tgz"
          path: ${{ github.workspace }}/native_client/wasm/stt-wasm-*.tgz
  test-wasm:
    name: "Wasm|Test libstt"
    runs-on: ubuntu-20.04
    needs: [build-wasm]
    container:
      image: quay.io/pypa/manylinux_2_24_x86_64:2021-12-05-142ef77
      volumes:
        - ${{ github.workspace }}:${{ github.workspace }}
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - uses: actions/download-artifact@v3
        with:
          name: "libstt.tflite.wasm.es6.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - run: make -C native_client/wasm/test clean test
        shell: bash
  test-cpp-Linux:
    name: "Lin|Test C++ binary"
    runs-on: ubuntu-20.04
    needs: [ build-lib-Linux, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Linux.tar.xz"
          path: ${{ env.CI_TMP_DIR }}
      - run: |
          cd ${{ env.CI_TMP_DIR }}
          mkdir ds && cd ds && tar xf ../native_client.tar.xz
          ls -lh
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: ./.github/actions/run-tests
        with:
          runtime: "cpp"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-py-Linux:
    name: "Lin|Test Python bindings"
    runs-on: ubuntu-20.04
    needs: [ build-python-Linux, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - run: |
          sudo apt-get install -y --no-install-recommends sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-Linux.whl"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          pip3 install --only-binary :all: --upgrade ${{ env.CI_TMP_DIR }}/stt*.whl
      - uses: ./.github/actions/run-tests
        with:
          runtime: "python"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-evaluate-export:
    name: "Lin|Test evaluate_export"
    runs-on: ubuntu-20.04
    needs: [ build-python-Linux, train-test-model-Linux, build-ctc-decoder-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        python-version: ["3.7"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-Linux.whl"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.python-version }}.whl"
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
      - run: |
          python -m pip install --only-binary :all: --upgrade ${{ env.CI_TMP_DIR }}/stt*.whl
      - run: |
          python -m pip install coqui_stt_ctcdecoder-*.whl
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 libopusfile0
      - run: |
          ./ci_scripts/evaluate-export-test.sh ${{ matrix.samplerate }}
  test-nodejs-Linux:
    name: "Lin|Test NodeJS bindings"
    runs-on: ubuntu-20.04
    needs: [ build-nodejs-Linux, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 14, 16, 17]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - run: |
          sudo apt-get install -y --no-install-recommends sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-Linux.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ~/.npm/
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          ls -hal node_modules/stt* node_modules/.bin/
      - uses: ./.github/actions/run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs-Linux:
    name: "Lin|Test ElectronJS bindings"
    runs-on: ubuntu-20.04
    needs: [ build-nodejs-Linux, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 13.0.0, 14.0.0, 15.0.0, 16.0.0]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - run: |
          sudo apt-get install -y --no-install-recommends sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-Linux.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ~/.npm/
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  python-notebooks-tests:
    name: "Lin|Python notebook tests"
    needs: ["build-ctc-decoder-Linux"]
    runs-on: ubuntu-20.04
    if: ${{ github.event_name == 'pull_request' }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-3.7.whl"
      - run: |
          sudo apt-get install -y --no-install-recommends libopusfile0 libopus-dev libopusfile-dev
      - run: |
          python --version
          python -m pip --version
      - run: |
          python -m pip install --upgrade pip setuptools wheel jupyter
      - run: |
          python -m pip install coqui_stt_ctcdecoder*.whl
          DS_NODECODER=y python -m pip install --upgrade .
      - name: Run python notebooks
        run: |
          ./ci_scripts/notebook-tests.sh
  training-basic-tests:
    name: "Lin|Basic training tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - name: Run basic training tests
        run: |
          set -ex
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # Run twice to test preprocessed features
          time ./bin/run-ci-ldc93s1_new.sh 249 "${{ matrix.samplerate }}"
          time ./bin/run-ci-ldc93s1_new.sh 1 "${{ matrix.samplerate }}"
          time ./bin/run-ci-ldc93s1_tflite.sh "${{ matrix.samplerate }}"

          tar -cf - \
              -C /tmp/ckpt/ . \
              | ${XZ} > ${CI_ARTIFACTS_DIR}/checkpoint.tar.xz

          cp /tmp/train/output_graph.pb ${CI_ARTIFACTS_DIR}
          cp /tmp/train_tflite/output_graph.tflite ${CI_ARTIFACTS_DIR}

          /tmp/convert_graphdef_memmapped_format \
            --in_graph=/tmp/train/output_graph.pb \
            --out_graph=/tmp/train/output_graph.pbmm
          cp /tmp/train/output_graph.pbmm ${CI_ARTIFACTS_DIR}

          time ./bin/run-ci-ldc93s1_checkpoint.sh
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}-output_graph.pb
          path: ${{ github.workspace }}/artifacts/output_graph.pb
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}-output_graph.pbmm
          path: ${{ github.workspace }}/artifacts/output_graph.pbmm
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}-output_graph.tflite
          path: ${{ github.workspace }}/artifacts/output_graph.tflite
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}-checkpoint.tar.xz
          path: ${{ github.workspace }}/artifacts/checkpoint.tar.xz
  training-extra-tests:
    name: "Lin|Extra training tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 libopusfile0 libvorbis-dev sox
      - name: Run tests
        run: |
          set -xe
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # Test --metrics_files training argument
          time ./bin/run-ci-ldc93s1_new_metrics.sh 2 "${{ matrix.samplerate }}"

          # Training graph inference
          time ./bin/run-ci-ldc93s1_singleshotinference.sh

          # Augmentations
          time ./bin/run-ci-sample_augmentations.sh

          # Test Ogg/Vorbis input
          time ./bin/run-ci-ldc93s1-vorbis.sh --epochs 1

          # Test WebDataset input
          time ./bin/run-ci-ldc93s1-webdataset.sh --epochs 1

          # Test FLAC input
          time ./bin/run-ci-ldc93s1-flac.sh --epochs 1

          # Test LM opt
          time ./bin/run-ci-lm-opt.sh
  training-sdb-tests:
    name: "Lin|SDB training tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 sox
      - name: Run tests
        run: |
          set -xe
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # Testing single SDB source
          time ./bin/run-ci-ldc93s1_new_sdb.sh 220 "${{ matrix.samplerate }}"

          # Testing interleaved source (SDB+CSV combination) - run twice to test preprocessed features
          time ./bin/run-ci-ldc93s1_new_sdb_csv.sh 109 "${{ matrix.samplerate }}"
          time ./bin/run-ci-ldc93s1_new_sdb_csv.sh 1 "${{ matrix.samplerate }}"

          # Test resuming from checkpoints created above
          # SDB, resuming from checkpoint
          time ./bin/run-ci-ldc93s1_checkpoint_sdb.sh
  training-bytes-tests:
    name: "Lin|Bytes output mode training tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 sox
      - name: Run tests
        run: |
          set -xe
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # Test training with bytes output mode
          time ./bin/run-ci-ldc93s1_new_bytes.sh 200 "${{ matrix.samplerate }}"
          time ./bin/run-ci-ldc93s1_new_bytes_tflite.sh "${{ matrix.samplerate }}"

          # Bytes output mode, resuming from checkpoint
          time ./bin/run-ci-ldc93s1_checkpoint_bytes.sh
  training-python-tests:
    name: "Lin|Python API training tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 sox
      - name: Run tests
        run: |
          set -xe
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # Training with args set via initialize_globals_from_args()
          time python ./bin/run-ldc93s1.py
  training-transcribe-tests:
    name: "Lin|Transcribe module tests"
    runs-on: ubuntu-20.04
    needs: [build-ctc-decoder-Linux, training-basic-tests]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
        pyver: ["3.7"]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver }}
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-Linux-${{ matrix.pyver }}.whl"
      - uses: actions/download-artifact@v3
        with:
          name: "training-basic-tests-checkpoint.tar.xz"
      - name: Extract training checkpoint
        run: |
          ls -lh
          mkdir -p /tmp/ckpt
          tar xvf checkpoint.tar.xz -C /tmp/ckpt
          ls -lh /tmp/ckpt
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.linux.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          mv convert_graphdef_memmapped_format /tmp
      - run: |
          mkdir -p ${CI_ARTIFACTS_DIR} || true
      - run: |
          sudo apt-get install -y --no-install-recommends libopus0 sox
      - name: Run tests
        run: |
          set -xe
          python -m pip install ".[transcribe]"
          python -m pip install coqui_stt_ctcdecoder-*.whl

          source ./ci_scripts/train-tests-setup.sh ${{ matrix.samplerate }}

          # transcribe module
          time python -m coqui_stt_training.transcribe \
              --checkpoint_dir "/tmp/ckpt" \
              --src "data/smoke_test/LDC93S1.wav" \
              --dst ${CI_ARTIFACTS_DIR}/transcribe.log \
              --scorer_path "data/smoke_test/pruned_lm.scorer"

          mkdir /tmp/transcribe_dir
          cp data/smoke_test/LDC93S1.wav /tmp/transcribe_dir
          time python -m coqui_stt_training.transcribe \
             --checkpoint_dir "/tmp/ckpt" \
             --src "/tmp/transcribe_dir/" \
             --scorer_path "data/smoke_test/pruned_lm.scorer"

          for i in /tmp/transcribe_dir/*.tlog; do echo $i; cat $i; echo; done
  twine-upload-training:
    name: "Upload STT training packages to PyPI"
    runs-on: ubuntu-20.04
    needs: [create-release]
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Update pip and install deps
        run: |
          python -m pip install -U pip setuptools twine build
      - run: |
          python -m build
      - name: Setup PyPI config
        run: |
          cat << EOF > ~/.pypirc
          [pypi]
          username=__token__
          password=${{ secrets.PYPI_TRAINING_TOKEN }}
          EOF
      - run: |
          twine upload --repository pypi dist/*
      - name: Upload artifacts to GitHub release
        uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "dist/*.whl"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
  twine-upload-stt:
    name: "Upload STT packages to PyPI"
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    needs: [create-release, build-python-Linux, build-python-macOS, build-python-Windows, build-python-LinuxArmv7, build-python-LinuxAarch64]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Update pip and install twine
        run: |
          python -m pip install -U pip
          python -m pip install -U twine
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.6.8-macOS.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.7.9-macOS.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.8.9-macOS.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.9.4-macOS.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.10.1-macOS.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.6.8-Windows.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.7.9-Windows.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.8.8-Windows.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.9.4-Windows.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.10.0-Windows.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.6-Linux.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.7-Linux.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.8-Linux.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.9-Linux.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.10-Linux.whl
      - name: Setup PyPI config
        run: |
          cat << EOF > ~/.pypirc
          [pypi]
          username=__token__
          password=${{ secrets.PYPI_STT_TOKEN }}
          EOF
      - run: |
          twine upload --repository pypi *.whl
      # PyPI only supports ARM wheels built on manylinux images, but those aren't
      # ready for use yet, so we upload our wheels to the corresponding release
      # for this tag.
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.7-armv7.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.7-aarch64.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.9-armv7.whl
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite-3.9-aarch64.whl
      - name: Upload artifacts to GitHub release
        uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.whl"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
  upload-nc-release-assets:
    name: "Upload native client artifacts to release assets"
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    needs: [create-release, build-lib-Windows, build-lib-Linux, build-universal-lib-macOS, build-lib-LinuxAarch64, build-lib-LinuxArmv7]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/download-artifact@v3
        with:
          name: libstt.tflite.Linux.zip
      - run: mv libstt.zip libstt.tflite.Linux.zip
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.Linux.tar.xz
      - run: mv native_client.tar.xz native_client.tflite.Linux.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: libstt.tflite.macOS.zip
      - run: mv libstt.zip libstt.tflite.macOS.zip
      - uses: actions/download-artifact@v3
        with:
          name: libstt.tflite.wasm.zip
      - run: mv libstt.zip libstt.tflite.wasm.zip
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.macOS.tar.xz
      - run: mv native_client.tar.xz native_client.tflite.macOS.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: libstt.tflite.Windows.zip
      - run: mv libstt.zip libstt.tflite.Windows.zip
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.Windows.tar.xz
      - run: mv native_client.tar.xz native_client.tflite.Windows.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.linux.armv7.tar.xz
      - run: mv native_client.tar.xz native_client.tflite.linux.armv7.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.linux.aarch64.tar.xz
      - run: mv native_client.tar.xz native_client.tflite.linux.aarch64.tar.xz
      - run: ls -lh
      - uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.tar.xz"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
      - uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.zip"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
  docker-build:
    name: "Build Dockerfile.build image"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - name: Check VERSION matches Git tag and compute Docker tag
        id: compute-tag
        run: |
          if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
            # PR build
            echo "tag=dev" >> $GITHUB_OUTPUT
          else
            VERSION="v$(cat VERSION)"
            if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
              echo "Pushed tag does not match VERSION file. Aborting push."
              exit 1
            fi
            echo "tag=${VERSION}" >> $GITHUB_OUTPUT
          fi
      - name: Build
        run: |
          DOCKER_TAG="${{ steps.compute-tag.outputs.tag }}"
          docker build -f Dockerfile.build . -t ghcr.io/coqui-ai/stt-build:latest -t "ghcr.io/coqui-ai/stt-build:${DOCKER_TAG}"
  docker-publish:
    name: "Build and publish Docker training image to GHCR"
    runs-on: ubuntu-20.04
    needs: [upload-nc-release-assets]
    if: always()
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - name: Log in to the Container registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Check VERSION matches Git tag and compute Docker tag
        id: compute-tag
        run: |
          set -ex
          if [[ "${{ github.ref }}" = "refs/heads/main" ]]; then
            # Push to main
            tags="main ${{ github.sha }}"
          elif [[ "${{ startsWith(github.ref, 'refs/tags/') }}" != "true" ]]; then
            # PR build
            tags="dev"
          else
            VERSION="v$(cat VERSION)"
            if [[ "${{ github.ref }}" != "refs/tags/${VERSION}" ]]; then
              echo "Pushed tag does not match VERSION file. Aborting push."
              exit 1
            fi
            tags="${VERSION} latest ${{ github.sha }}"
          fi
          echo "tags=${tags}" >> $GITHUB_OUTPUT
      - name: Build
        run: |
          set -ex
          declare -a tag_args=()
          for tag in ${{ steps.compute-tag.outputs.tags }}; do
            tag_args+=("-t" "ghcr.io/coqui-ai/stt-train:${tag}")
          done
          docker build -f Dockerfile.train . ${tag_args[@]}
      - name: Push
        run: |
          set -ex
          for tag in ${{ steps.compute-tag.outputs.tags }}; do
            docker push ghcr.io/coqui-ai/stt-train:${tag}
          done
        if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
  twine-upload-decoder:
    name: "Upload coqui_stt_ctcdecoder packages to PyPI"
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    needs: [create-release, build-ctc-decoder-Linux, build-ctc-decoder-macos, build-ctc-decoder-windows]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Update pip and install twine
        run: |
          python -m pip install -U pip
          python -m pip install -U twine
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-Linux-3.6.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-Linux-3.7.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-Linux-3.8.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-Linux-3.9.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-Linux-3.10.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-macOS-3.6.8.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-macOS-3.7.9.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-macOS-3.8.9.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-macOS-3.9.4.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-macOS-3.10.1.whl
      - uses: actions/download-artifact@v3
        with:
          name: coqui_stt_ctcdecoder-windows-test.whl
      - name: Setup PyPI config
        run: |
          cat << EOF > ~/.pypirc
          [pypi]
          username=__token__
          password=${{ secrets.PYPI_DECODER_TOKEN }}
          EOF
      - run: |
          twine upload --repository pypi *.whl
      - name: Upload artifacts to GitHub release
        uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.whl"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
  python-notebooks-tests-production:
    name: "Lin|Python notebook tests with PyPI package"
    needs: [twine-upload-decoder]
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    steps:
      - name: Wait for PyPI index to refresh
        run: |
          sleep 60
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - run: |
          sudo apt-get install -y --no-install-recommends libopusfile0 libopus-dev libopusfile-dev
      - run: |
          python -m pip install -U pip setuptools wheel jupyter
          python -m pip install .
      - name: Run python notebooks
        run: |
          ./ci_scripts/notebook-tests.sh
  npmjs-publish:
    name: "Upload STT packages to npmjs.com"
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    needs: [create-release, repackage-nodejs-allplatforms, build-wasm]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 12
          registry-url: 'https://registry.npmjs.org'
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Compute tag for npm from git tag
        id: compute-npm-tag
        run: |
          if [ "${{ needs.create-release.outputs.is-prerelease }}" = "true" ]; then
            echo "npm-tag=prerelease" >> $GITHUB_OUTPUT
          else
            echo "npm-tag=latest" >> $GITHUB_OUTPUT
          fi
      - uses: actions/download-artifact@v3
        with:
          name: stt-tflite.tgz
          path: ${{ github.workspace }}/
      - uses: actions/download-artifact@v3
        with:
          name: libstt.tflite.wasm.es6.tgz
          path: ${{ github.workspace }}/
      - run: |
          for pkg in ${{ github.workspace }}/stt-*.tgz; do
            npm publish --access=public --verbose $pkg --tag ${{ steps.compute-npm-tag.outputs.npm-tag }}
          done
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Upload artifacts to GitHub release
        uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.tgz"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
  # macOS jobs
  swig_macOS:
    name: "Mac|Build SWIG"
    runs-on: macos-12
    env:
      swig_hash: "90cdbee6a69d13b39d734083b9f91069533b0d7b"
    steps:
      - uses: actions/checkout@v3
        with:
          repository: "swig/swig"
          ref: ${{ env.swig_hash }}
      - run: |
          mkdir -p build-static/
      - uses: actions/cache@v3
        id: swig-build-cache
        with:
          path: build-static/
          key: swig-${{ runner.os }}-${{ env.swig_hash }}
      - run: |
          brew install automake
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          curl -sSL https://github.com/coqui-ai/STT/releases/download/v0.10.0-alpha.7/pcre-8.43.tar.gz > pcre-8.43.tar.gz
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          ./Tools/pcre-build.sh
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          sh autogen.sh
          ./configure \
            --prefix=${{ github.workspace }}/build-static/ \
            --program-prefix=ds-
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make -j
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - run: |
          make install
        if: steps.swig-build-cache.outputs.cache-hit != 'true'
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ github.job }}
          path: ${{ github.workspace }}/build-static/
  build-ctc-decoder-macos:
    name: "Mac|Build CTC decoder Python package"
    needs: [ swig_macOS ]
    runs-on: macos-12
    strategy:
      matrix:
        python-version: [3.6.8, 3.7.9, 3.8.9, 3.9.4, 3.10.1]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: ./.github/actions/install-python-upstream
        with:
          version: ${{ matrix.python-version }}
      - run: |
          python --version
          pip --version
      - uses: actions/download-artifact@v3
        with:
          name: "swig_macOS"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - name: Make decoder package
        run: |
          NUMPY_BUILD_VERSION="${{ steps.get_numpy.outputs.build_version }}" \
          NUMPY_DEP_VERSION="${{ steps.get_numpy.outputs.dep_version }}" \
          make -C native_client/ctcdecode/ \
            NUM_PROCESSES=$(sysctl hw.ncpu |cut -d' ' -f2) \
            bindings
      - uses: actions/upload-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-macOS-${{ matrix.python-version }}.whl"
          path: ${{ github.workspace }}/native_client/ctcdecode/dist/*.whl
      - run: |
          make -C native_client/ctcdecode clean-keep-third-party
  train-test-model-macOS:
    name: "Mac|Train a test model"
    needs: [ "build-ctc-decoder-macos" ]
    runs-on: macos-12
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        samplerate: ["8000", "16000"]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - uses: actions/download-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-macOS-3.7.9.whl"
      - run: |
          python --version
          python -m pip --version
      - run: |
          python -m pip install -U pip setuptools wheel
      - run: |
          python -m pip install coqui_stt_ctcdecoder-*.whl
          DS_NODECODER=y python -m pip install --upgrade .
      - run: |
          # Easier to rename to that we can exercize the LDC93S1 importer code to
          # generate the CSV file.
          echo "Moving ${{ matrix.samplerate }} to LDC93S1.wav"
          mv data/smoke_test/LDC93S1_pcms16le_1_${{ matrix.samplerate}}.wav data/smoke_test/LDC93S1.wav

          ./bin/run-ci-ldc93s1_new.sh 249 ${{ matrix.samplerate}}
          ./bin/run-ci-ldc93s1_tflite.sh ${{ matrix.samplerate}}
      - run: |
          wget -O temp.zip https://github.com/coqui-ai/STT/releases/download/v0.9.3/convert_graphdef_memmapped_format.macOS.amd64.zip
          unzip temp.zip
          rm temp.zip
          chmod +x convert_graphdef_memmapped_format
          ./convert_graphdef_memmapped_format --in_graph=/tmp/train/output_graph.pb --out_graph=/tmp/train/output_graph.pbmm
      - run: |
          tar -cf - \
            -C /tmp/ckpt/ . \
            | xz -9 -T0 > /tmp/checkpoint.tar.xz
      - run: |
          mkdir -p ${{ github.workspace }}/tmp/
          cp /tmp/train*/output_graph.* /tmp/checkpoint.tar.xz ${{ github.workspace }}/tmp/
      - run: |
          ls -hal /tmp/ ${{ github.workspace }}/tmp/
      - uses: actions/upload-artifact@v3
        with:
          name: "test-model.mac.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ github.workspace }}/tmp/output_graph.tflite
      - uses: actions/upload-artifact@v3
        with:
          name: "test-checkpoint.${{ matrix.samplerate }}.zip"
          path: ${{ github.workspace }}/tmp/checkpoint.tar.xz
  build-lib-macOS:
    name: "Mac|Build libstt+client"
    runs-on: macos-12
    strategy:
      matrix:
        arch: ["x86_64", "arm64"]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - name: Install system deps
        run:
          brew install coreutils
      - name: Select Xcode version
        run: |
          sudo xcode-select --switch /Applications/Xcode_13.1.app/Contents/Developer
      - uses: actions/cache@v3
        id: cache
        if: matrix.arch == 'arm64'
        with:
          path: ~/arm-target
          key: ${{ runner.os }}-arm-brew-cache
      - name: Install arm64 deps
        if: matrix.arch == 'arm64' && steps.cache.outputs.cache-hit != 'true'
        run: |
          set -xe
          mkdir -p ~/arm-target/bin
          mkdir -p ~/arm-target/brew-cache
          export PATH="$HOME/arm-target/bin:$PATH"

          cd ~/arm-target
          mkdir arm-brew && curl -L https://github.com/Homebrew/brew/tarball/932d2cf3b77c9439a57b6a43577fc8d3b6399a62 | tar xz --strip 1 -C arm-brew

          export HOMEBREW_NO_AUTO_UPDATE=1
          export HOMEBREW_CACHE=~/arm-target/brew-cache
          export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
          ~/arm-target/arm-brew/bin/brew fetch --deps --bottle-tag=arm64_big_sur sox opusfile |\
             grep -E "(Downloaded to:|Already downloaded:)" |\
             grep -v pkg-config |\
             awk '{ print $3 }' |\
             xargs -n 1 ~/arm-target/arm-brew/bin/brew install --ignore-dependencies --force-bottle

          # Install host version of pkg-config so we can call it in the build system
          ~/arm-target/arm-brew/bin/brew install pkg-config
          ln -s ~/arm-target/arm-brew/bin/pkg-config ~/arm-target/bin/arm-pkg-config
      - run: |
          echo "$HOME/arm-target/bin" >> $GITHUB_PATH
        if: matrix.arch == 'arm64'
      - run: ./ci_scripts/tf-setup.sh
      - name: Workaround problems with mixing headers from Xcode and CommandLineTools by removing the latter
        run: |
          sudo rm -r /Library/Developer/CommandLineTools
      - run: ./ci_scripts/host-build.sh ${{ matrix.arch }}
      - run: ./ci_scripts/package.sh
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.macOS.${{ matrix.arch }}.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.macOS.${{ matrix.arch }}.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
  build-lib-iOS:
    name: "iOS|Build libstt+client"
    runs-on: macos-12
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - name: Install system deps
        run:
          brew install coreutils
      - name: Select Xcode version
        run: |
          sudo xcode-select --switch /Applications/Xcode_13.1.app/Contents/Developer
      - run: ./ci_scripts/tf-setup.sh
      - name: Workaround problems with mixing headers from Xcode and CommandLineTools by removing the latter
        run: |
          sudo rm -r /Library/Developer/CommandLineTools
      - run: ./ci_scripts/ios-build.sh
      - run: |
          zip -r9 --junk-paths ${CI_ARTIFACTS_DIR}/ios_artifacts.zip \
            tensorflow/bazel-bin/native_client/STT.swiftdoc \
            tensorflow/bazel-bin/native_client/STT.swiftmodule \
            tensorflow/bazel-bin/native_client/STT.swiftsourceinfo \
            tensorflow/bazel-bin/native_client/coqui_stt_bundle.swift.modulemap \
            tensorflow/bazel-bin/native_client/libkenlm.so \
            tensorflow/bazel-bin/native_client/libstt.so \
            tensorflow/bazel-out/applebin_ios*/bin/native_client/stt_ios.zip \
            tensorflow/bazel-out/applebin_ios*/bin/native_client/kenlm_ios.zip
      - uses: actions/upload-artifact@v3
        with:
          name: "ios_artifacts.zip"
          path: ${{ github.workspace }}/artifacts/ios_artifacts.zip
  build-universal-lib-macOS:
    name: "Mac|Build universal lib"
    runs-on: macos-12
    needs: [build-lib-macOS]
    steps:
      # Download and extract individual arch packages and create universal binaries
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.macOS.x86_64.tar.xz"
      - run: |
          mkdir nc.x86_64
          cd nc.x86_64
          tar xvf ../native_client.tar.xz
          rm ../native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.macOS.arm64.tar.xz"
      - run: |
          mkdir nc.arm64
          cd nc.arm64
          tar xvf ../native_client.tar.xz
          rm ../native_client.tar.xz
      - name: Create universal binaries
        run: |
          for binary in "libstt.so" "libkenlm.so" "stt"; do
            lipo -create -output "${binary}" "nc.x86_64/${binary}" "nc.arm64/${binary}"
            cp -f "${binary}" "nc.x86_64/${binary}"
          done
      - run: |
          cd nc.x86_64
          tar cvJf native_client.tar.xz .
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.macOS.tar.xz"
          path: nc.x86_64/native_client.tar.xz
      # Now do the same, but for libstt.zip
      - uses: actions/download-artifact@v3
        with:
          name: "libstt.tflite.macOS.x86_64.zip"
      - run: |
          mkdir libstt.x86_64
          cd libstt.x86_64
          tar xvf ../libstt.zip
          rm ../libstt.zip
      - uses: actions/download-artifact@v3
        with:
          name: "libstt.tflite.macOS.arm64.zip"
      - run: |
          mkdir libstt.arm64
          cd libstt.arm64
          tar xvf ../libstt.zip
          rm ../libstt.zip
      - name: Create universal binaries
        run: |
          for binary in "libstt.so" "libkenlm.so"; do
            lipo -create -output "${binary}" "libstt.x86_64/${binary}" "libstt.arm64/${binary}"
            cp -f "${binary}" "libstt.x86_64/${binary}"
          done
      - run: |
          zip -r9 --junk-paths libstt.zip libstt.x86_64/*
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.macOS.zip"
          path: libstt.zip
  build-python-macOS:
    name: "Mac|Build Python bindings"
    runs-on: macos-12
    needs: [build-universal-lib-macOS, swig_macOS]
    strategy:
      matrix:
        python-version: [3.6.8, 3.7.9, 3.8.9, 3.9.4, 3.10.1]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.macOS.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_macOS"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - uses: ./.github/actions/install-python-upstream
        with:
          version: ${{ matrix.python-version }}
      # GitHub packaged version are limited to macOS deployment target 10.14
      #- uses: actions/setup-python@v4
      #  with:
      #    python-version: ${{ matrix.python-version }}
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - uses: ./.github/actions/python-build
        with:
          numpy_build: "${{ steps.get_numpy.outputs.build_version }}"
          numpy_dep: "${{ steps.get_numpy.outputs.dep_version }}"
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-macOS.whl"
          path: ${{ github.workspace }}/native_client/python/dist/*.whl
  build-nodejs-macOS:
    name: "Mac|Build NodeJS and ElectronJS"
    runs-on: macos-12
    needs: [build-universal-lib-macOS, swig_macOS]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.macOS.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_macOS"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/cache@v3
        id: node-headers-cache
        with:
          path: native_client/javascript/headers/nodejs/
          key: node-headers-12.7.0_17.0.1
      - uses: actions/cache@v3
        id: electron-headers-cache
        with:
          path: native_client/javascript/headers/electronjs/
          key: electron-headers-12.0.0_16.0.0
      - uses: ./.github/actions/node-build
        with:
          nodejs_versions: "12.7.0 13.0.0 14.0.0 15.0.0 16.0.0 17.0.1"
          electronjs_versions: "12.0.0 13.0.0 14.0.0 15.0.0 16.0.0"
      - uses: actions/upload-artifact@v3
        with:
          name: "nodewrapper-tflite-macOS_amd64.tar.gz"
          path: ${{ github.workspace }}/native_client/javascript/wrapper.tar.gz
      - uses: actions/upload-artifact@v3
        with:
          name: "stt_intermediate-tflite-macOS.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  test-cpp-macOS:
    name: "Mac|Test C++ binary"
    runs-on: macos-12
    needs: [build-universal-lib-macOS, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.macOS.tar.xz"
          path: ${{ env.CI_TMP_DIR }}
      - run: |
          cd ${{ env.CI_TMP_DIR }}
          mkdir ds && cd ds && tar xf ../native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -halR ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: ./.github/actions/run-tests
        with:
          runtime: "cpp"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-py-macOS:
    name: "Mac|Test Python bindings"
    runs-on: macos-12
    needs: [build-python-macOS, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        python-version: [3.6.8, 3.7.9, 3.8.9, 3.9.4]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-macOS.whl"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          pip3 install --only-binary :all: --upgrade ${{ env.CI_TMP_DIR }}/stt*.whl
      - uses: ./.github/actions/run-tests
        with:
          runtime: "python"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-nodejs-macOS:
    name: "Mac|Test NodeJS bindings"
    runs-on: macos-12
    needs: [build-nodejs-macOS, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 14, 16, 17]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-macOS.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ~/.npm/
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          ls -hal node_modules/stt* node_modules/.bin/
      - uses: ./.github/actions/run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs-macOS:
    name: "Mac|Test ElectronJS bindings"
    runs-on: macos-12
    needs: [build-nodejs-macOS, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 13.0.0, 14.0.0, 15.0.0, 16.0.0]
        models: ["test"]
        samplerate: ["16000"]
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-macOS.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ~/.npm/
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  # Windows jobs
  build-ctc-decoder-windows:
    name: "Win|Build CTC decoder Python package"
    needs: [swig_Windows_crosscompiled]
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            git
            make
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7.9
      - run: |
          python --version
          python -m pip --version
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Windows_crosscompiled"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Remove /usr/bin/link conflicting with MSVC link.exe
        run: |
          set -ex
          which link
          rm /usr/bin/link
      - name: Link ds-swig into swig
        run: |
          set -ex
          ls -hal native_client/ds-swig/bin
          ln -s ds-swig.exe native_client/ds-swig/bin/swig.exe
          chmod +x native_client/ds-swig/bin/ds-swig.exe native_client/ds-swig/bin/swig.exe
      - run: |
          make -C native_client/ctcdecode/ \
            NUM_PROCESSES=$(nproc) \
            bindings
      - uses: actions/upload-artifact@v3
        with:
          name: "coqui_stt_ctcdecoder-windows-test.whl"
          path: ${{ github.workspace }}/native_client/ctcdecode/dist/*.whl
      - run: |
          make -C native_client/ctcdecode clean-keep-third-party
  build-lib-Windows:
    name: "Win|Build libstt+client"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            git
            patch
            tar
            unzip
            zip
            make
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7.9
      - name: Workaround bazel bug when LLVM is installed https://github.com/bazelbuild/bazel/issues/12144
        run: |
          rm -f /c/msys64/mingw64/clang-cl*
          rm -rf "/c/Program Files/LLVM"
      - run: ./ci_scripts/tf-setup.sh
      - run: ./ci_scripts/host-build.sh
      - run: ./ci_scripts/package.sh
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.Windows.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.Windows.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
  build-python-Windows:
    name: "Win|Build Python bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [build-lib-Windows, swig_Windows_crosscompiled]
    strategy:
      matrix:
        # Try to keep Python versions in sync with cached versions to speed things up:
        # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
        python-version: [3.6.8, 3.7.9, 3.8.8, 3.9.4, 3.10.0]
    steps:
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            make
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Windows.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd tensorflow/bazel-bin/native_client/
          "C:/Program Files/7-Zip/7z.exe" x native_client.tar.xz -so | "C:/Program Files/7-Zip/7z.exe" x -aoa -si -snld -ttar -o`pwd`
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Windows_crosscompiled"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          set -ex
          ls -hal native_client/ds-swig/bin
          ln -s ds-swig.exe native_client/ds-swig/bin/swig.exe
          chmod +x native_client/ds-swig/bin/ds-swig.exe native_client/ds-swig/bin/swig.exe
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Remove /usr/bin/link conflicting with MSVC link.exe
        run: |
          rm /usr/bin/link
      - id: get_numpy
        uses: ./.github/actions/win-numpy-vers
        with:
          pyver: ${{ matrix.python-version }}
      - uses: ./.github/actions/win-python-build
        with:
          numpy_build: "${{ steps.get_numpy.outputs.build_version }}"
          numpy_dep: "${{ steps.get_numpy.outputs.dep_version }}"
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-Windows.whl"
          path: ${{ github.workspace }}/native_client/python/dist/*.whl
  build-nodejs-Windows:
    name: "Win|Build NodeJS/ElectronJS"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [build-lib-Windows, swig_Windows_crosscompiled]
    steps:
      - uses: ilammy/msvc-dev-cmd@v1
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            make
            tar
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Windows.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd tensorflow/bazel-bin/native_client/
          "C:/Program Files/7-Zip/7z.exe" x native_client.tar.xz -so | "C:/Program Files/7-Zip/7z.exe" x -aoa -si -snld -ttar -o`pwd`
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Windows_crosscompiled"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          set -ex
          ls -hal native_client/ds-swig/bin
          ln -s ds-swig.exe native_client/ds-swig/bin/swig.exe
          chmod +x native_client/ds-swig/bin/ds-swig.exe native_client/ds-swig/bin/swig.exe
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/cache@v3
        id: node-headers-cache
        with:
          path: native_client/javascript/headers/nodejs/
          key: node-headers-win-12.7.0_16.0.0
      - uses: actions/cache@v3
        id: electron-headers-cache
        with:
          path: native_client/javascript/headers/electronjs/
          key: electron-headers-win-12.0.0_15.0.0
      - uses: ./.github/actions/win-node-build
        with:
          nodejs_versions: "12.7.0 13.0.0 14.0.0 15.0.0 16.0.0"
          electronjs_versions: "12.0.0 13.0.0 14.0.0 15.0.0 16.0.0"
      - uses: actions/upload-artifact@v3
        with:
          name: "nodewrapper-tflite-Windows_amd64.tar.gz"
          path: ${{ github.workspace }}/native_client/javascript/wrapper.tar.gz
      - uses: actions/upload-artifact@v3
        with:
          name: "STT_intermediate-tflite-Windows.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  test-cpp-Windows:
    name: "Win|Test C++ binary"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [build-lib-Windows, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - name: Download native_client.tar.xz
        uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.Windows.tar.xz"
          path: ${{ env.CI_TMP_DIR }}
      - name: Extract native_client.tar.xz
        run: |
          mkdir -p ${{ env.CI_TMP_DIR }}/ds
          pushd ${{ env.CI_TMP_DIR }}/ds
          "C:/Program Files/7-Zip/7z.exe" x ../native_client.tar.xz -so | "C:/Program Files/7-Zip/7z.exe" x -aoa -si -snld -ttar -o`pwd`
          ls -hal
          popd
      - name: Download trained test model
        uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-16000.zip"
          path: ${{ env.CI_TMP_DIR }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "cppwin"
          samplerate: "16000"
          model-kind: ""
  test-py-Windows:
    name: "Win|Test Python bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [ build-python-Windows, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # Try to keep Python versions in sync with cached versions to speed things up:
        # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
        python-version: [3.6.8, 3.7.9, 3.8.8, 3.9.4, 3.10.0]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: ./.github/actions/win-install-sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-Windows.whl"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          python -m pip install --only-binary :all: --upgrade ${{ env.CI_TMP_DIR }}/stt*.whl
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "python"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-nodejs-Windows:
    name: "Win|Test NodeJS bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [ build-nodejs-Windows, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        nodejs-version: [12, 14, 16]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - uses: ./.github/actions/win-install-sox
      - uses: actions/download-artifact@v3
        with:
          name: "STT_intermediate-tflite-Windows.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - name: Get npm cache directory
        id: npm-cache-dir
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install ${{ env.CI_TMP_DIR }}/stt*.tgz
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs-Windows:
    name: "Win|Test ElectronJS bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [ build-nodejs-Windows, train-test-model-Linux ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 13.0.0, 14.0.0, 15.0.0, 16.0.0]
        models: ["test"]
        samplerate: ["16000"]
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: ./.github/actions/win-install-sox
      - uses: actions/download-artifact@v3
        with:
          name: "STT_intermediate-tflite-Windows.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Get npm cache directory
        id: npm-cache-dir
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  # Shared jobs (multi-platform dependencies)
  repackage-nodejs-allplatforms:
    name: "Repackage NodeJS / ElectronJS for multiplatforms"
    runs-on: ubuntu-20.04
    needs: [build-nodejs-macOS, build-nodejs-Windows, build-nodejs-Linux, build-nodejs-LinuxArmv7, build-nodejs-LinuxAarch64]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - run: |
          mkdir -p /tmp/nodewrapper-tflite-macOS_amd64/
          mkdir -p /tmp/nodewrapper-tflite-Windows_amd64/
      - uses: actions/download-artifact@v3
        with:
          name: "nodewrapper-tflite-macOS_amd64.tar.gz"
          path: /tmp/nodewrapper-macOS_amd64/
      - uses: actions/download-artifact@v3
        with:
          name: "nodewrapper-tflite-Windows_amd64.tar.gz"
          path: /tmp/nodewrapper-Windows_amd64/
      - uses: actions/download-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_amd64.tar.gz"
          path: /tmp/nodewrapper-Linux_amd64/
      - uses: actions/download-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_armv7.tar.gz"
          path: /tmp/nodewrapper-Linux_armv7/
      - uses: actions/download-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_aarch64.tar.gz"
          path: /tmp/nodewrapper-Linux_aarch64/
      - name: Extract nodewrapper archives
        run: |
          tar -C ${{ github.workspace }}/native_client/javascript -xzvf /tmp/nodewrapper-macOS_amd64/wrapper.tar.gz
          tar -C ${{ github.workspace }}/native_client/javascript -xzvf /tmp/nodewrapper-Windows_amd64/wrapper.tar.gz
          tar -C ${{ github.workspace }}/native_client/javascript -xzvf /tmp/nodewrapper-Linux_amd64/wrapper.tar.gz
          tar -C ${{ github.workspace }}/native_client/javascript -xzvf /tmp/nodewrapper-Linux_armv7/wrapper.tar.gz
          tar -C ${{ github.workspace }}/native_client/javascript -xzvf /tmp/nodewrapper-Linux_aarch64/wrapper.tar.gz
      - run: |
          make -C native_client/javascript clean npm-pack PROJECT_NAME=stt
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  test-nodejs_all-Linux:
    name: "Lin|Test MultiArchPlatform NodeJS bindings"
    runs-on: ubuntu-20.04
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 17]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - run: |
          sudo apt-get install -y --no-install-recommends sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ~/.npm/
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          ls -hal node_modules/stt* node_modules/.bin/
      - uses: ./.github/actions/run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs_all-Linux:
    name: "Lin|Test MultiArchPlatform ElectronJS bindings"
    runs-on: ubuntu-20.04
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 16.0.0]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - run: |
          sudo apt-get install -y --no-install-recommends sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ~/.npm/
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  test-nodejs_all-macOS:
    name: "Mac|Test MultiArchPlatform NodeJS bindings"
    runs-on: macos-12
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 17]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ~/.npm/
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          ls -hal node_modules/stt* node_modules/.bin/
      - uses: ./.github/actions/run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs_all-macOS:
    name: "Mac|Test MultiArchPlatform ElectronJS bindings"
    runs-on: macos-12
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 16.0.0]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp/
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ~/.npm/
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  test-nodejs_all-Windows:
    name: "Win|Test MultiArchPlatform NodeJS bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 16]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.nodejs-version }}
      - uses: ./.github/actions/win-install-sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - name: Get npm cache directory
        id: npm-cache-dir
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
      - uses: actions/cache@v3
        id: node-modules-cache
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: node-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "node"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs_all-Windows:
    name: "Win|Test MultiArchPlatform ElectronJS bindings"
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
    needs: [repackage-nodejs-allplatforms, train-test-model-Linux]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        electronjs-version: [12.0.0, 16.0.0]
        models: ["test", "prod"]
        samplerate: ["8000", "16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: tmp/
      STT_TEST_MODEL: tmp/output_graph.tflite
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MSYS
          path-type: inherit
          update: true
          install: >-
            vim
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: ./.github/actions/win-install-sox
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite.tgz"
          path: ${{ env.CI_TMP_DIR }}
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: Get npm cache directory
        id: npm-cache-dir
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
      - uses: actions/cache@v3
        id: electron-modules-cache
        with:
          path: ${{ steps.npm-cache-dir.outputs.dir }}
          key: electron-modules-tflite-${{ runner.os }}-${{ env.CI_NODE_MODULES_NTH }}
      - name: Install STT package
        run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          npm install --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          npm install electron@${{ matrix.electronjs-version }}
      - uses: ./.github/actions/win-run-tests
        with:
          runtime: "electronjs"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
  # Linux Armv7 and Aarch64 jobs
  build-lib-LinuxArmv7:
    name: "LinArmv7|Build libstt+client"
    runs-on: ubuntu-20.04
    env:
      SYSTEM_TARGET: rpi3
      SYSTEM_RASPBIAN: ${{ github.workspace }}/multistrap-raspbian-buster
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - name: Install chroot
        uses: ./.github/actions/multistrap
        with:
          arch: armv7
      - run: ./ci_scripts/tf-setup.sh
      - run: ./ci_scripts/armv7-build.sh
      - run: ./ci_scripts/package.sh
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.linux.armv7.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.linux.armv7.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
  build-lib-LinuxAarch64:
    name: "LinAarch64|Build libstt+client"
    runs-on: ubuntu-20.04
    env:
      SYSTEM_TARGET: rpi3-armv8
      SYSTEM_RASPBIAN: ${{ github.workspace }}/multistrap-armbian64-buster
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - name: Install chroot
        uses: ./.github/actions/multistrap
        with:
          arch: aarch64
      - run: ./ci_scripts/tf-setup.sh
      - run: ./ci_scripts/aarch64-build.sh
      - run: ./ci_scripts/package.sh
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.linux.aarch64.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.tflite.linux.aarch64.zip"
          path: ${{ github.workspace }}/artifacts/libstt.zip
  build-python-LinuxArmv7:
    name: "LinArmv7|Build Python bindings"
    runs-on: ubuntu-20.04
    needs: [build-lib-LinuxArmv7, swig_Linux]
    strategy:
      matrix:
        include:
          - python-version: 3.7
            system-raspbian: multistrap-raspbian-buster
            arch: armv7
          - python-version: 3.9
            system-raspbian: multistrap-raspbian-bullseye
            arch: armv7
      fail-fast: false
    env:
      DEBIAN_FRONTEND: "noninteractive"
      SYSTEM_TARGET: rpi3
      SYSTEM_RASPBIAN: ${{ github.workspace }}/${{ matrix.system-raspbian }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.linux.armv7.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: "Install chroot"
        uses: ./.github/actions/multistrap
        with:
          arch: ${{ matrix.arch }}
          pyver: ${{ matrix.python-version }}
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          pip install -U pip setuptools wheel
      - name: Download cross-build toolchain
        run: |
          cd tensorflow
          bazel build --cpu=armhf @local_config_embedded_arm//:toolchain
      - uses: ./.github/actions/install-xldd
        with:
          target: ${{ env.SYSTEM_TARGET }}
      - uses: ./.github/actions/python-build
        with:
          numpy_build: "${{ steps.get_numpy.outputs.build_version }}"
          numpy_dep: "${{ steps.get_numpy.outputs.dep_version }}"
          target: ${{ env.SYSTEM_TARGET }}
          chroot: ${{ env.SYSTEM_RASPBIAN }}
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-armv7.whl"
          path: ${{ github.workspace }}/native_client/python/dist/*.whl
  build-nodejs-LinuxArmv7:
    name: "LinArmv7|Build NodeJS and ElectronJS"
    runs-on: ubuntu-20.04
    needs: [build-lib-LinuxArmv7, swig_Linux]
    env:
      SYSTEM_TARGET: rpi3
      SYSTEM_RASPBIAN: ${{ github.workspace }}/multistrap-raspbian-buster
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.linux.armv7.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - name: "Install chroot"
        uses: ./.github/actions/multistrap
        with:
          arch: armv7
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/cache@v3
        id: node-headers-cache
        with:
          path: native_client/javascript/headers/nodejs/
          key: node-headers-12.7.0_17.0.1
      - uses: actions/cache@v3
        id: electron-headers-cache
        with:
          path: native_client/javascript/headers/electronjs/
          key: electron-headers-12.0.0_16.0.0
      - name: Download cross-build toolchain
        run: |
          cd tensorflow
          bazel build --cpu=armhf @local_config_embedded_arm//:toolchain
      - uses: ./.github/actions/install-xldd
        with:
          target: ${{ env.SYSTEM_TARGET }}
      - uses: ./.github/actions/node-build
        with:
          nodejs_versions: "12.7.0 13.0.0 14.0.0 15.0.0 16.0.0 17.0.1"
          electronjs_versions: "12.0.0 13.0.0 14.0.0 15.0.0 16.0.0"
          target: ${{ env.SYSTEM_TARGET }}
          chroot: ${{ env.SYSTEM_RASPBIAN }}
      - uses: actions/upload-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_armv7.tar.gz"
          path: ${{ github.workspace }}/native_client/javascript/wrapper.tar.gz
      - uses: actions/upload-artifact@v3
        with:
          name: "stt_intermediate-tflite-armv7.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  build-python-LinuxAarch64:
    name: "LinAarch64|Build Python bindings"
    runs-on: ubuntu-20.04
    needs: [build-lib-LinuxAarch64, swig_Linux]
    strategy:
      matrix:
        include:
          - python-version: 3.7
            system-raspbian: multistrap-armbian64-buster
            arch: aarch64
          - python-version: 3.9
            system-raspbian: multistrap-armbian64-bullseye
            arch: aarch64
      fail-fast: false
    env:
      DEBIAN_FRONTEND: "noninteractive"
      SYSTEM_TARGET: rpi3-armv8
      SYSTEM_RASPBIAN: ${{ github.workspace }}/${{ matrix.system-raspbian }}
    steps:
      - run: |
          sudo apt-get install -y --no-install-recommends
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.linux.aarch64.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: "Install chroot"
        uses: ./.github/actions/multistrap
        with:
          arch: ${{ matrix.arch }}
          pyver: ${{ matrix.python-version }}
      - id: get_numpy
        uses: ./.github/actions/numpy_vers
        with:
          pyver: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          pip install -U pip setuptools wheel
      - name: Download cross-build toolchain
        run: |
          cd tensorflow
          bazel build --cpu=aarch64 @local_config_embedded_arm//:toolchain
      - uses: ./.github/actions/install-xldd
        with:
          target: ${{ env.SYSTEM_TARGET }}
      - uses: ./.github/actions/python-build
        with:
          numpy_build: "${{ steps.get_numpy.outputs.build_version }}"
          numpy_dep: "${{ steps.get_numpy.outputs.dep_version }}"
          target: ${{ env.SYSTEM_TARGET }}
          chroot: ${{ env.SYSTEM_RASPBIAN }}
      - uses: actions/upload-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-aarch64.whl"
          path: ${{ github.workspace }}/native_client/python/dist/*.whl
  build-nodejs-LinuxAarch64:
    name: "LinAarch64|Build NodeJS and ElectronJS"
    runs-on: ubuntu-20.04
    needs: [build-lib-LinuxAarch64, swig_Linux]
    env:
      SYSTEM_TARGET: rpi3-armv8
      SYSTEM_RASPBIAN: ${{ github.workspace }}/multistrap-armbian64-buster
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.linux.aarch64.tar.xz"
          path: ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
      - run: |
          cd ${{ github.workspace }}/tensorflow/bazel-bin/native_client/
          tar xf native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "swig_Linux"
          path: ${{ github.workspace }}/native_client/ds-swig/
      - name: Link ds-swig into swig
        run: |
          ls -hal ${{ github.workspace }}/native_client/ds-swig/bin
          ln -s ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
          chmod +x ${{ github.workspace }}/native_client/ds-swig/bin/ds-swig ${{ github.workspace }}/native_client/ds-swig/bin/swig
      - name: "Install chroot"
        uses: ./.github/actions/multistrap
        with:
          arch: aarch64
      - uses: actions/setup-node@v3
        with:
          node-version: 12
      - uses: actions/cache@v3
        id: node-headers-cache
        with:
          path: native_client/javascript/headers/nodejs/
          key: node-headers-12.7.0_17.0.1
      - uses: actions/cache@v3
        id: electron-headers-cache
        with:
          path: native_client/javascript/headers/electronjs/
          key: electron-headers-12.0.0_16.0.0
      - name: Download cross-build toolchain
        run: |
          cd tensorflow
          bazel build --cpu=aarch64 @local_config_embedded_arm//:toolchain
      - uses: ./.github/actions/install-xldd
        with:
          target: ${{ env.SYSTEM_TARGET }}
      - uses: ./.github/actions/node-build
        with:
          nodejs_versions: "12.7.0 13.0.0 14.0.0 15.0.0 16.0.0 17.0.1"
          electronjs_versions: "12.0.0 13.0.0 14.0.0 15.0.0 16.0.0"
          target: ${{ env.SYSTEM_TARGET }}
          chroot: ${{ env.SYSTEM_RASPBIAN }}
      - uses: actions/upload-artifact@v3
        with:
          name: "nodewrapper-tflite-Linux_aarch64.tar.gz"
          path: ${{ github.workspace }}/native_client/javascript/wrapper.tar.gz
      - uses: actions/upload-artifact@v3
        with:
          name: "stt_intermediate-tflite-aarch64.tgz"
          path: ${{ github.workspace }}/native_client/javascript/stt-*.tgz
  build-test-chroot:
    name: "Lin|Build test chroot"
    runs-on: ubuntu-20.04
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        include:
          - arch: armv7
            python-version: 3.7
            system: buster
          - arch: armv7
            python-version: 3.9
            system: bullseye
          - arch: aarch64
            python-version: 3.7
            system: buster
          - arch: aarch64
            python-version: 3.9
            system: bullseye
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp
      DEBIAN_FRONTEND: "noninteractive"
      SYSTEM_RASPBIAN: ${{ github.workspace }}/chroot-${{ matrix.arch }}-${{ matrix.system }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - name: "Install and setup chroot"
        uses: ./.github/actions/multistrap
        with:
          arch: ${{ matrix.arch }}
          pyver: ${{ matrix.python-version }}
          packages: "bash wget curl sox xxd libatlas3-base libopenblas-base ca-certificates python3 python3-pip gnupg libatk1.0-0 libatk-bridge2.0-0 libcairo2 libcups2 libdbus-1-3 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm1 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libx11-xcb1 libxcb-dri3-0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 xauth"
      - name: "Create a chroot tarball"
        run: |
          sudo tar -cf - -C ${{ env.SYSTEM_RASPBIAN }}/ --one-file-system . | xz -9 -T0 > ${{ github.workspace }}/chroot.tar.xz
      - uses: actions/upload-artifact@v3
        with:
          name: chroot-${{ matrix.arch }}-${{ matrix.system }}
          path: ${{ github.workspace }}/chroot.tar.xz
  test-cpp-LinuxArm:
    name: "LinArm*|Test C++ binary"
    runs-on: ubuntu-20.04
    needs: [ build-lib-LinuxArmv7, build-lib-LinuxAarch64, train-test-model-Linux, build-test-chroot ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        include:
          - arch: "armv7"
            system: "buster"
            models: "test"
            samplerate: "8000"
          - arch: "armv7"
            system: "buster"
            models: "test"
            samplerate: "16000"
          - arch: "armv7"
            system: "buster"
            models: "prod"
            samplerate: "8000"
          - arch: "armv7"
            system: "buster"
            models: "prod"
            samplerate: "16000"
          - arch: "armv7"
            system: "bullseye"
            models: "test"
            samplerate: "8000"
          - arch: "armv7"
            system: "bullseye"
            models: "test"
            samplerate: "16000"
          - arch: "armv7"
            system: "bullseye"
            models: "prod"
            samplerate: "8000"
          - arch: "armv7"
            system: "bullseye"
            models: "prod"
            samplerate: "16000"
          - arch: "aarch64"
            system: "buster"
            models: "test"
            samplerate: "8000"
          - arch: "aarch64"
            system: "buster"
            models: "test"
            samplerate: "16000"
          - arch: "aarch64"
            system: "buster"
            models: "prod"
            samplerate: "8000"
          - arch: "aarch64"
            system: "buster"
            models: "prod"
            samplerate: "16000"
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp
      DEBIAN_FRONTEND: "noninteractive"
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
      SYSTEM_RASPBIAN: ${{ github.workspace }}/chroot-${{ matrix.arch }}-${{ matrix.system }}
    steps:
      - name: "Install QEMU"
        run: |
          sudo apt-get update -y
          sudo apt-get install -y --no-install-recommends qemu-user-static
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "chroot-${{ matrix.arch }}-${{ matrix.system }}"
          path: ${{ env.CI_TMP_DIR }}/
      - run: |
          mkdir ${{ env.SYSTEM_RASPBIAN }}/
          sudo tar -xf ${{ env.CI_TMP_DIR }}/chroot.tar.xz -C ${{ env.SYSTEM_RASPBIAN }}/
          rm ${{ env.CI_TMP_DIR }}/chroot.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "native_client.tflite.linux.${{ matrix.arch }}.tar.xz"
          path: ${{ env.CI_TMP_DIR }}/
      - run: |
          cd ${{ env.CI_TMP_DIR }}/
          mkdir ds && cd ds && tar xf ../native_client.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - name: "Check tests"
        run: |
          file ${{ env.SYSTEM_RASPBIAN }}/${{ env.CI_TMP_DIR }}/ds/*
      - uses: ./.github/actions/chroot-bind-mount
        with:
          mounts: "/dev"
      - uses: ./.github/actions/run-tests
        with:
          runtime: "cpp"
          chroot: "sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ${{ github.workspace }}"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-py-LinuxArm:
    name: "LinArm*|Test Python bindings"
    runs-on: ubuntu-20.04
    needs: [ build-python-LinuxArmv7, build-python-LinuxAarch64, train-test-model-Linux, build-test-chroot ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        include:
          - arch: armv7
            system: "buster"
            python-version: "3.7"
            models: "test"
            samplerate: "8000"
          - arch: armv7
            system: "buster"
            python-version: "3.7"
            models: test
            samplerate: "16000"
          - arch: armv7
            system: "buster"
            python-version: "3.7"
            models: "prod"
            samplerate: "8000"
          - arch: armv7
            system: "buster"
            python-version: "3.7"
            models: "prod"
            samplerate: "16000"
          - arch: armv7
            system: "bullseye"
            python-version: "3.9"
            models: "test"
            samplerate: "8000"
          - arch: armv7
            system: "bullseye"
            python-version: "3.9"
            models: "test"
            samplerate: "16000"
          - arch: armv7
            system: "bullseye"
            python-version: "3.9"
            models: "prod"
            samplerate: "8000"
          - arch: armv7
            system: "bullseye"
            python-version: "3.9"
            models: "prod"
            samplerate: "16000"
          - arch: aarch64
            system: "buster"
            python-version: "3.7"
            models: "test"
            samplerate: "8000"
          - arch: aarch64
            system: "buster"
            python-version: "3.7"
            models: "test"
            samplerate: "16000"
          - arch: aarch64
            system: "buster"
            python-version: "3.7"
            models: "prod"
            samplerate: "8000"
          - arch: aarch64
            system: "buster"
            python-version: "3.7"
            models: "prod"
            samplerate: "16000"
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp
      DEBIAN_FRONTEND: "noninteractive"
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
      SYSTEM_RASPBIAN: ${{ github.workspace }}/chroot-${{ matrix.arch }}-${{ matrix.system }}
      PIP_EXTRA_INDEX_URL: "https://www.piwheels.org/simple https://lissyx.github.io/deepspeech-python-wheels/"
    steps:
      - name: "Install QEMU"
        run: |
          sudo apt-get update -y
          sudo apt-get install -y --no-install-recommends qemu-user-static
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "chroot-${{ matrix.arch }}-${{ matrix.system }}"
          path: ${{ env.CI_TMP_DIR }}/
      - run: |
          mkdir ${{ env.SYSTEM_RASPBIAN }}/
          sudo tar -xf ${{ env.CI_TMP_DIR }}/chroot.tar.xz -C ${{ env.SYSTEM_RASPBIAN }}/
          rm ${{ env.CI_TMP_DIR }}/chroot.tar.xz
      - uses: actions/download-artifact@v3
        with:
          name: "stt-tflite-${{ matrix.python-version }}-${{ matrix.arch }}.whl"
          path: ${{ env.CI_TMP_DIR }}/
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: ./.github/actions/chroot-bind-mount
        with:
          mounts: "/dev"
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
          ls -hal ${{ github.workspace }}/
          ls -hal ${{ env.SYSTEM_RASPBIAN }}/${{ github.workspace }}/
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ pip3 install --only-binary :all: --upgrade ${{ env.CI_TMP_DIR }}/stt*.whl
      - uses: ./.github/actions/run-tests
        with:
          runtime: "python"
          chroot: "sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ${{ github.workspace }}"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-nodejs-LinuxArm:
    name: "LinArm*|Test NodeJS bindings"
    runs-on: ubuntu-20.04
    needs: [ build-nodejs-LinuxArmv7, build-nodejs-LinuxAarch64, train-test-model-Linux, build-test-chroot ]
    if: ${{ github.event_name == 'pull_request' }}
    strategy:
      matrix:
        arch: ["armv7", "aarch64"]
        # https://nodejs.org/en/about/releases/
        nodejs-version: [12, 14, 16, 17]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp
      DEBIAN_FRONTEND: "noninteractive"
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
      SYSTEM_RASPBIAN: ${{ github.workspace }}/chroot-${{ matrix.arch }}-buster
    steps:
      - name: "Install QEMU"
        run: |
          sudo apt-get update -y
          sudo apt-get install -y --no-install-recommends qemu-user-static
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "chroot-${{ matrix.arch }}-buster"
          path: ${{ env.CI_TMP_DIR }}/
      - run: |
          mkdir ${{ env.SYSTEM_RASPBIAN }}/
          sudo tar -xf ${{ env.CI_TMP_DIR }}/chroot.tar.xz -C ${{ env.SYSTEM_RASPBIAN }}/
          rm ${{ env.CI_TMP_DIR }}/chroot.tar.xz
      - name: "Install NodeJS"
        uses: ./.github/actions/node-install
        with:
          node: ${{ matrix.nodejs-version }}
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-${{ matrix.arch }}.tgz"
          path: ${{ env.CI_TMP_DIR }}/
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: ./.github/actions/chroot-bind-mount
        with:
          mounts: "/dev"
      - name: Install STT package
        run: |
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ npm install --prefix ${{ github.workspace }}/ --verbose ${{ env.CI_TMP_DIR }}/stt*.tgz
      - uses: ./.github/actions/run-tests
        with:
          runtime: "node"
          chroot: "sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ${{ github.workspace }}"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
  test-electronjs-LinuxArm:
    name: "LinArm*|Test ElectronJS bindings"
    runs-on: ubuntu-20.04
    needs: [ build-nodejs-LinuxArmv7, build-nodejs-LinuxAarch64, train-test-model-Linux, build-test-chroot ]
    # Disable this task because it seems qemu does not work super-well with ElectronJS
    if: ${{ github.event_name == 'disabled' }}
    strategy:
      matrix:
        arch: ["armv7", "aarch64"]
        electronjs-version: [12.0.0, 13.0.0, 14.0.0, 15.0.0, 16.0.0]
        models: ["test"]
        samplerate: ["16000"]
      fail-fast: false
    env:
      CI_TMP_DIR: ${{ github.workspace }}/tmp
      DEBIAN_FRONTEND: "noninteractive"
      STT_TEST_MODEL: ${{ github.workspace }}/tmp/output_graph.tflite
      SYSTEM_RASPBIAN: ${{ github.workspace }}/chroot-${{ matrix.arch }}-buster
      DISPLAY: ":99.0"
    steps:
      - name: "Install QEMU"
        run: |
          sudo apt-get update -y
          sudo apt-get install -y --no-install-recommends qemu-user-static xvfb xauth
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions/download-artifact@v3
        with:
          name: "chroot-${{ matrix.arch }}-buster"
          path: ${{ env.CI_TMP_DIR }}/
      - run: |
          mkdir ${{ env.SYSTEM_RASPBIAN }}/
          sudo tar -xf ${{ env.CI_TMP_DIR }}/chroot.tar.xz -C ${{ env.SYSTEM_RASPBIAN }}/
          rm ${{ env.CI_TMP_DIR }}/chroot.tar.xz
      - name: "Install NodeJS"
        uses: ./.github/actions/node-install
        with:
          node: 12
      - uses: actions/download-artifact@v3
        with:
          name: "stt_intermediate-tflite-${{ matrix.arch }}.tgz"
          path: ${{ env.CI_TMP_DIR }}/
      - uses: actions/download-artifact@v3
        with:
          name: "test-model.tflite-${{ matrix.samplerate }}.zip"
          path: ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - run: |
          ls -hal ${{ env.CI_TMP_DIR }}/
        if: matrix.models == 'test'
      - uses: ./.github/actions/chroot-bind-mount
        with:
          mounts: "/dev /proc /sys /run"
      - name: Install STT package
        run: |
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ npm install --prefix ${{ github.workspace }}/ ${{ env.CI_TMP_DIR }}/stt*.tgz
      - run: |
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ npm install --prefix ${{ github.workspace }}/ electron@${{ matrix.electronjs-version }}
      - name: "Fake X display"
        run: |
          sudo Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
          xvfb_process=$!
          echo $xvfb_process > ${{ env.CI_TMP_DIR }}/xvfb.pid
          cat ${{ env.CI_TMP_DIR }}/xvfb.pid
      - name: "Debug missing libs"
        run: |
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ls -hal ${{ github.workspace }}/node_modules/electron/dist/electron
          sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ldd ${{ github.workspace }}/node_modules/electron/dist/electron
      - uses: ./.github/actions/run-tests
        with:
          runtime: "electronjs"
          chroot: "sudo --preserve-env chroot --userspec=runner:docker ${{ env.SYSTEM_RASPBIAN }}/ ${{ github.workspace }}"
          samplerate: ${{ matrix.samplerate }}
          model-kind: ${{ matrix.models }}
        timeout-minutes: 5
      - name: "Kill X"
        run: |
          cat ${{ env.CI_TMP_DIR }}/xvfb.pid
          sudo kill -9 $(cat ${{ env.CI_TMP_DIR }}/xvfb.pid)
  # Android jobs
  build-lib-AndroidArmv7:
    name: "AndroidArmv7|Build libstt+client"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "8"
      - run: ./ci_scripts/tf-setup.sh --android-armv7
      - run: ./ci_scripts/tf-configure.sh --android
      - run: ./ci_scripts/android-armv7-build.sh
      - run: ./ci_scripts/android-package.sh armeabi-v7a
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.android.armv7.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
  build-lib-AndroidArm64:
    name: "AndroidArm64|Build libstt+client"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "8"
      - run: ./ci_scripts/tf-setup.sh --android-arm64
      - run: ./ci_scripts/tf-configure.sh --android
      - run: ./ci_scripts/android-arm64-build.sh
      - run: ./ci_scripts/android-package.sh arm64-v8a
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.android.arm64.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
  build-lib-Androidx86_64:
    name: "Androidx86_64|Build libstt+client"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          submodules: 'recursive'
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "8"
      - run: ./ci_scripts/tf-setup.sh --android-arm64
      - run: ./ci_scripts/tf-configure.sh --android
      - run: ./ci_scripts/android-x86_64-build.sh
      - run: ./ci_scripts/android-package.sh x86_64
      - uses: actions/upload-artifact@v3
        with:
          name: "native_client.tflite.android.x86_64.tar.xz"
          path: ${{ github.workspace }}/artifacts/native_client.tar.xz
  build-android-apk-aar:
    name: "Android|Build AAR+APK"
    runs-on: ubuntu-20.04
    needs: [build-lib-AndroidArmv7, build-lib-AndroidArm64, build-lib-Androidx86_64]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.android.armv7.tar.xz
          path: /tmp/nc
      - run: |
          mkdir -p native_client/java/libstt/libs/armeabi-v7a
          cd /tmp/nc
          tar xvf native_client.tar.xz
          mv libstt.so libkenlm.so ${CI_TASK_DIR}/native_client/java/libstt/libs/armeabi-v7a/
          rm -f *
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.android.arm64.tar.xz
          path: /tmp/nc
      - run: |
          mkdir -p native_client/java/libstt/libs/arm64-v8a
          cd /tmp/nc
          tar xvf native_client.tar.xz
          mv libstt.so libkenlm.so ${CI_TASK_DIR}/native_client/java/libstt/libs/arm64-v8a/
          rm -f *
      - uses: actions/download-artifact@v3
        with:
          name: native_client.tflite.android.x86_64.tar.xz
          path: /tmp/nc
      - run: |
          mkdir -p native_client/java/libstt/libs/x86_64
          cd /tmp/nc
          tar xvf native_client.tar.xz
          mv libstt.so libkenlm.so ${CI_TASK_DIR}/native_client/java/libstt/libs/x86_64/
          rm -f *
      - uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "11"
          cache: "gradle"
      - name: Setup Android SDK
        uses: android-actions/setup-android@v2
      - name: Install Android NDK r19c
        uses: nttld/setup-ndk@v1
        id: setup-ndk
        with:
          ndk-version: r19c
          add-to-path: false
      # This particular version of CMake confuses Gradle by not being semver.
      # We're fine with 3.22.1 which is also installed. Keep an eye on the
      # virtual environments though:
      # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-12-Readme.md#android
      - name: Remove CMake 3.18.1-g262b901
        run: |
          ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --uninstall 'cmake;3.18.1'
      - run: |
          make GRADLE="./gradlew " -C native_client/java
        env:
          ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
      - run: |
          make GRADLE="./gradlew " -C native_client/java maven-bundle
        env:
          ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
      - uses: actions/upload-artifact@v3
        with:
          name: "app.apk"
          path: ${{ github.workspace }}/native_client/java/app/build/outputs/apk/release/app*.apk
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.aar"
          path: ${{ github.workspace }}/native_client/java/libstt/build/outputs/aar/libstt*.aar
      - uses: actions/upload-artifact@v3
        with:
          name: "libstt.maven.zip"
          path: ${{ github.workspace }}/native_client/java/libstt/build/libstt-*.maven.zip
  publish-android-aar:
    name: "Android|Publish AAR"
    runs-on: ubuntu-20.04
    needs: [create-release, build-android-apk-aar]
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v3
        with:
          name: "libstt.aar"
          path: ${{ github.workspace }}/
      - run: ls -lh
      - uses: ./.github/actions/upload-release-asset
        with:
          name: '' # use filename
          path: "*.aar"
          release-tag: ${{ needs.create-release.outputs.release-tag }}
