ci: use docker executors with conditional jobs and best practices #26
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |
| # | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: CI | |
| on: | |
| push: | |
| branches: [main, pull-request/1] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| check-changes: | |
| name: Check for source changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| source-changed: ${{ steps.changes.outputs.source == 'true' }} | |
| docs-changed: ${{ steps.changes.outputs.docs == 'true' }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for changes | |
| id: changes | |
| uses: dorny/paths-filter@v3 | |
| with: | |
| filters: | | |
| source: | |
| - 'src/**' | |
| - 'cext/**' | |
| - 'test/**' | |
| - 'samples/**' | |
| - 'pyproject.toml' | |
| - 'setup.py' | |
| - 'CMakeLists.txt' | |
| - 'ci/**' | |
| - '.github/workflows/**' | |
| - 'Dockerfile.ci' | |
| docs: | |
| - 'docs/**' | |
| - '*.md' | |
| build-ci-image: | |
| name: Build CI Image | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: check-changes | |
| if: needs.check-changes.outputs.source-changed == 'true' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| buildkitd-config: /etc/buildkit/buildkitd.toml | |
| - name: Build CI image | |
| timeout-minutes: 20 | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile.ci | |
| tags: cutile-ci:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| load: true | |
| outputs: type=docker,compression=zstd | |
| - name: Export CI image | |
| run: | | |
| docker save cutile-ci:${{ github.sha }} | gzip > cutile-ci-image.tar.gz | |
| - name: Upload CI image artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: ci-image | |
| path: cutile-ci-image.tar.gz | |
| retention-days: 1 | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| container: | |
| image: python:3.10-slim | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install lint dependencies | |
| run: pip install --no-cache-dir flake8==7.3.0 reuse==5.1.0 | |
| - name: Run flake8 | |
| run: flake8 | |
| - name: Run cpplint | |
| run: python ci/cpplint.py | |
| - name: Check license headers (REUSE) | |
| run: ci/scripts/check_license.sh | |
| - name: Check inline samples are up to date | |
| run: python test/tools/inline_samples.py --check | |
| build-wheel: | |
| name: Build wheel (Linux x86_64, Python ${{ matrix.python-version }}) | |
| runs-on: ubuntu-latest | |
| needs: [check-changes, build-ci-image] | |
| if: needs.check-changes.outputs.source-changed == 'true' | |
| timeout-minutes: 30 | |
| container: | |
| image: cutile-ci:${{ github.sha }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - name: Load CI image | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: ci-image | |
| - run: docker load < cutile-ci-image.tar.gz | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Build wheel | |
| timeout-minutes: 15 | |
| run: | | |
| python${{ matrix.python-version }} -m venv .venv | |
| .venv/bin/pip install --upgrade pip build wheel setuptools | |
| .venv/bin/python -m build --wheel --outdir dist/ | |
| - name: Upload wheel artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: wheel-linux-x86_64-py${{ matrix.python-version }} | |
| path: dist/*.whl | |
| retention-days: 7 | |
| build-docs: | |
| name: Build docs | |
| runs-on: ubuntu-latest | |
| needs: [check-changes, build-ci-image, build-wheel] | |
| if: always() && (needs.check-changes.outputs.source-changed == 'true' || needs.check-changes.outputs.docs-changed == 'true') | |
| timeout-minutes: 15 | |
| container: | |
| image: cutile-ci:${{ github.sha }} | |
| steps: | |
| - name: Load CI image | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: ci-image | |
| - run: docker load < cutile-ci-image.tar.gz | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Download wheel artifact | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: wheel-linux-x86_64-py3.10 | |
| path: dist/ | |
| - name: Install dependencies | |
| run: | | |
| pip install dist/*.whl | |
| - name: Build documentation | |
| timeout-minutes: 10 | |
| run: | | |
| cd docs | |
| timeout 8m make html | |
| - name: Upload documentation artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: docs-html | |
| path: docs/build/html/ | |
| retention-days: 7 |