Repository: ClearcodeHQ/pytest-elasticsearch (language: python)

Issue:
Check if setting up elasticsearch with ankane/setup-elasticsearch will allow to run CI correctly
https://github.com/ankane/setup-elasticsearch


Discussion / hints:

Fix patch:
diff --git a/.install-elasticsearch.sh b/.install-elasticsearch.sh
deleted file mode 100755
index d557d115..00000000
--- a/.install-elasticsearch.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash -v
-function install_from_zip {
-  INSTALL_PATH=$HOME/es/$2
-  echo $INSTALL_PATH
-  if [ ! -d "$INSTALL_PATH" ]; then
-    wget -nv $1 -O out
-    unzip out
-    mv $2 $INSTALL_PATH
-  fi
-  $INSTALL_PATH/bin/elasticsearch -Vv
-  remove_if_erroneus $INSTALL_PATH
-  rm out
-}
-
-function install_from_targz {
-  INSTALL_PATH=$HOME/es/$2
-  echo $INSTALL_PATH
-  if [ ! -d "$INSTALL_PATH" ]; then
-    wget -nv $1 -O out
-    mkdir $2
-    tar -zxf out -C $2 --strip-components 1
-    mv $2 $INSTALL_PATH
-  fi
-  $INSTALL_PATH/bin/elasticsearch -Vv
-  remove_if_erroneus $INSTALL_PATH
-}
-
-function remove_if_erroneus {
-  if [ ! -f "$1/bin/elasticsearch" ]; then
-    rm -rv $1
-  fi
-}
-
-if [ ! -f "$HOME/es" ]; then
-  mkdir $HOME/es
-fi
-
-install_from_zip https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.18.zip elasticsearch-6.8.18
-install_from_targz https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.2-linux-x86_64.tar.gz elasticsearch-7.14
-install_from_targz https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.2-linux-x86_64.tar.gz elasticsearch-7.15
-install_from_targz https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.2-linux-x86_64.tar.gz elasticsearch-7.16
-install_from_targz https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.0-linux-x86_64.tar.gz elasticsearch-7.17
-install_from_targz https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.0-linux-x86_64.tar.gz elasticsearch-8.0
diff --git a/newsfragments/486.misc.rst b/newsfragments/486.misc.rst
new file mode 100644
index 00000000..4cf8cca3
--- /dev/null
+++ b/newsfragments/486.misc.rst
@@ -0,0 +1,1 @@
+Switched custom elasticsearch installation script to `ankane/setup-elasticsearch@v1`
\ No newline at end of file


Test patch:
diff --git a/.github/actions/pytest/action.yml b/.github/actions/pytest/action.yml
index b5b3fdcc..2239975e 100644
--- a/.github/actions/pytest/action.yml
+++ b/.github/actions/pytest/action.yml
@@ -14,23 +14,26 @@ runs:
     uses: actions/setup-python@v3
     with:
       python-version: ${{ inputs.python-version }}
-  - name: Cache Elasticsearch installations
-    uses: actions/cache@v3
+  - uses: actions/cache@v3
     with:
-      path: ~/es
-      key: es-${{ hashFiles('.install-elasticsearch.sh') }}
+      path: ~/elasticsearch
+      key: elasticsearch-${{ inputs.elasticsearch }}
+  - name: Setup elasticsearch
+    uses: ankane/setup-elasticsearch@v1
+    with:
+      elasticsearch-version: ${{ inputs.elasticsearch }}
   - name: Run test
     uses: fizyk/actions-reuse/.github/actions/pipenv@v2.1.2
     with:
       python-version: ${{ matrix.python-version }}
       pipenv-install-options: "--skip-lock"
-      command: pytest --elasticsearch-executable=/home/runner/es/elasticsearch-${{ inputs.elasticsearch }}/bin/elasticsearch -n 0 --cov-report=xml
+      command: pytest --elasticsearch-executable=$ES_HOME/bin/elasticsearch -n 0 --cov-report=xml
   - name: Run xdist test
     uses: fizyk/actions-reuse/.github/actions/pipenv@v2.1.2
     with:
       python-version: ${{ matrix.python-version }}
       pipenv-install-options: "--skip-lock"
-      command: pytest --elasticsearch-executable=/home/runner/es/elasticsearch-${{ inputs.elasticsearch }}/bin/elasticsearch -n 1 --cov-report=xml:coverage-xdist.xml
+      command: pytest --elasticsearch-executable=$ES_HOME/bin/elasticsearch -n 1 --cov-report=xml:coverage-xdist.xml
   - name: Upload coverage to Codecov
     uses: codecov/codecov-action@v3.0.0
     with:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 54e1ab04..ae9a4e72 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -7,19 +7,7 @@ on:
     branches: [ main ]
 
 jobs:
-  install_es:
-    runs-on: ubuntu-latest
-    steps:
-    - uses: actions/checkout@v3
-    - name: Cache Elasticsearch installations
-      uses: actions/cache@v3
-      with:
-        path: ~/es
-        key: es-${{ hashFiles('.install-elasticsearch.sh') }}
-    - name: Install Elasticsearch
-      run: ./.install-elasticsearch.sh
   tests_7_17:
-    needs: [install_es]
     runs-on: ubuntu-latest
     strategy:
       fail-fast: true
@@ -82,19 +70,3 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
           elasticsearch: "7.14"
-  tests_6_8:
-    needs: [install_es]
-    runs-on: ubuntu-latest
-    strategy:
-      fail-fast: true
-      matrix:
-        python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.8]
-    env:
-      OS: ubuntu-latest
-      PYTHON: ${{ matrix.python-version }}
-    steps:
-      - uses: actions/checkout@v3
-      - uses: ./.github/actions/pytest
-        with:
-          python-version: ${{ matrix.python-version }}
-          elasticsearch: "6.8.18"