From c789baec4f364d6c2efddc93ae2535d748f11fe9 Mon Sep 17 00:00:00 2001 From: Tom Vo Date: Wed, 22 Dec 2021 09:47:59 -0800 Subject: [PATCH] Add matrix testing and ci specific conda env (#178) --- .github/workflows/build_workflow.yml | 79 +++++++++++++++++----------- conda-env/ci.yml | 15 ++++++ docs/project_maintenance.rst | 2 +- 3 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 conda-env/ci.yml diff --git a/.github/workflows/build_workflow.yml b/.github/workflows/build_workflow.yml index 2f55e053..18b2066e 100644 --- a/.github/workflows/build_workflow.yml +++ b/.github/workflows/build_workflow.yml @@ -9,73 +9,92 @@ on: workflow_dispatch: +env: + CANCEL_OTHERS: true + PATHS_IGNORE: '["**/README.rst", "**/docs/**", "**/ISSUE_TEMPLATE/**", "**/pull_request_template.md", "**/.vscode/**"]' + jobs: - check-jobs-to-skip: + pre-commit-hooks: runs-on: ubuntu-latest - outputs: - should_skip: ${{ steps.skip_check.outputs.should_skip }} + timeout-minutes: 2 steps: - id: skip_check uses: fkirc/skip-duplicate-actions@master with: - cancel_others: true - paths_ignore: '["**/README.rst", "**/docs/**", "**/ISSUE_TEMPLATE/**", "**/pull_request_template.md", "**/.vscode/**"]' + cancel_others: ${{ env.CANCEL_OTHERS }} + paths_ignore: ${{ env.PATHS_IGNORE }} - pre-commit-hooks: - needs: check-jobs-to-skip - if: ${{ needs.check-jobs-to-skip.outputs.should_skip != 'true'}} || ${{ github.event_name == 'push' }} - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: Checkout Code Repository + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Checkout Code Repository uses: actions/checkout@v2 - - name: Set up Python 3.9 + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Set up Python 3.9 uses: actions/setup-python@v2 with: python-version: 3.9 - # Run all pre-commit hooks on all the files. - # Getting only staged files can be tricky in case a new PR is opened - # since the action is run on a branch in detached head state - - name: Install and Run Pre-commit + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + # Run all pre-commit hooks on all the files. + # Getting only staged files can be tricky in case a new PR is opened + # since the action is run on a branch in detached head state + name: Install and Run Pre-commit uses: pre-commit/action@v2.0.3 build: - needs: check-jobs-to-skip - if: ${{ needs.check-jobs-to-skip.outputs.should_skip != 'true'}} || ${{ github.event_name == 'push' }} - runs-on: ubuntu-latest + name: Build (Python ${{ matrix.python-version }}) + runs-on: "ubuntu-latest" + timeout-minutes: 10 defaults: run: shell: bash -l {0} - timeout-minutes: 5 + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9"] steps: - - uses: actions/checkout@v2 + - id: skip_check + uses: fkirc/skip-duplicate-actions@master + with: + cancel_others: ${{ env.CANCEL_OTHERS }} + paths_ignore: ${{ env.PATHS_IGNORE }} - - name: Cache Conda + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + uses: actions/checkout@v2 + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Cache Conda uses: actions/cache@v2 env: - # Increase this value to reset cache if conda/dev.yml has not changed in the workflow + # Increase this value to reset cache if conda-env/ci.yml has not changed in the workflow CACHE_NUMBER: 0 with: path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-publish + key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }} - - name: Set up Conda Environment + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Set up Conda Environment uses: conda-incubator/setup-miniconda@v2 with: - activate-environment: "xcdat_dev" - environment-file: conda-env/dev.yml + activate-environment: "xcdat_ci" + environment-file: conda-env/ci.yml channel-priority: strict auto-update-conda: true # IMPORTANT: This needs to be set for caching to work properly! use-only-tar-bz2: true + python-version: ${{ matrix.python-version }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Install xcdat + run: | + python -m pip install . - - name: Run Tests + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Run Tests run: | pytest - - name: Upload Coverage Report + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Upload Coverage Report uses: codecov/codecov-action@v1 with: file: "tests_coverage_reports/coverage.xml" diff --git a/conda-env/ci.yml b/conda-env/ci.yml new file mode 100644 index 00000000..552c036c --- /dev/null +++ b/conda-env/ci.yml @@ -0,0 +1,15 @@ +# Conda xcdat CI/CD environment (used in GH Actions) +name: xcdat_ci +channels: + - conda-forge + - defaults +dependencies: + # Base + # ================== + - python + - pip + # Testing + # ================== + - pytest=6.2.5 + - pytest-cov=3.0.0 +prefix: /opt/miniconda3/envs/xcdat_ci diff --git a/docs/project_maintenance.rst b/docs/project_maintenance.rst index e645e1e2..ceb43665 100644 --- a/docs/project_maintenance.rst +++ b/docs/project_maintenance.rst @@ -41,4 +41,4 @@ This workflow is triggered by Git ``pull_request`` and ``push`` (merging PRs) ev Jobs: 1. Run ``pre-commit`` for formatting, linting, and type checking - 2. Build conda development environment and run test suite + 2. Build conda CI/CD environment with different Python versions, install package, and run test suite