From db5078d0ec646370206d9f16090559d59ba93f80 Mon Sep 17 00:00:00 2001 From: ilai Date: Sun, 29 Oct 2023 14:46:09 +0200 Subject: [PATCH] [CI] Added common action for installing dependencies + canopy This saves a lot of code duplication --- .../install-deps-and-canopy/action.yml | 41 +++++++++++++ .github/workflows/PR.yml | 57 +++---------------- .github/workflows/merege_queue.yml | 57 +++---------------- 3 files changed, 55 insertions(+), 100 deletions(-) create mode 100644 .github/actions/install-deps-and-canopy/action.yml diff --git a/.github/actions/install-deps-and-canopy/action.yml b/.github/actions/install-deps-and-canopy/action.yml new file mode 100644 index 00000000..be69305d --- /dev/null +++ b/.github/actions/install-deps-and-canopy/action.yml @@ -0,0 +1,41 @@ +name: Install dependencies and canopy +inputs: + python-version: + description: "Python version" + required: true + default: "3.9" + install-canopy: + description: "Whether to install canopy library, or dependencies only" + required: true + default: "true" + +runs: + using: "composite" + steps: + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.3.2 + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + #---------------------------------------------- + # load cached venv if cache exists + #---------------------------------------------- + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: | + .venv + poetry.lock + key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('pyproject.toml') }} + #---------------------------------------------- + # install dependencies if cache does not exist + #---------------------------------------------- + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root --with dev + - name: Install project + if: {{ inputs.install-canopy }} == "true" + run: poetry install --no-interaction diff --git a/.github/workflows/PR.yml b/.github/workflows/PR.yml index 3651d37a..0e6b78a6 100644 --- a/.github/workflows/PR.yml +++ b/.github/workflows/PR.yml @@ -23,31 +23,11 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.3.2 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v3 - with: - path: | - .venv - poetry.lock - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root --with dev + uses: .github/actions/install-deps-and-canopy + with: + python-version: ${{ matrix.python-version }} + install-canopy: false - name: Run flake8 Check run: poetry run flake8 . - name: Run mypy check @@ -68,33 +48,10 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.3.2 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v3 - with: - path: | - .venv - poetry.lock - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root --with dev - - name: Install project - run: poetry install --no-interaction + uses: .github/actions/install-deps-and-canopy + with: + python-version: ${{ matrix.python-version }} - name: Run unit tests run: poetry run pytest --html=report.html --self-contained-html tests/unit - name: upload pytest report.html diff --git a/.github/workflows/merege_queue.yml b/.github/workflows/merege_queue.yml index 4d8b36b4..8e13f344 100644 --- a/.github/workflows/merege_queue.yml +++ b/.github/workflows/merege_queue.yml @@ -16,31 +16,11 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.3.2 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v3 - with: - path: | - .venv - poetry.lock - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root --with dev + uses: .github/actions/install-deps-and-canopy + with: + python-version: ${{ matrix.python-version }} + install-canopy: false - name: Run flake8 Check run: poetry run flake8 . - name: Run mypy check @@ -61,33 +41,10 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 1.3.2 - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v3 + - name: Install dependencies and canopy + uses: .github/actions/install-deps-and-canopy with: - path: | - .venv - poetry.lock - key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root --with dev - - name: Install project - run: poetry install --no-interaction + python-version: ${{ matrix.python-version }} - name: Run unit tests run: poetry run pytest --html=report.html --self-contained-html tests/unit - name: Set Index Name for System / E2E