|
| 1 | +# This workflow will for a variety of Python versions |
| 2 | +# - install the code base |
| 3 | +# - lint the code base |
| 4 | +# - test the code base |
| 5 | +# - upload the test coverage to codecov |
| 6 | +# |
| 7 | +# It will also |
| 8 | +# - build the package |
| 9 | +# - check the package |
| 10 | +# |
| 11 | +# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries |
| 12 | + |
| 13 | +name: Build and test package |
| 14 | + |
| 15 | +# Trigger the workflow on push, pull request and manual trigger |
| 16 | +on: [push, pull_request, workflow_call] |
| 17 | + |
| 18 | +# Allow only one concurrent workflow, skipping runs queued between the run in-progress and latest queued. |
| 19 | +# And cancel in-progress runs. |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + |
| 26 | + # Job 1: Build the package |
| 27 | + build-package: |
| 28 | + |
| 29 | + # current job matrix. if modified, remember to UPDATE the strategy in the next job |
| 30 | + strategy: |
| 31 | + fail-fast: false |
| 32 | + matrix: |
| 33 | + os: [ubuntu-24.04, windows-2022, macos-13, macos-14] |
| 34 | + python-version: ['3.10', '3.11', '3.12'] |
| 35 | + |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout repository |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Set up Python ${{ matrix.python-version }} |
| 43 | + uses: actions/setup-python@v5 |
| 44 | + with: |
| 45 | + python-version: ${{ matrix.python-version }} |
| 46 | + |
| 47 | + - name: Upgrade package installer for Python |
| 48 | + run: python -m pip install --upgrade pip |
| 49 | + |
| 50 | + - name: Install Python dependencies |
| 51 | + run: pip install '.[dev]' |
| 52 | + |
| 53 | + - name: Create Python package # dist/*.whl |
| 54 | + run: python -m build --wheel --outdir dist |
| 55 | + |
| 56 | + - name: Upload zipped Python package (with tests and examples) for next job |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + name: EasyDiffractionLib_py${{ matrix.python-version }}_${{ matrix.os }}_${{ runner.arch }} |
| 60 | + path: | |
| 61 | + dist/*.whl |
| 62 | + tests/ |
| 63 | + examples/ |
| 64 | + if-no-files-found: "error" |
| 65 | + compression-level: 0 |
| 66 | + |
| 67 | + # Job 2: Test the package |
| 68 | + test-package: |
| 69 | + needs: build-package # previous job 'code-testing' need to be finished first |
| 70 | + |
| 71 | + strategy: |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + os: [ubuntu-24.04, windows-2022, macos-13, macos-14] |
| 75 | + python-version: ['3.10', '3.11', '3.12'] |
| 76 | + |
| 77 | + runs-on: ${{ matrix.os }} |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Set up Python ${{ matrix.python-version }} |
| 81 | + uses: actions/setup-python@v5 |
| 82 | + with: |
| 83 | + python-version: ${{ matrix.python-version }} |
| 84 | + |
| 85 | + - name: Upgrade package installer for Python |
| 86 | + run: python -m pip install --upgrade pip |
| 87 | + |
| 88 | + - name: Download zipped Python package (with tests and examples) from previous job |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: # name or path are taken from the upload step of the previous job |
| 91 | + name: EasyDiffractionLib_py${{ matrix.python-version }}_${{ matrix.os }}_${{ runner.arch }} |
| 92 | + path: . # directory to extract downloaded zipped artifacts |
| 93 | + |
| 94 | + - name: Install Python package from previous job with 'dev' extras |
| 95 | + run: pip install 'easydiffraction[dev]' --find-links=dist |
| 96 | + |
| 97 | + - name: Run Python tests |
| 98 | + run: > |
| 99 | + pytest tests/ |
| 100 | + --color=yes |
| 101 | + -n auto |
| 102 | +
|
| 103 | + - name: Run tests on Jupyter Notebooks |
| 104 | + shell: bash |
| 105 | + run: > |
| 106 | + pytest |
| 107 | + --nbmake examples/*ipynb |
| 108 | + --nbmake-timeout=300 |
| 109 | + --color=yes |
| 110 | + -n=auto |
0 commit comments