From 647e7daae8465aefc5c54242418208b41f5c5302 Mon Sep 17 00:00:00 2001 From: Matthew Hambley Date: Thu, 20 Jun 2024 10:57:15 +0100 Subject: [PATCH] Add caching to workflow. (#306) --- .github/workflows/build.yml | 81 +++++++++++++++++--------------- .github/workflows/build_docs.yml | 73 ++++++++++++++++------------ pyproject.toml | 2 +- 3 files changed, 88 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ede95de..3579682c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,46 +5,53 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: max-parallel: 4 matrix: python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Setup Compiler - run: | - sudo apt-get -y install gcc gfortran - - name: Setup LibClang - run: | - sudo apt-get -y install libclang-dev python-clang - SP=~/.local/lib/python${{ matrix.python-version }}/site-packages - mkdir -p $SP - cp -vr /usr/lib/python3/dist-packages/clang $SP/ - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -e . - - name: Type check with mypy - run: | - pip install -e .[dev] - pip install pytest - python -m mypy source tests - - name: Code style check with flake8 - run: | - pip install -e .[dev] - flake8 . --count --show-source --statistics - - name: Unit tests with Pytest - run: | - pip install .[tests] - python -m pytest --cov=fab tests/unit_tests - - - name: System tests with Pytest - run: | - pip install .[tests] - python -m pytest --cov=fab tests/system_tests + # Should this step use a cache? + # + - name: Setup Compiler + run: | + sudo apt-get -y install llvm clang libclang-dev gcc gfortran + + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + + # The clang binding version has to match the version in the Ubuntu being used. + - name: Install Python libraries + run: | + python -m pip install --upgrade pip + pip install -e . + pip install clang==14.0 + + - name: Type check with mypy + run: | + pip install -e .[dev] + pip install pytest + python -m mypy source tests + + - name: Code style check with flake8 + run: | + pip install -e .[dev] + flake8 . --count --show-source --statistics + + - name: Unit tests with Pytest + run: | + pip install .[tests] + python -m pytest --cov=fab tests/unit_tests + + - name: System tests with Pytest + run: | + pip install .[tests] + python -m pytest --cov=fab tests/system_tests diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index cc2564ac..df04c7c0 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -5,35 +5,48 @@ on: workflow_dispatch jobs: build-docs: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - name: set git user - run: | - git config --global user.email "metomi@metoffice.gov.uk" - git config --global user.name "SciFab Developers" - - uses: actions/checkout@v3 - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: install fab - run: pip install .[docs] - - name: build docs - run: | - cd docs - rm -rf build - sphinx-apidoc --separate --module-first -d 5 -f -o source/apidoc ../source/fab - make html - - name: move built docs to docs root - run: | - mv docs/build/html/* docs/ - - name: git add built docs - run: | - git add docs/* - - name: commit - run: | - git commit -m "docs build" - - name: push to gh_pages branch - run: | - echo "pushing from $GITHUB_REF_NAME to gh_pages" - git push --force origin $GITHUB_REF_NAME:gh_pages + - name: set git user + run: | + git config --global user.email "metomi@metoffice.gov.uk" + git config --global user.name "SciFab Developers" + + - name: Checkout Fab project files + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: pip + + - name: Install Python libraries + run: | + python -m pip install --upgrade pip + pip install -e .[docs] + + - name: build docs + run: | + cd docs + rm -rf build + sphinx-apidoc --separate --module-first -d 5 -f -o source/apidoc ../source/fab + make html + + - name: move built docs to docs root + run: | + mv docs/build/html/* docs/ + + - name: git add built docs + run: | + git add docs/* + + - name: commit + run: | + git commit -m "docs build" + + - name: push to gh_pages branch + run: | + echo "pushing from $GITHUB_REF_NAME to gh_pages" + git push --force origin $GITHUB_REF_NAME:gh_pages diff --git a/pyproject.toml b/pyproject.toml index 76424ead..8823f899 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ ] [project.optional-dependencies] -c-language = ['python-clang'] +c-language = ['clang'] plots = ['matplotlib'] tests = ['pytest', 'pytest-cov', 'pytest-mock'] checks = ['flake8>=5.0.4', 'mypy']