|
| 1 | +name: CI/CD Build Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + CANCEL_OTHERS: true |
| 14 | + PATHS_IGNORE: '["**/README.rst", "**/docs/**", "**/ISSUE_TEMPLATE/**", "**/pull_request_template.md", "**/.vscode/**"]' |
| 15 | + |
| 16 | +jobs: |
| 17 | + pre-commit-hooks: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - id: skip_check |
| 21 | + uses: fkirc/skip-duplicate-actions@master |
| 22 | + with: |
| 23 | + cancel_others: ${{ env.CANCEL_OTHERS }} |
| 24 | + paths_ignore: ${{ env.PATHS_IGNORE }} |
| 25 | + |
| 26 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 27 | + name: Checkout Code Repository |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 31 | + name: Set up Python 3.10 |
| 32 | + uses: actions/setup-python@v3 |
| 33 | + with: |
| 34 | + python-version: "3.10" |
| 35 | + |
| 36 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 37 | + # Run all pre-commit hooks on all the files. |
| 38 | + # Getting only staged files can be tricky in case a new PR is opened |
| 39 | + # since the action is run on a branch in detached head state |
| 40 | + name: Install and Run Pre-commit |
| 41 | + uses: pre-commit/[email protected] |
| 42 | + |
| 43 | + build: |
| 44 | + name: Build (Python ${{ matrix.python-version }}) |
| 45 | + runs-on: "ubuntu-latest" |
| 46 | + defaults: |
| 47 | + run: |
| 48 | + shell: bash -l {0} |
| 49 | + strategy: |
| 50 | + matrix: |
| 51 | + python-version: ["3.9", "3.10", "3.11"] |
| 52 | + steps: |
| 53 | + - id: skip_check |
| 54 | + uses: fkirc/skip-duplicate-actions@master |
| 55 | + with: |
| 56 | + cancel_others: ${{ env.CANCEL_OTHERS }} |
| 57 | + paths_ignore: ${{ env.PATHS_IGNORE }} |
| 58 | + do_not_skip: '["push", "workflow_dispatch"]' |
| 59 | + |
| 60 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 61 | + uses: actions/checkout@v3 |
| 62 | + |
| 63 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 64 | + name: Cache Conda |
| 65 | + uses: actions/cache@v3 |
| 66 | + env: |
| 67 | + # Increase this value to reset cache if conda-env/ci.yml has not changed in the workflow |
| 68 | + CACHE_NUMBER: 0 |
| 69 | + with: |
| 70 | + path: ~/conda_pkgs_dir |
| 71 | + key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }} |
| 72 | + |
| 73 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 74 | + name: Set up Conda Environment |
| 75 | + uses: conda-incubator/setup-miniconda@v2 |
| 76 | + with: |
| 77 | + activate-environment: "ci" |
| 78 | + miniforge-variant: Mambaforge |
| 79 | + miniforge-version: latest |
| 80 | + use-mamba: true |
| 81 | + mamba-version: "*" |
| 82 | + environment-file: conda-env/ci.yml |
| 83 | + channel-priority: strict |
| 84 | + auto-update-conda: true |
| 85 | + # IMPORTANT: This needs to be set for caching to work properly! |
| 86 | + use-only-tar-bz2: true |
| 87 | + python-version: ${{ matrix.python-version }} |
| 88 | + |
| 89 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 90 | + name: Install Package to the CI Environment |
| 91 | + # Source: https://github.com/conda/conda-build/issues/4251#issuecomment-1053460542 |
| 92 | + run: | |
| 93 | + python -m pip install --no-build-isolation --no-deps -e . |
| 94 | +
|
| 95 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 96 | + name: Run Tests |
| 97 | + run: | |
| 98 | + pytest |
0 commit comments