Publish test results

# Copied from https://github.com/EnricoMi/publish-unit-test-result-action/blob/v1.23/README.md#support-fork-repositories-and-dependabot-branches

name: Publish test results

on:
  workflow_run:
    workflows: ["CI"]
    types:
      - completed

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

jobs:
  publish-test-results:
    name: Publish test results
    runs-on: ubuntu-latest
    if: github.event.workflow_run.conclusion != 'skipped'

    steps:
      - name: Download and extract artifacts
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: |
          mkdir artifacts && cd artifacts

          artifacts_url=${{ github.event.workflow_run.artifacts_url }}

          gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
          do
            IFS=$'\t' read name url <<< "$artifact"
            gh api $url > "$name.zip"
            unzip -d "$name" "$name.zip"
          done

      - name: Publish Unit Test Results
        uses: EnricoMi/publish-unit-test-result-action@v2
        with:
          commit: ${{ github.event.workflow_run.head_sha }}
          event_file: artifacts/Event File/event.json
          event_name: ${{ github.event.workflow_run.event }}
          files: "artifacts/**/*.xml"
          comment_mode: off


Benchmark

name: Benchmark

on:
  pull_request:
    types: [opened, reopened, synchronize, labeled]
  workflow_dispatch:

jobs:
  benchmark:
    if: ${{ contains( github.event.pull_request.labels.*.name, 'run-benchmark') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
    name: Linux
    runs-on: ubuntu-20.04
    env:
      ASV_DIR: "./asv_bench"
      CONDA_ENV_FILE: ci/requirements/environment.yml

    steps:
      # We need the full repo to avoid this issue
      # https://github.com/actions/checkout/issues/23
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up conda environment
        uses: mamba-org/setup-micromamba@v1
        with:
          environment-file: ${{env.CONDA_ENV_FILE}}
          environment-name: xarray-tests
          cache-environment: true
          cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}-benchmark"
          # add "build" because of https://github.com/airspeed-velocity/asv/issues/1385
          create-args: >-
            asv
            build
            mamba

      - name: Run benchmarks
        shell: bash -l {0}
        id: benchmark
        env:
          OPENBLAS_NUM_THREADS: 1
          MKL_NUM_THREADS: 1
          OMP_NUM_THREADS: 1
          ASV_FACTOR: 1.5
          ASV_SKIP_SLOW: 1
        run: |
          set -x
          # ID this runner
          asv machine --yes
          echo "Baseline:  ${{ github.event.pull_request.base.sha }} (${{ github.event.pull_request.base.label }})"
          echo "Contender: ${GITHUB_SHA} (${{ github.event.pull_request.head.label }})"
          # Run benchmarks for current commit against base
          ASV_OPTIONS="--split --show-stderr --factor $ASV_FACTOR"
          asv continuous $ASV_OPTIONS ${{ github.event.pull_request.base.sha }} ${GITHUB_SHA} \
              | sed "/Traceback \|failed$\|PERFORMANCE DECREASED/ s/^/::error::/" \
              | tee benchmarks.log
          # Report and export results for subsequent steps
          if grep "Traceback \|failed\|PERFORMANCE DECREASED" benchmarks.log > /dev/null ; then
              exit 1
          fi
        working-directory: ${{ env.ASV_DIR }}

      - name: Add instructions to artifact
        if: always()
        run: |
          cp benchmarks/README_CI.md benchmarks.log .asv/results/
        working-directory: ${{ env.ASV_DIR }}

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: asv-benchmark-results-${{ runner.os }}
          path: ${{ env.ASV_DIR }}/.asv/results


Benchmark compare last release

name: Benchmark compare last release

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  benchmark:
    name: Linux
    runs-on: ubuntu-20.04
    env:
      ASV_DIR: "./asv_bench"
      CONDA_ENV_FILE: ci/requirements/environment.yml

    steps:
      # We need the full repo to avoid this issue
      # https://github.com/actions/checkout/issues/23
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up conda environment
        uses: mamba-org/setup-micromamba@v1
        with:
          environment-file: ${{env.CONDA_ENV_FILE}}
          environment-name: xarray-tests
          cache-environment: true
          cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}-benchmark"
          create-args: >-
            asv

      - name: 'Get Previous tag'
        id: previoustag
        uses: "WyriHaximus/github-action-get-previous-tag@v1"
        # with:
        #   fallback: 1.0.0 # Optional fallback tag to use when no tag can be found

      - name: Run benchmarks
        shell: bash -l {0}
        id: benchmark
        env:
          OPENBLAS_NUM_THREADS: 1
          MKL_NUM_THREADS: 1
          OMP_NUM_THREADS: 1
          ASV_FACTOR: 1.5
          ASV_SKIP_SLOW: 1
        run: |
          set -x
          # ID this runner
          asv machine --yes
          echo "Baseline: ${{ steps.previoustag.outputs.tag }} "
          echo "Contender: ${{ github.sha }}"
          # Use mamba for env creation
          # export CONDA_EXE=$(which mamba)
          export CONDA_EXE=$(which conda)
          # Run benchmarks for current commit against base
          ASV_OPTIONS="--split --show-stderr --factor $ASV_FACTOR"
          asv continuous $ASV_OPTIONS ${{ steps.previoustag.outputs.tag }}  ${{ github.sha }} \
              | sed "/Traceback \|failed$\|PERFORMANCE DECREASED/ s/^/::error::/" \
              | tee benchmarks.log
          # Report and export results for subsequent steps
          if grep "Traceback \|failed\|PERFORMANCE DECREASED" benchmarks.log > /dev/null ; then
              exit 1
          fi
        working-directory: ${{ env.ASV_DIR }}

      - name: Add instructions to artifact
        if: always()
        run: |
          cp benchmarks/README_CI.md benchmarks.log .asv/results/
        working-directory: ${{ env.ASV_DIR }}

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: asv-benchmark-results-${{ runner.os }}
          path: ${{ env.ASV_DIR }}/.asv/results


Upload nightly wheels

name: Upload nightly wheels
on:
  workflow_dispatch:
  schedule:
    - cron: "0 0 * * *"
jobs:
  cron:
    runs-on: ubuntu-latest
    if: github.repository == 'pydata/xarray'
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine

      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build

      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/xarray-0.0.0.tar.gz ]; then
              echo "❌ INVALID VERSION NUMBER"
              exit 1
          else
              echo "✅ Looks good"
          fi

      - name: Upload wheel
        uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0
        with:
          anaconda_nightly_upload_token: ${{ secrets.ANACONDA_NIGHTLY }}
          artifacts_path: dist


Slow Hypothesis CI

name: Slow Hypothesis CI
on:
  push:
    branches:
      - "main"
  pull_request:
    branches:
      - "main"
    types: [opened, reopened, synchronize, labeled]
  schedule:
    - cron: "0 0 * * *" # Daily “At 00:00” UTC
  workflow_dispatch: # allows you to trigger manually

env:
  FORCE_COLOR: 3

jobs:
  detect-ci-trigger:
    name: detect ci trigger
    runs-on: ubuntu-latest
    if: |
      github.repository == 'pydata/xarray'
      && (github.event_name == 'push' || github.event_name == 'pull_request')
    outputs:
      triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2
      - uses: xarray-contrib/ci-trigger@v1
        id: detect-trigger
        with:
          keyword: "[skip-ci]"

  hypothesis:
    name: Slow Hypothesis Tests
    runs-on: "ubuntu-latest"
    needs: detect-ci-trigger
    if: |
        always()
        && (
            needs.detect-ci-trigger.outputs.triggered == 'false'
            && ( (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
                || contains( github.event.pull_request.labels.*.name, 'run-slow-hypothesis'))
        )
    defaults:
      run:
        shell: bash -l {0}

    env:
      CONDA_ENV_FILE: ci/requirements/environment.yml
      PYTHON_VERSION: "3.12"

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Fetch all history for all branches and tags.

      - name: set environment variables
        run: |
          echo "TODAY=$(date  +'%Y-%m-%d')" >> $GITHUB_ENV

      - name: Setup micromamba
        uses: mamba-org/setup-micromamba@v1
        with:
          environment-file: ci/requirements/environment.yml
          environment-name: xarray-tests
          create-args: >-
            python=${{env.PYTHON_VERSION}}
            pytest-reportlog
          cache-environment: true
          cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"

      - name: Install xarray
        run: |
          python -m pip install --no-deps -e .
      - name: Version info
        run: |
          conda info -a
          conda list
          python xarray/util/print_versions.py

      # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
      - name: Restore cached hypothesis directory
        id: restore-hypothesis-cache
        uses: actions/cache/restore@v4
        with:
          path: .hypothesis/
          key: cache-hypothesis-${{ runner.os }}-${{ github.run_id }}
          restore-keys: |
            cache-hypothesis-

      - name: Run slow Hypothesis tests
        if: success()
        id: status
        run: |
           python -m pytest --hypothesis-show-statistics --run-slow-hypothesis properties/*.py \
             --report-log output-${{ matrix.python-version }}-log.jsonl

      # explicitly save the cache so it gets updated, also do this even if it fails.
      - name: Save cached hypothesis directory
        id: save-hypothesis-cache
        if: always() && steps.status.outcome != 'skipped'
        uses: actions/cache/save@v4
        with:
          path: .hypothesis/
          key: cache-hypothesis-${{ runner.os }}-${{ github.run_id }}

      - name: Generate and publish the report
        if: |
          failure()
          && steps.status.outcome == 'failure'
          && github.event_name == 'schedule'
          && github.repository_owner == 'pydata'
        uses: xarray-contrib/issue-from-pytest-log@v1
        with:
          log-path: output-${{ matrix.python-version }}-log.jsonl
          issue-title: "Nightly Hypothesis tests failed"
          issue-label: "topic-hypothesis"


Close stale issues

name: Close stale issues

on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@v1
        with:
          repo-token: ${{ secrets.JINA_DEV_BOT }}
          stale-issue-message: '@jina-ai/product This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days'
          days-before-stale: 90
          days-before-close: 14


CD

name: CD

on:
  push:
    branches:
      - master

#on:
#  push:
#    branches-ignore:
#      - '**'  # temporally ignore all

jobs:
  update-schema:
    if: |
      !startsWith(github.event.head_commit.message, 'chore') &&
      !startsWith(github.event.head_commit.message, 'build: hotfix') &&
      !endsWith(github.event.head_commit.message, 'reformatted by jina-dev-bot')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
#          submodules: true
          fetch-depth: 100
      - run: |
          truncate --size=24KB README.md > README-trunc.md
      - uses: peter-evans/dockerhub-description@v3
        with:
          username: ${{ secrets.DOCKERHUB_DEVBOT_USER  }}
          password: ${{ secrets.DOCKERHUB_DEVBOT_PWD }}
          repository: jinaai/jina
          readme-filepath: ./README-trunc.md
      - uses: actions/checkout@v2.5.0
        with:
          repository: jina-ai/api
          path: schema
          token: ${{ secrets.JINA_DEV_BOT }}
      - uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: |
          pip install . --no-cache-dir
          pip install docarray==0.21.0 # only valid for this version. I think we should remove this schema loading
          JINA_VERSION=$(sed -n '/^__version__/p' ./jina/__init__.py | cut -d \' -f2)-master
          echo "JINA_VERSION=${JINA_VERSION}" >> $GITHUB_ENV
          cd schema
          mkdir -p schemas
          jina export schema --schema-path schemas/"$JINA_VERSION.json" schemas/master.json schemas/master --yaml-path "$JINA_VERSION.yml" master.yml --json-path "$JINA_VERSION.json" master.json master
          python ../scripts/get-openapi-schemas.py
          npm install --prefix ~ snippet-enricher-cli
          ~/node_modules/.bin/snippet-enricher-cli --input=gateway.json --targets=shell_curl > gateway-with-code.json
          cd -
      - name: redoc-cli-gateway
        uses: seeebiii/redoc-cli-github-action@v10
        with:
          args: 'bundle schema/gateway-with-code.json -o rest.html'
      - name: push-to-api-repo
        run: |
          mkdir -p schema/rest/
          cp rest.html schema/rest/master.html
          cp schema/gateway.json schema/rest/master.json
          rm schema/gateway.json schema/gateway-with-code.json
          cd schema
          git config --local user.email "dev-bot@jina.ai"
          git config --local user.name "Jina Dev Bot"
          if [[ `git status --porcelain` ]]; then
            git pull && git add . && git commit -m "update ${{env.JINA_VERSION}} due to ${{github.event_name}} on ${{github.repository}}" && git push
          fi

  update-docker:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: Manual Docker Build
          inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "CD"}'
          token: ${{ secrets.JINA_DEV_BOT }}
        env:
          release_token: ${{ secrets.JINA_CORE_RELEASE_TOKEN }}

  prep-testbed:
    runs-on: ubuntu-latest
    needs: update-schema
    env:
      release_token: ${{ secrets.JINA_CORE_RELEASE_TOKEN }}
    steps:
      - uses: actions/checkout@v2.5.0
      - id: set-matrix
        run: |
          sudo apt-get install jq
          export value=$(bash scripts/get-all-test-paths.sh)
          echo "matrix=$value" >> $GITHUB_OUTPUT
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}

  docarray-v-two-test:
    needs: prep-testbed
    runs-on: ubuntu-latest
    env:
      JINA_RANDOM_PORT_MIN: 16384
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        protobuf-version: ['==3.19.6', '']
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[common,devel,test]" --no-cache-dir
          if [[ "${{ matrix.protobuf-version }}" == "==3.19.6" ]]; then
            pip install -U protobuf${{ matrix.protobuf-version }} grpcio==1.47.5 grpcio-reflection==1.47.5 grpcio-health-checking==1.47.5
          else
            pip install -U protobuf${{ matrix.protobuf-version }}
          fi
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test
        id: test
        run: |
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/unit/serve/runtimes/test_helper.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_v2.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/deployment_http_composite
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_singleton.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_parameters_as_pydantic.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_streaming.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/csp
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/docker
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 45
        env:
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  stateful-docarray-v-two-test:
    needs: prep-testbed
    runs-on: ubuntu-latest
    env:
      JINA_RANDOM_PORT_MIN: 16384
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        protobuf-version: ['==3.19.6', '']
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[common,devel,test]" --no-cache-dir
          if [[ "${{ matrix.protobuf-version }}" == "==3.19.6" ]]; then
            pip install -U protobuf${{ matrix.protobuf-version }} grpcio==1.47.5 grpcio-reflection==1.47.5 grpcio-health-checking==1.47.5
          else
            pip install -U protobuf${{ matrix.protobuf-version }}
          fi
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test stateful
        id: test_stateful
        run: |
          JINA_LOG_LEVEL=DEBUG JINA_RANDOM_PORT_MAX="60535" pytest --suppress-no-test-exit-code --maxfail 1 --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/stateful
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 30
        env:
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  mark-dev-N:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 200

      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}

      - id: computedevdelta
        run: |
          git fetch --depth=200
          LAST_VER=$(git tag -l | sort -V | tail -n1)
          COMMITS_SINCE_LAST_VER=$(git rev-list $LAST_VER..HEAD --count)
          echo "devdelta=$COMMITS_SINCE_LAST_VER" >> $GITHUB_OUTPUT
          INIT_FILE='jina/__init__.py'
          RELEASE_VER=$(sed -n '/^__version__/p' $INIT_FILE | cut -d \' -f2)
          echo "LAST_VER $LAST_VER"
          echo "COMMITS_SINCE_LAST_VER $COMMITS_SINCE_LAST_VER"
          echo "RELEASE_VER $RELEASE_VER"
          echo "devdelta=$COMMITS_SINCE_LAST_VER" >> $GITHUB_OUTPUT
          echo "releasever=$RELEASE_VER" >> $GITHUB_OUTPUT
    outputs:
      devdelta: ${{ steps.computedevdelta.outputs.devdelta }}
      releasever: ${{ steps.computedevdelta.outputs.releasever }}

  # Build the wheels for Linux and macOS for Python 3.8 and newer
  build-wheels:
    runs-on: ${{ matrix.os }}
    needs: [mark-dev-N]
    strategy:
      # Ensure that a wheel builder finishes even if another fails
      fail-fast: false
      matrix:
        include:
          # linux
          - os: ubuntu-latest
            python: '3.7'
            python-manylinux-tag: "cp37-cp37m"
          - os: ubuntu-latest
            python: '3.8'
            python-manylinux-tag: "cp38-cp38"
          - os: ubuntu-latest
            python: '3.9'
            python-manylinux-tag: "cp39-cp39"
          - os: ubuntu-latest
            python: '3.10'
            python-manylinux-tag: "cp310-cp310"
          - os: ubuntu-latest
            python: '3.11'
            python-manylinux-tag: "cp311-cp311"

          # MacOS emulated
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64

          # MacOS native
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}

      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Update version
        run: |
          DEVDELTA=${{needs.mark-dev-N.outputs.devdelta}}
          RELEASE_VER=${{needs.mark-dev-N.outputs.releasever}}
          INIT_FILE='jina/__init__.py'
          DEV_VER=$RELEASE_VER".dev"$DEVDELTA
          echo "DEVDELTA $DEVDELTA"
          echo "RELEASE_VER $RELEASE_VER"
          echo "DEV_VER $DEV_VER"
          if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
            sed -i '' '/'"${RELEASE_VER}"'/s/.*/'"__version__ = '${DEV_VER}'"'/' "${INIT_FILE}"
          else
            sed -i '/'"${RELEASE_VER}"'/s/.*/'"__version__ = '${DEV_VER}'"'/' "${INIT_FILE}"
          fi

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: |
          setuptools-golang-build-manylinux-wheels --pythons ${{ matrix.python-manylinux-tag }}

      - name: Build wheels with cibuildwheels on macos
        env:
          CIBW_BUILD: cp${{ matrix.python-cibuildwheels }}-${{ matrix.platform_id }}
          CIBW_ARCHS: ${{ matrix.arch }}
          CIBW_TEST_COMMAND: python -c "import jina; import jraft"
          CIBW_BUILD_VERBOSITY: 1
          GOARCH: ${{ matrix.goarch }}
          CGO_ENABLED: 1
        if: ${{ matrix.os == 'macos-latest' }}
        run: |
          python -m cibuildwheel --output-dir dist

      - name: Upload wheels as artifacts
        uses: actions/upload-artifact@v2
        with:
          path: dist/*.whl

# comment for now, do it manually if needed
  # pre-release:
  #   if: |
  #     !startsWith(github.event.head_commit.message, 'chore') &&
  #     !startsWith(github.event.head_commit.message, 'build: hotfix') &&
  #     !endsWith(github.event.head_commit.message, 'reformatted by jina-dev-bot')
  #   needs: [build-wheels, mark-dev-N]
  #   runs-on: ubuntu-latest
  #   steps:
  #     - uses: actions/checkout@v2.5.0
  #       with:
  #         #          submodules: true
  #         fetch-depth: 100
  #     - run: |
  #         truncate --size=24KB README.md > README-trunc.md
  #     - uses: actions/download-artifact@v3
  #       with:
  #         name: artifact
  #         path: dist

  #     - name: Update version
  #       run: |
  #         DEVDELTA=${{needs.mark-dev-N.outputs.devdelta}}
  #         RELEASE_VER=${{needs.mark-dev-N.outputs.releasever}}
  #         INIT_FILE='jina/__init__.py'
  #         DEV_VER=$RELEASE_VER".dev"$DEVDELTA
  #         echo "DEVDELTA $DEVDELTA"
  #         echo "RELEASE_VER $RELEASE_VER"
  #         echo "DEV_VER $DEV_VER"
  #         sed -i '/'"${RELEASE_VER}"'/s/.*/'"__version__ = '${DEV_VER}'"'/' "${INIT_FILE}"
  #     - name: Pre-release (.devN)
  #       run: |
  #         pip install twine wheel
  #         ./scripts/release.sh
  #       env:
  #         TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
  #         TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
  #         JINA_SLACK_WEBHOOK: ${{ secrets.JINA_SLACK_WEBHOOK }}

  core-test:
    needs: prep-testbed
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        test-path: ${{fromJson(needs.prep-testbed.outputs.matrix)}}
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test
        id: test
        run: |
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/docarray_v2/*' --ignore-glob='tests/integration/stateful/*' --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 30
        env:
          JINAHUB_USERNAME: ${{ secrets.JINAHUB_USERNAME }}
          JINAHUB_PASSWORD: ${{ secrets.JINAHUB_PASSWORD }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check file existence
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  import-test:
    runs-on: ubuntu-latest
    needs: update-schema
    strategy:
      fail-fast: false
      matrix:
        core: ['', 'true']
        perf: ['', 'true']
        python-env: ['3.7', '3.8', '3.9', '3.10', '3.11']
        exclude:
          - core: 'true'
            perf: 'true'
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-env }}
      - name: Prepare enviroment
        run: |
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install --no-cache-dir .
        env:
          JINA_PIP_INSTALL_CORE: ${{ matrix.core }}
          JINA_PIP_INSTALL_PERF: ${{ matrix.perf }}
      - name: Test basic import
        run: python -c 'from jina import Executor,requests,Client,Flow,dynamic_batching,Document,DocumentArray'
  docker-image-test:
    needs: update-schema
    runs-on: ubuntu-latest
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000
    strategy:
      fail-fast: false
      matrix:
        test-arch: ["linux/amd64", "linux/arm64"]
    steps:
      #      - name: Cancel Previous Runs
      #        uses: styfle/cancel-workflow-action@0.9.0
      #        with:
      #          access_token: ${{ github.token }}
      - uses: actions/checkout@v2.5.0
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          install: true
          driver-opts: network=host
      - run: |
          docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
          docker run --rm --privileged tonistiigi/binfmt --install all
      - name: Build and test
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfiles/debianx.Dockerfile
          platforms: ${{ matrix.test-arch }}
          push: true
          tags: localhost:5000/jina/multiarch:latest
          target: jina
      - run: |
          docker run --platform ${{ matrix.test-arch }} localhost:5000/jina/multiarch:latest -v

  hub-test:
    needs: update-schema
    runs-on: ubuntu-latest
    if: ${{ !github.event.pull_request.head.repo.fork }}
    steps:
      #      - name: Cancel Previous Runs
      #        uses: styfle/cancel-workflow-action@0.9.0
      #        with:
      #          access_token: ${{ github.token }}
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Test hubapp with hubpods
        run: |
          ./tests/jinahub/test_integration.sh
        timeout-minutes: 30
        env:
          JINAHUB_USERNAME: ${{ secrets.JINAHUB_USERNAME }}
          JINAHUB_PASSWORD: ${{ secrets.JINAHUB_PASSWORD }}

  k8s-flow-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s Flow
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_flow.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-deployment-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s Deployment
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-graceful-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test graceful request handling on k8s
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_graceful_request_handling.py
        timeout-minutes: 45
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-failures-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s failures
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          curl --proto '=https' --tlsv1.2 -sSfL https://linkerd.github.io/linkerd-smi/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_failures.py
        timeout-minutes: 45
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-otel-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test K8s with OpenTelemetry
        run: |
          pytest -v -s --cov=jina --cov-report=xml ./tests/k8s_otel
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  docker-compose-test:
    needs: update-schema
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test docker compose
        run: |
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  benchmark-pre-release:
    runs-on: ubuntu-latest
    needs: [update-schema, mark-dev-N]
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          fetch-depth: 200
      - run: |
          DEVDELTA=${{needs.mark-dev-N.outputs.devdelta}}
          RELEASE_VER=${{needs.mark-dev-N.outputs.releasever}}
          NEXT_VER=$RELEASE_VER".dev"$COMMITS_SINCE_LAST_VER
          echo "NEXT_VER=$NEXT_VER" >> $GITHUB_ENV
      - uses: benc-uk/workflow-dispatch@v1
        with:
          token: ${{ secrets.JINA_DEV_BOT }}
          workflow: Benchmark Jina
          repo: jina-ai/jina-terraform
          ref: "main"
          inputs: '{ "pypi_releases": "[\"${{ env.NEXT_VER }}\"]"}'
  # just for blocking the merge until all parallel core-test are successful
  success-all-steps:
    runs-on: ubuntu-latest
    needs: [core-test, docarray-v-two-test, stateful-docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-deployment-test, k8s-graceful-test, k8s-failures-test, k8s-otel-test, docker-compose-test, docker-image-test, benchmark-pre-release, update-schema, update-docker] #, pre-release]
    if: always()
    steps:
      - uses: technote-space/workflow-conclusion-action@v2
      - name: Check Failure
        if: env.WORKFLOW_CONCLUSION == 'failure'
        run: exit 1
      - name: Success
        if: ${{ success() }}
        run: echo "All Done"


CI

name: CI

on:
  pull_request:
    paths-ignore:
      - 'docs/**'
      - 'README.md'

#on:
#  push:
#    branches-ignore:
#      - '**'  # temporally ignore all
jobs:
  commit-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          fetch-depth: 0
      - uses: wagoid/commitlint-github-action@v4

  lint-flake-8:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Lint with flake8
        run: |
          pip install flake8
          # stop the build if there are Python syntax errors or undefined names
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist,tests/,jina/resources/,jina/proto/docarray_v1,jina/proto/docarray_v2,jina/serve/consensus/add_voter/pb,jina/serve/consensus/add_voter/pb2
          # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
          flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist,tests/,jina/proto/docarray_v1,jina/proto/docarray_v2,jina/serve/consensus/add_voter/pb,jina/serve/consensus/add_voter/pb2

  check-docstring:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          fetch-depth: 0
      - name: Set up Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - id: file_changes
        uses: Ana06/get-changed-files@v1.2
      - name: docstring check with darglint and pydocstyle
        run: ./scripts/docstrings_lint.sh
        env:
          CHANGED_FILES: ${{ steps.file_changes.outputs.added_modified }}

  check-black:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          fetch-depth: 0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - id: file_changes
        uses: Ana06/get-changed-files@v1.2
      - name: check black
        run: ./scripts/black.sh
        env:
          CHANGED_FILES: ${{ steps.file_changes.outputs.added_modified }}

  code-injection:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        if: ${{ !github.event.pull_request.head.repo.fork }}
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        if: ${{ !github.event.pull_request.head.repo.fork }}
        with:
          python-version: 3.8
      - name: Styling
        id: styling
        if: ${{ !github.event.pull_request.head.repo.fork }}
        run: |
          git config --local user.email "dev-bot@jina.ai"
          git config --local user.name "Jina Dev Bot"
          pip install ".[devel,black]"
          pip install setuptools
          cd scripts && bash ./devbot.sh && cd -
          if [[ -z $(git status -s) ]]
          then
            echo "tree is clean"
          else
            git add -u
            git commit -m "style: fix overload and cli autocomplete"
            echo "IS_CHANGED=YES" >> $GITHUB_OUTPUT
          fi
      - name: Push changes to head ref
        uses: ad-m/github-push-action@v0.6.0
        if: ${{ !github.event.pull_request.head.repo.fork }}
        with:
          github_token: ${{ secrets.JINA_DEV_BOT }}
          branch: ${{ github.head_ref }}
      - name: Fail this pipelint
        if: ${{ steps.styling.outputs.IS_CHANGED == 'YES' && !github.event.pull_request.head.repo.fork }}
        run: exit 1

  docker-image-test:
    needs: [code-injection]
    runs-on: ubuntu-latest
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000
    strategy:
      fail-fast: false
      matrix:
        test-arch: ["linux/amd64", "linux/arm64"]
    steps:
#      - name: Cancel Previous Runs
#        uses: styfle/cancel-workflow-action@0.9.0
#        with:
#          access_token: ${{ github.token }}
      - uses: actions/checkout@v2.5.0
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          install: true
          driver-opts: network=host
      - run: |
          docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
          docker run --rm --privileged tonistiigi/binfmt --install all
      - name: Build and test
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfiles/debianx.Dockerfile
          platforms: ${{ matrix.test-arch }}
          push: true
          tags: localhost:5000/jina/multiarch:latest
          target: jina
      - run: |
          docker run --platform ${{ matrix.test-arch }} localhost:5000/jina/multiarch:latest -v

  hub-test:
    runs-on: ubuntu-latest
    needs: [lint-flake-8, code-injection]
    if: ${{ !github.event.pull_request.head.repo.fork }}
    steps:
#      - name: Cancel Previous Runs
#        uses: styfle/cancel-workflow-action@0.9.0
#        with:
#          access_token: ${{ github.token }}
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Test hubapp with hubpods
        run: |
          ./tests/jinahub/test_integration.sh
        timeout-minutes: 30
        env:
          JINAHUB_USERNAME: ${{ secrets.JINAHUB_USERNAME }}
          JINAHUB_PASSWORD: ${{ secrets.JINAHUB_PASSWORD }}

  k8s-flow-test:
    needs: [lint-flake-8, code-injection]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s Flow
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_flow.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-deployment-test:
    needs: [lint-flake-8, code-injection]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s Deployment
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-graceful-test:
    needs: [lint-flake-8, code-injection]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test graceful request handling on k8s
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_graceful_request_handling.py
        timeout-minutes: 45
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-failures-test:
    needs: [ lint-flake-8, code-injection ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test k8s failures
        run: |
          export LINKERD2_VERSION=stable-2.11.4
          curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
          curl --proto '=https' --tlsv1.2 -sSfL https://linkerd.github.io/linkerd-smi/install | sh
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_failures.py
        timeout-minutes: 45
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  k8s-otel-test:
    needs: [lint-flake-8, code-injection]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
          curl -LO https://dl.k8s.io/release/v1.21.1/bin/linux/amd64/kubectl
          sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test K8s with OpenTelemetry
        run: |
          pytest -v -s --cov=jina --cov-report=xml ./tests/k8s_otel
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  docker-compose-test:
    needs: [lint-flake-8, code-injection]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install ".[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Test docker compose
        run: |
          pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
        timeout-minutes: 30
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  prep-testbed:
    runs-on: ubuntu-latest
    needs: [ lint-flake-8, code-injection]
    steps:
      - uses: actions/checkout@v2.5.0
      - id: set-matrix
        run: |
          sudo apt-get install jq
          export value=$(bash scripts/get-all-test-paths.sh)
          echo "matrix=$value" >> $GITHUB_OUTPUT
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}

  docarray-v-two-test:
    needs: prep-testbed
    runs-on: ubuntu-latest
    env:
      JINA_RANDOM_PORT_MIN: 16384
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        protobuf-version: ['==3.19.6', '']
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[common,devel,test]" --no-cache-dir
          if [[ "${{ matrix.protobuf-version }}" == "==3.19.6" ]]; then
            pip install -U protobuf${{ matrix.protobuf-version }} grpcio==1.47.5 grpcio-reflection==1.47.5 grpcio-health-checking==1.47.5
          else
            pip install -U protobuf${{ matrix.protobuf-version }}
          fi
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test
        id: test
        run: |
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/unit/serve/runtimes/test_helper.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_v2.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/deployment_http_composite
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_singleton.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_parameters_as_pydantic.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/test_streaming.py
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/csp
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/docarray_v2/docker
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 45
        env:
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  stateful-docarray-v-two-test:
    needs: prep-testbed
    runs-on: ubuntu-latest
    env:
      JINA_RANDOM_PORT_MIN: 16384
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        protobuf-version: ['==3.19.6', '']
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[common,devel,test]" --no-cache-dir
          if [[ "${{ matrix.protobuf-version }}" == "==3.19.6" ]]; then
            pip install -U protobuf${{ matrix.protobuf-version }} grpcio==1.47.5 grpcio-reflection==1.47.5 grpcio-health-checking==1.47.5
          else
            pip install -U protobuf${{ matrix.protobuf-version }}
          fi
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test stateful
        id: test_stateful
        run: |
          JINA_LOG_LEVEL=DEBUG JINA_RANDOM_PORT_MAX="60535" pytest --suppress-no-test-exit-code --maxfail 1 --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/integration/stateful
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 30
        env:
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  # Build the wheels for Linux and macOS for Python 3.8 and newer
  build-wheels:
    runs-on: ${{ matrix.os }}
    strategy:
      # Ensure that a wheel builder finishes even if another fails
      fail-fast: false
      matrix:
        include:
          # linux
          - os: ubuntu-latest
            python: '3.7'
            python-manylinux-tag: "cp37-cp37m"
          - os: ubuntu-latest
            python: '3.8'
            python-manylinux-tag: "cp38-cp38"
          - os: ubuntu-latest
            python: '3.9'
            python-manylinux-tag: "cp39-cp39"
          - os: ubuntu-latest
            python: '3.10'
            python-manylinux-tag: "cp310-cp310"
          - os: ubuntu-latest
            python: '3.11'
            python-manylinux-tag: "cp311-cp311"

          # MacOS emulated
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64

          # MacOS native
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64

    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}

      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: |
          setuptools-golang-build-manylinux-wheels --pythons ${{ matrix.python-manylinux-tag }}

      - name: Build wheels with cibuildwheels on macos
        env:
          CIBW_BUILD: cp${{ matrix.python-cibuildwheels }}-${{ matrix.platform_id }}
          CIBW_ARCHS: ${{ matrix.arch }}
          CIBW_TEST_COMMAND: python -c "import jina; import jraft"
          CIBW_BUILD_VERBOSITY: 1
          GOARCH: ${{ matrix.goarch }}
          CGO_ENABLED: 1
        if: ${{ matrix.os == 'macos-latest' }}
        run: |
          python -m cibuildwheel --output-dir dist

      - name: Upload wheels as artifacts
        uses: actions/upload-artifact@v2
        with:
          path: dist/*.whl

  core-test:
    needs: [prep-testbed]
    runs-on: ubuntu-latest
    env:
      JINA_RANDOM_PORT_MIN: 16384
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.8]
        test-path: ${{fromJson(needs.prep-testbed.outputs.matrix)}}
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        run: |
          setuptools-golang-build-manylinux-wheels --pythons cp38-cp38
      - name: Prepare environment
        run: |
          docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
          python -m pip install --upgrade pip
          python -m pip install wheel
          WHEEL_FILE=$(ls dist/*whl)
          pip install "$WHEEL_FILE[all]" --no-cache-dir
          pip install docarray==0.21.0
          jina
          export JINA_LOG_LEVEL="ERROR"
      - name: Test
        id: test
        run: |
          pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/docarray_v2/*' --ignore-glob='tests/integration/stateful/*' --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}
          if [[ "${{ matrix.test-path }}" == *"tests/integration/instrumentation/" ]]
          then
            echo "sleeping to let open telemetry export daemon thread expire by itself"
            sleep 2
          fi
          echo "flag it as jina for codeoverage"
          echo "codecov_flag=jina" >> $GITHUB_OUTPUT
        timeout-minutes: 30
        env:
          JINA_AUTH_TOKEN: "${{ secrets.JINA_AUTH_TOKEN }}"
      - name: Check codecov file
        id: check_files
        uses: andstor/file-existence-action@v1
        with:
          files: "coverage.xml"
      - name: Upload coverage from test to Codecov
        uses: codecov/codecov-action@v3.1.1
        if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
        with:
          file: coverage.xml
          name: ${{ matrix.test-path }}-codecov
          flags: ${{ steps.test.outputs.codecov_flag }}
          fail_ci_if_error: false

  import-test:
    runs-on: ubuntu-latest
    needs: [lint-flake-8, code-injection ]
    strategy:
      fail-fast: false
      matrix:
        core: ['', 'true']
        perf: ['', 'true']
        python-env: ['3.7', '3.8', '3.9', '3.10', '3.11']
        exclude:
          - core: 'true'
            perf: 'true'
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Prepare enviroment
        run: |
          python -m pip install --upgrade pip
          python -m pip install wheel
          pip install --no-cache-dir .
        env:
          JINA_PIP_INSTALL_CORE: ${{ matrix.core }}
          JINA_PIP_INSTALL_PERF: ${{ matrix.perf }}
      - name: Test basic import
        run: python -c 'from jina import Executor,requests,Client,Flow,dynamic_batching,Document,DocumentArray'
      - name: Test import all
        run: python -c 'from jina import *'

  install-jina-ecosystem-test:
    runs-on: ubuntu-latest
    needs: [lint-flake-8, code-injection ]
    strategy:
      fail-fast: false
    steps:
      - uses: actions/checkout@v2.5.0
      - name: Set up Python 3.8
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Prepare enviroment
        run: |
          python -m pip install --upgrade pip
          python -m pip install wheel

          HUBBLE_VERSION=$(curl -L -s "https://pypi.org/pypi/jina-hubble-sdk/json" |  jq  -r '.releases | keys | .[]| select(startswith("0."))'  | sort -V | tail -1)
          DOCARRAY_VERSION=$(curl -L -s "https://pypi.org/pypi/docarray/json" |  jq  -r '.releases | keys | .[]| select(startswith("0."))'  | sort -V | tail -1)
          JCLOUD_VERSION=$(curl -L -s "https://pypi.org/pypi/jcloud/json" |  jq  -r '.releases | keys | .[]| select(startswith("0."))'  | sort -V | tail -1)

          pip install . jcloud==$JCLOUD_VERSION docarray==$DOCARRAY_VERSION jina-hubble-sdk==$HUBBLE_VERSION
        env:
          JINA_PIP_INSTALL_CORE: ${{ matrix.core }}
          JINA_PIP_INSTALL_PERF: ${{ matrix.perf }}

      - name: Test basic import
        run: python -c 'from jina import Executor,requests'
      - name: Test import all
        run: python -c 'from jina import *'

  # just for blocking the merge until all parallel core-test are successful
  success-all-test:
    runs-on: ubuntu-latest
    needs: [commit-lint, core-test, docarray-v-two-test, stateful-docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-deployment-test, k8s-graceful-test, k8s-failures-test, k8s-otel-test, docker-compose-test, docker-image-test, check-docstring, check-black, code-injection, build-wheels]

    if: always()
    steps:
      - uses: technote-space/workflow-conclusion-action@v2
      - name: Check Failure
        if: env.WORKFLOW_CONCLUSION == 'failure'
        run: exit 1
      - name: Success
        if: ${{ success() }}
        run: echo "All Done"


Release CD

name: Release CD

on:
  push:
    tags:
      - "v*"  # push to version tags trigger the build

#on:
#  push:
#    branches-ignore:
#      - '**'  # temporally disable this action

jobs:
  update-schema:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
      - uses: actions/checkout@v2.5.0
        with:
          repository: jina-ai/api
          path: schema
          token: ${{ secrets.JINA_DEV_BOT }}
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: |
          JINA_VERSION=${GITHUB_REF/refs\/tags\/v/}
          JINA_MINOR_VERSION=${JINA_VERSION%.*}
          V_JINA_VERSION=${GITHUB_REF/refs\/tags\//}
          echo "JINA_VERSION=${JINA_VERSION}" >> $GITHUB_ENV
          echo "V_JINA_VERSION=${V_JINA_VERSION}" >> $GITHUB_ENV
          echo "JINA_MINOR_VERSION=${JINA_MINOR_VERSION}" >> $GITHUB_ENV
          pip install . --no-cache-dir
          cd schema
          mkdir -p schemas
          jina export schema --schema-path schemas/"$JINA_VERSION.json" schemas/latest.json schemas/latest --yaml-path "$JINA_VERSION.yml" latest.yml --json-path "$JINA_VERSION.json" latest.json latest
          python ../scripts/get-openapi-schemas.py
          npm install --prefix ~ snippet-enricher-cli
          ~/node_modules/.bin/snippet-enricher-cli --input=gateway.json --targets=shell_curl > gateway-with-code.json
          cd -
      - name: redoc-cli-gateway
        uses: seeebiii/redoc-cli-github-action@v10
        with:
          args: 'bundle schema/gateway-with-code.json -o rest.html'
      - name: push-to-api-repo
        run: |
          mkdir -p schema/rest/
          cp rest.html schema/rest/index.html
          cp rest.html schema/rest/${{env.JINA_VERSION}}.html
          cp rest.html schema/rest/latest.html
          cp schema/gateway.json schema/rest/${{env.JINA_VERSION}}.json
          cp schema/gateway.json schema/rest/latest.json
          rm schema/gateway.json schema/gateway-with-code.json
          cd schema
          git config --local user.email "dev-bot@jina.ai"
          git config --local user.name "Jina Dev Bot"
          git add . && git commit -m "update ${{env.JINA_VERSION}} due to ${{github.event_name}} on ${{github.repository}}" && git push

  update-doc:
    runs-on: ubuntu-latest
    steps:
      - uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: Manual Docs Build
          token: ${{ secrets.JINA_DEV_BOT }}
          inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "TAG", "build_old_docs": "TRUE"}'
        env:
          release_token: ${{ secrets.JINA_CORE_RELEASE_TOKEN }}

  update-docker:
    needs: update-doc
    runs-on: ubuntu-latest
    steps:
      - uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: Manual Docker Build
          token: ${{ secrets.JINA_DEV_BOT }}
          inputs: '{ "release_token": "${{ env.release_token }}", "triggered_by": "TAG"}'
        env:
          release_token: ${{ secrets.JINA_CORE_RELEASE_TOKEN }}

  create-release:
    needs: update-doc
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2.5.0
        with:
          ref: 'master'
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - run: |
          python scripts/get-last-release-note.py
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
        with:
          tag_name: ${{ github.ref }}
          release_name: 💫 Patch ${{ github.ref }}
          body_path: 'tmp.md'
          draft: false
          prerelease: false


CLA

name: CLA

on:
  push:
    branches-ignore:
      - '**'  # temporally ignore all

jobs:
  cla-check:
    runs-on: ubuntu-latest
    steps:
      - name: "CLA Assistant"
        if: (github.event.comment.body == 'recheckcla' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
        # Alpha Release
        uses: cla-assistant/github-action@v2.1.3-beta
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # the below token should have repo scope and must be manually added by you in the repository's secret
          PERSONAL_ACCESS_TOKEN: ${{ secrets.CLA_TOKEN }}
        with:
          path-to-signatures: '.github/signatures/v1/cla.json'
          path-to-document: 'https://github.com/jina-ai/jina/blob/master/.github/CLA.md'
          branch: 'cla'
          allowlist: jina-bot
          signed-commit-message: '$contributorName has signed the CLA in #$pullRequestNo'


Manual Release

name: Manual Release

on:
  workflow_dispatch:
    inputs:
      release_token:
        description: 'Your release token'
        required: true
      release_reason:
        description: 'Short reason for this manual release'
        required: true

jobs:
  token-check:
    runs-on: ubuntu-latest
    steps:
      - name: Check release token
        id: token-check
        run: |
          touch SUCCESS
        if: inputs.release_token == env.release_token
        env:
          release_token: ${{ secrets.JINA_CORE_RELEASE_TOKEN }}
      - name: Fail release token
        run: |
          [[ -f SUCCESS ]]

  # Build the wheels for Linux, Windows and macOS for Python 3.8 and newer
  build-wheels:
    runs-on: ${{ matrix.os }}
    strategy:
      # Ensure that a wheel builder finishes even if another fails
      fail-fast: false
      matrix:
        include:
          # linux
          - os: ubuntu-latest
            python: '3.7'
            python-manylinux-tag: "cp37-cp37m"
          - os: ubuntu-latest
            python: '3.8'
            python-manylinux-tag: "cp38-cp38"
          - os: ubuntu-latest
            python: '3.9'
            python-manylinux-tag: "cp39-cp39"
          - os: ubuntu-latest
            python: '3.10'
            python-manylinux-tag: "cp310-cp310"
          - os: ubuntu-latest
            python: '3.11'
            python-manylinux-tag: "cp311-cp311"

          # MacOS emulated
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_x86_64
            arch: x86_64
            goarch: amd64

          # MacOS native
          - os: macos-latest
            python: '3.8'
            python-cibuildwheels: '38'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.9'
            python-cibuildwheels: '39'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.10'
            python-cibuildwheels: '310'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64
          - os: macos-latest
            python: '3.11'
            python-cibuildwheels: '311'
            platform_id: macosx_arm64
            arch: arm64
            goarch: arm64

    steps:
      - name: Check out repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 200

      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python }}

      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.5

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel
          pip install git+https://github.com/jina-ai/setuptools-golang.git@feat-align-with-alaeddine-code
          pip install cibuildwheel

      - name: Build wheels with setuptools-golang-build-manylinux-wheel
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: |
          setuptools-golang-build-manylinux-wheels --pythons ${{ matrix.python-manylinux-tag }}
      - name: Build wheels with cibuildwheels on macos
        env:
          CIBW_BUILD: cp${{ matrix.python-cibuildwheels }}-${{ matrix.platform_id }}
          CIBW_ARCHS: ${{ matrix.arch }}
          CIBW_TEST_COMMAND: python -c "import jina; import jraft"
          CIBW_BUILD_VERBOSITY: 1
          GOARCH: ${{ matrix.goarch }}
          CGO_ENABLED: 1
        if: ${{ matrix.os == 'macos-latest' }}
        run: |
          python -m cibuildwheel --output-dir dist

      - name: Upload wheels as artifacts
        uses: actions/upload-artifact@v2
        with:
          path: dist/*.whl

  regular-release:
    needs: [token-check, build-wheels]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          token: ${{ secrets.JINA_DEV_BOT }}
          fetch-depth: 100  # means max contribute history is limited to 100 lines
#          submodules: true
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
        # https://github.com/actions/checkout#fetch-all-tags
      - uses: actions/download-artifact@v3
        with:
          name: artifact
          path: dist
      - run: |
          git fetch --depth=200
          npm install git-release-notes
          pip install twine wheel
          ./scripts/release.sh final "${{ github.event.inputs.release_reason }}" "${{github.actor}}"
        env:
          env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
          JINA_SLACK_WEBHOOK: ${{ secrets.JINA_SLACK_WEBHOOK }}
      - if: failure()
        run: echo "nothing to release"
      - name: bumping master version
        uses: ad-m/github-push-action@v0.6.0
        with:
          github_token: ${{ secrets.JINA_DEV_BOT }}
          tags: true
          branch: ${{ github.ref }}


PR

name: PR

on:
  pull_request:

jobs:
  assign-label-to-pr:
    runs-on: ubuntu-latest
    if: ${{ !github.event.pull_request.head.repo.fork }}
    steps:
      - uses: codelytv/pr-size-labeler@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          xs_max_size: '10'
          s_max_size: '100'
          m_max_size: '500'
          l_max_size: '1000'
          fail_if_xl: 'false'
      - uses: actions/labeler@v3
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
      - id: docs_updated
        if: contains( github.event.pull_request.labels.*.name, 'area/docs')
        run: echo "docs=true" >> $GITHUB_OUTPUT
    outputs:
      docs: ${{ steps.docs_updated.outputs.docs }}

  deploy-to-netlify:
    runs-on: ubuntu-latest
    needs: [assign-label-to-pr]
    if: ${{ needs.assign-label-to-pr.outputs.docs == 'true' }}
    steps:
      - run: |
          echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
      - uses: actions/checkout@v2.5.0
        with:
          repository: jina-ai/jina
          ref: ${{ env.BRANCH_NAME }}
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Build and Deploy
        timeout-minutes: 30
        run: |
          npm i -g netlify-cli
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          git fetch origin
          export NUM_RELEASES=2 # only 2 last tags to save build time
          bash makedoc.sh local-only
          netlify deploy --dir=./_build/dirhtml --alias=${{ env.BRANCH_NAME }} --message="Deploying docs to ${{ env.BRANCH_NAME }} branch"
        env:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
        working-directory: docs
      - name: Find the prev comment if exists
        uses: peter-evans/find-comment@v1
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: 'Docs are deployed'
      - name: Delete comment if exists
        if: ${{ steps.fc.outputs.comment-id != 0 && !github.event.pull_request.head.repo.fork }}
        uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.issues.deleteComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              comment_id: ${{ steps.fc.outputs.comment-id }},
            })
      - name: Add or update comment
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            :memo: Docs are deployed on https://${{ env.BRANCH_NAME }}--jina-docs.netlify.app :tada:


name: issue-hf2020

#on:
#  issues:
#    types: [opened]
#  pull_request_target:
#    types: [opened]

on:
  push:
    branches-ignore:
      - '**'  # temporally ignore all

jobs:
  automate-issues-labels:
    runs-on: ubuntu-latest
    steps:
      - name: hacktoberfest
        uses: andymckay/labeler@master
        with:
          add-labels: "hacktoberfest, hacktoberfest2020"
          repo-token: "${{ secrets.JINA_DEV_BOT }}"


Autocommit

name: Autocommit

on:
  schedule:
    - cron: "0 23 * * *"
  workflow_dispatch:

jobs:
  autocommit:
    if: |
      !startsWith(github.event.head_commit.message, 'chore') &&
      !startsWith(github.event.head_commit.message, 'build: hotfix') &&
      !endsWith(github.event.head_commit.message, 'reformatted by jina-dev-bot')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.5.0
        with:
          token: ${{ secrets.JINA_DEV_BOT }}
          ref: ${{ github.event.pull_request.head.sha }}
      - run: |
          git config --local user.email "dev-bot@jina.ai"
          git config --local user.name "Jina Dev Bot"
      - uses: actions/setup-python@v4
        with:
          python-version: 3.7
      - name: Generate TOC
        uses: technote-space/toc-generator@v3
        with:
          MAX_HEADER_LEVEL: 2
          GITHUB_TOKEN: ${{ secrets.JINA_DEV_BOT }}
          COMMIT_NAME: Jina Dev Bot
          COMMIT_EMAIL: dev-bot@jina.ai
          TOC_TITLE: ''
          TARGET_PATHS: 'CHANGELOG.md,CONTRIBUTING.md,RELEASE.md'
          CHECK_ONLY_DEFAULT_BRANCH: true
      - uses: ad-m/github-push-action@v0.6.0
        with:
          github_token: ${{ secrets.JINA_DEV_BOT }}
          branch: master


PR

# commit-lint needs "pull_request_target" access,
# therefore separate from main ci.yml
name: PR

on:
  push:
    branches-ignore:
      - '**'  # temporally ignore all, as https://github.com/wagoid/commitlint-github-action/issues/66

jobs:
  commit-lint-check:
    runs-on: ubuntu-latest
    steps:
      - name: find the prev warning if exist
        uses: peter-evans/find-comment@v1
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: 'bad commit message'
      - name: Delete comment if exist
        if: ${{ steps.fc.outputs.comment-id != 0 }}
        uses: actions/github-script@v3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.issues.deleteComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              comment_id: ${{ steps.fc.outputs.comment-id }},
            })
      - uses: actions/checkout@v2.5.0
        with:
          fetch-depth: 0
      - run: "echo \"module.exports = {extends: ['@commitlint/config-conventional']}\" > commitlint.config.js"
      - uses: wagoid/commitlint-github-action@v1
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
      - name: if lint failed
        if: ${{ failure() }}
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            Thanks for your contribution :heart:
            :broken_heart: Unfortunately, this PR has one ore more **bad commit messages**, it can not be merged. To fix this problem, please refer to:
            - [Commit Message Guideline for the First Time Contributor](https://github.com/jina-ai/jina/issues/553)
            - [Contributing Guideline](https://github.com/jina-ai/jina/blob/master/CONTRIBUTING.md)

            Note, other CI tests will *not* *start* until the commit messages get fixed.

            This message will be deleted automatically when the commit messages get fixed.
          reaction-type: "eyes"