From a48031e768de099ec2ad955051bd3adc859e36b1 Mon Sep 17 00:00:00 2001 From: drew2a Date: Fri, 3 Jun 2022 09:04:03 +0200 Subject: [PATCH] Add pyenv action --- .github/actions/pyenv/action.yml | 37 +++++++++++++++++++++++++++++ .github/workflows/!PR.yml | 1 - .github/workflows/build_ubuntu.yml | 6 ++++- .github/workflows/coverage.yml | 10 ++++---- .github/workflows/documentation.yml | 9 +++---- .github/workflows/guitest.yml | 9 +++---- .github/workflows/pytest.yml | 9 +++---- 7 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 .github/actions/pyenv/action.yml diff --git a/.github/actions/pyenv/action.yml b/.github/actions/pyenv/action.yml new file mode 100644 index 00000000000..bb63ef49180 --- /dev/null +++ b/.github/actions/pyenv/action.yml @@ -0,0 +1,37 @@ +name: pyenv +description: Setup python and install required dependencies to venv with cache +inputs: + python-version: + default: '3.8' + description: 'Python version' + required: false + + requirements: + default: 'requirements.txt' + description: 'The path to requirements.txt file' + required: false + +outputs: + virtualenv-directory: + description: 'The path to the restored or created virtualenv' + value: ${{steps.cache-virtualenv.outputs.virtualenv-directory}} + +runs: + using: 'composite' + steps: + - uses: actions/setup-python@v3 + with: + python-version: ${{inputs.python-version}} + + - name: Restore virtual env + uses: syphar/restore-virtualenv@v1 + id: cache-virtualenv + with: + requirement_files: ${{inputs.requirements}} + + - name: Install pip dependencies + if: steps.cache-virtualenv.outputs.cache-hit != 'true' + shell: bash + run: | + python -m pip install --upgrade pip + pip install -r ${{inputs.requirements}} diff --git a/.github/workflows/!PR.yml b/.github/workflows/!PR.yml index 449281dee7a..775bd6185a4 100644 --- a/.github/workflows/!PR.yml +++ b/.github/workflows/!PR.yml @@ -36,4 +36,3 @@ jobs: upload: false os: ubuntu-20.04 python-version: 3.8 - diff --git a/.github/workflows/build_ubuntu.yml b/.github/workflows/build_ubuntu.yml index 38ea8f18269..e7b0bbbbbb4 100644 --- a/.github/workflows/build_ubuntu.yml +++ b/.github/workflows/build_ubuntu.yml @@ -27,9 +27,12 @@ jobs: fetch-depth: 0 ref: ${{github.event.pull_request.head.sha}} - - uses: actions/setup-python@v3 + - name: Create python environment + id: pyenv + uses: ./.github/actions/pyenv with: python-version: ${{inputs.python-version}} + requirements: requirements-build.txt - name: Save Git info run: | @@ -51,6 +54,7 @@ jobs: QT_QPA_PLATFORM: offscreen QT_ACCESSIBILITY: 1 QT_IM_MODULE: ibus + VENV: ${{steps.pyenv.outputs.virtualenv-directory}} run: | ./build/debian/makedist_debian.sh diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b2a612bdb7d..bf76ad3e7b6 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -14,14 +14,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + + - name: Create python environment + uses: ./.github/actions/pyenv with: python-version: ${{inputs.python-version}} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./requirements-test.txt + requirements: requirements-test.txt - name: Run Pytest with Coverage run: | diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index b9ef47123a3..f5b962fca84 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -14,14 +14,11 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - name: Create python environment + uses: ./.github/actions/pyenv with: python-version: ${{inputs.python-version}} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./doc/requirements.txt + requirements: ./doc/requirements.txt - name: Build documentation run: | diff --git a/.github/workflows/guitest.yml b/.github/workflows/guitest.yml index 9bc4ea6f1df..d4b5f4c99a7 100644 --- a/.github/workflows/guitest.yml +++ b/.github/workflows/guitest.yml @@ -18,14 +18,11 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - name: Create python environment + uses: ./.github/actions/pyenv with: python-version: ${{inputs.python-version}} - - - name: Install pip dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./requirements-test.txt + requirements: requirements-test.txt - name: Install xvfb dependencies run: | diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 3371d15cade..5ba9a443be1 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -25,9 +25,11 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - name: Create python environment + uses: ./.github/actions/pyenv with: python-version: ${{inputs.python-version}} + requirements: requirements-test.txt - name: Install Libsodium (win) if: matrix.os == 'windows-latest' @@ -36,11 +38,6 @@ jobs: 7z x libsodium-1.0.17-msvc.zip copy ./x64/Release/v141/dynamic/libsodium.dll C:\Windows\system32\ - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./requirements-test.txt - - name: Run Pytest run: | pytest ./src/tribler/core ${{matrix.pytest-arguments}}