From 92dffc9f41fac7d5e28c4022312b4309be9e0638 Mon Sep 17 00:00:00 2001 From: Mike S Wang <32841762+MikeSWang@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:32:25 +0100 Subject: [PATCH] BUILD: Add GitHub CI & CD workflows --- .github/workflows/cd.yml | 74 ++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..a4448f3 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,74 @@ +# Provide continuous delivery (CD). +# +# CD deliverables currently include: +# - Cuba shared library (built from C sources); +# +name: continuous-delivery + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+.post[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+.dev[0-9]+' + paths: + - .github/workflows/cd.yml + workflow_dispatch: + inputs: + rebuild_sharedlib: + description: 'Rebuild shared library' + type: boolean + default: false + required: false + version_tag: + description: 'Version tag for delivery' + type: string + required: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_sharedlib: + name: Build shared library + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + compiler: [gcc, clang] + exclude: + - os: ubuntu-latest + compiler: clang + + runs-on: ${{ matrix.os }} + + timeout-minutes: 20 + + if: > + github.event_name != 'workflow_dispatch' || + github.event.inputs.rebuild_sharedlib == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Override compiler (macOS) + if: runner.os == 'macOS' + run: | + if [ "${{ matrix.compiler }}" == 'gcc' ]; then + export CC=$(find $(brew --prefix gcc)/bin -type f -name 'gcc*') + fi + if [ "${{ matrix.compiler }}" == 'clang' ]; then + export CC=$(brew --prefix llvm@15)/bin/clang + fi + + - name: Build shared library + run: ./make_sharedlib.sh + + - name: Upload shared library + uses: actions/upload-artifact@v4 + with: + name: libcuba-${{ github.ref_name }}-${{ runner.os }}-${{ matrix.compiler }} + path: dist/libcuba.* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6d960bd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,97 @@ +# Perform continuous integration (CI) checks. +# +# CI tasks include but are not limited to: +# - development builds (on all supported OS); +# - unit/integration tests; +# - code linting. +# +name: continuous-integration + +on: + push: + branches: + - main + paths: + - src/** + - patches/** + - cuba.h + - make* + - config* + - setup.py + - pyproject.toml + - .gitignore + - .github/workflows/ci.yml + pull_request: + types: [opened, synchronize, reopened] + paths: + - src/** + - patches/** + - cuba.h + - make* + - config* + - setup.py + - pyproject.toml + - .gitignore + - .github/workflows/ci.yml + pull_request_review: + types: [submitted, edited] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-test-dev: + name: Build & test (in dev mode) + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + + runs-on: ${{ matrix.os }} + + timeout-minutes: 20 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install Python build requirements + run: python -m pip install --upgrade pip + + - name: Build and install + run: python -m pip install --editable . -vvv + + - name: Demo test + run: python -c "from pycuba import demo; demo()" + + lint: + name: Lint + + runs-on: ubuntu-latest + + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install Python linting requirements + run: python -m pip install flake8 + + - name: Lint + run: | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --exit-zero --statistics