From f583cfc3245943a0420b44d1bc92a2323ff8bcf1 Mon Sep 17 00:00:00 2001 From: Ebram Shehata Date: Mon, 15 Jan 2024 02:13:36 +0200 Subject: [PATCH] Update Github workflow to use pip caching --- .github/actions/setup/action.yml | 27 ++++++++++++++++++++++++ .github/workflows/ci.yml | 35 +++++++++++++++----------------- 2 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 .github/actions/setup/action.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..e2bb756 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,27 @@ +name: 'Setup' +description: 'Set up Python and install dependencies' +inputs: + python-version: + description: 'Version of Python to set up' + required: true +runs: + using: 'composite' + steps: + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Restore Dependencies Cache + uses: actions/cache@v3 + with: + path: ~/.cache/pip/ + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install -r requirements.txt + pip install -e . diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9eafdf..9f03949 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,22 +9,24 @@ on: - synchronize - closed -# TODO: Use some kind of cache to speed up running. jobs: - test-main-python: + cache-dependencies: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup with: - python-version: "3.12" + python-version: "3.9" - - name: Install Dependencies - run: | - pip install -r requirements.txt - pip install -e . + main: + needs: cache-dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/setup + with: + python-version: "3.9" - name: Unit Tests run: coverage run -m pytest -s tests @@ -38,22 +40,17 @@ jobs: pre-commit run --all-files test-matrix: + needs: cache-dependencies runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.9", "3.10", "3.11" ] + python-version: [ "3.10", "3.11", "3.12" ] steps: - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup with: - python-version: ${{ matrix.version }} - - - name: Install Dependencies - run: | - pip install -r requirements.txt - pip install -e . + python-version: ${{ matrix.python-version }} - name: Run Test Matrix run: |