From 0ea6454b4d06362f6ad5595fae680ff89d5c85b4 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 20 Feb 2024 05:05:23 -0800 Subject: [PATCH] feat: os independent venv activation on code-style action (#404) --- code-style/action.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/code-style/action.yml b/code-style/action.yml index c93c940fc..4811b7f47 100644 --- a/code-style/action.yml +++ b/code-style/action.yml @@ -85,11 +85,22 @@ runs: python -m pip install --upgrade pip python -m venv .venv + - name: "Store venv activation mechanism depending on OS" + shell: bash + run: | + if [[ "$RUNNER_OS" == "Linux" ]]; then + echo "ACTIVATE_VENV=$(echo 'source .venv/bin/activate')" >> $GITHUB_ENV + elif [[ "$RUNNER_OS" == "macOS" ]]; then + echo "ACTIVATE_VENV=$(echo 'source .venv/bin/activate')" >> $GITHUB_ENV + elif [[ "$RUNNER_OS" == "Windows" ]]; then + echo "ACTIVATE_VENV=$(echo '.venv\\Scripts\\activate')" >> $GITHUB_ENV + fi + - name: "Install project (if required)" if: inputs.skip-install == 'false' shell: bash run: | - source .venv/bin/activate + ${{ env.ACTIVATE_VENV }} if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then python -m pip install poetry python -m poetry install @@ -100,14 +111,14 @@ runs: - name: "Install pre-commit" shell: bash run: | - source .venv/bin/activate + ${{ env.ACTIVATE_VENV }} python -m pip install pre-commit pre-commit install - name: "Run pre-commit" shell: bash run: | - source .venv/bin/activate + ${{ env.ACTIVATE_VENV }} pre-commit run --all-files --show-diff-on-failure # ------------------------------------------------------------------------