Skip to content

Merge pull request #154 from hopr-framework/cicd.precommit.allfiles #224

Merge pull request #154 from hopr-framework/cicd.precommit.allfiles

Merge pull request #154 from hopr-framework/cicd.precommit.allfiles #224

Workflow file for this run

# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of PyHOPE
#
# Copyright (c) 2024 Numerics Research Group, University of Stuttgart, Prof. Andrea Beck
#
# PyHOPE is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# PyHOPE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# PyHOPE. If not, see <http://www.gnu.org/licenses/>.
# ==================================================================================================================================
# Continuous Integration/Continuous Deployment
# ==================================================================================================================================
# Workflow for continuous integration (CI)
name: CI
on:
# Runs on pushes targeting the default branch
push:
branches:
- main
# Runs on pull requests
pull_request:
# Allows running this workflow manually from the Actions tab
workflow_dispatch:
# Permissions
permissions:
contents: read # default for all jobs
packages: read
pull-requests: write # coverage-bot
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
# Environment variables
env:
UV_LINK_MODE: copy
jobs:
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# Linter
# ----------------------------------------------------------------------------------------------------------------------------------------------------
ruff:
name: Lint / ruff
runs-on: ubuntu-latest
container:
image: python:3.14.5-slim-trixie
steps:
- uses: actions/checkout@v7
# with:
# fetch-depth: 0
# fetch-tags: true
- uses: ./.github/actions/setup
with:
minimal: 'true'
- shell: bash
run: |
source .venv/bin/activate
uv pip install ruff
ruff --version
ruff check --config pyproject.toml --preview
ty:
name: Lint / ty
runs-on: ubuntu-latest
container:
image: python:3.14.5-slim-trixie
steps:
# Git LFS requires git
- name: Install Git LFS
shell: bash
run: |
apt-get update
apt-get install -y --no-install-recommends git git-lfs
# This does not strictly require LFS but we want the checkout before the compatibility matrix
- uses: actions/checkout@v7
- uses: ./.github/actions/setup
# with:
# minimal: 'false'
- shell: bash
run: |
source .venv/bin/activate
uv pip --no-cache-dir install ty
ty --version
ty check --color always --project pyhope pyhope
vulture:
name: Lint / vulture
runs-on: ubuntu-latest
container:
image: python:3.14.5-slim-trixie
steps:
- uses: actions/checkout@v7
# with:
# fetch-depth: 0
# fetch-tags: true
- uses: ./.github/actions/setup
with:
minimal: 'true'
- shell: bash
run: |
source .venv/bin/activate
uv pip install vulture
vulture --version
vulture --config pyproject.toml .gmsh pyhope
gitleaks:
name: Lint / gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: pre-commit/[email protected]
with:
extra_args: --all-files gitleaks
pre-commit:
name: Lint / pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: pre-commit/[email protected]
with:
extra_args: --all-files check-merge-conflict
- uses: pre-commit/[email protected]
with:
extra_args: --all-files check-symlinks
- uses: pre-commit/[email protected]
with:
extra_args: --all-files trailing-whitespace
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# Compatibility
# ----------------------------------------------------------------------------------------------------------------------------------------------------
compatibility:
name: Compatibility / Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs: [ruff, ty, vulture, gitleaks, pre-commit]
strategy:
fail-fast: false
matrix:
include:
- { python-version: "3.10", image: "python:3.10.20-slim-trixie" }
- { python-version: "3.11", image: "python:3.11.15-slim-trixie" }
- { python-version: "3.12", image: "python:3.12.13-slim-trixie" }
- { python-version: "3.13", image: "python:3.13.13-slim-trixie" }
- { python-version: "3.14", image: "python:3.14.5-slim-trixie" }
container:
image: ${{ matrix.image }}
steps:
# Git LFS requires git
- name: Install Git LFS
shell: bash
run: |
apt-get update
apt-get install -y --no-install-recommends git git-lfs
- uses: actions/checkout@v7
# - uses: nschloe/action-cached-lfs-checkout@v1
with:
# fetch-depth: 0
# fetch-tags: true
lfs: true
- uses: ./.github/actions/setup
- name: Run compatibility tests
shell: bash
run: |
source .venv/bin/activate
pyhope tutorials/1-04-cartbox_multiple_stretch/parameter.ini
pyhope tutorials/2-02-external_mesh_CGNS_mixed/parameter.ini
# ==================================================================================================================================
# Verification
# ==================================================================================================================================
examples:
name: Verification / examples
runs-on: ubuntu-latest
needs: [compatibility]
container:
image: python:3.14.5-slim-trixie
steps:
# Git LFS requires git
- name: Install Git LFS
shell: bash
run: |
apt-get update
apt-get install -y --no-install-recommends git git-lfs
- uses: actions/checkout@v7
# - uses: nschloe/action-cached-lfs-checkout@v1
with:
# fetch-depth: 0
# fetch-tags: true
lfs: true
- uses: ./.github/actions/setup
with:
coverage: 'true'
- name: Run examples with coverage
shell: bash
run: |
source .venv/bin/activate
bash ./.github/scripts/examples.sh
- name: Save coverage reports
shell: bash
run: |
mkdir -p .tmp/coverage
cp .coverage.* .tmp/coverage
- name: Generate the coverage report in XML format
shell: bash
run: |
source .venv/bin/activate
coverage report --skip-empty --precision=2
- name: Output the final report
shell: bash
run: |
echo ""
printf "┌─%s─┬────────┐\n" "$(printf '─%.0s' $(seq 1 $((max_dir_length))))"
printf "│ %-$(($col_width-2))s │ %-5s │\n" "Example Directory" "Result"
printf "├─%s─┼────────┤\n" "$(printf '─%.0s' $(seq 1 $((max_dir_length))))"
for result in "${results[@]}"; do
paramdir=$(echo "$result" | cut -d ':' -f 1)
paramres=$(echo "$result" | cut -d ':' -f 2 | tr -d '[:space:]')
if [[ "$paramres" == "PASS" ]]; then
printf "│ %-$(($col_width-2))s │ ${green}%-6s${reset} │\n" "$paramdir" "$paramres"
else
printf "│ %-$(($col_width-2))s │ ${red}%-6s${reset} │\n" "$paramdir" "$paramres"
fi
done
printf "└─%s─┴────────┘\n" "$(printf '─%.0s' $(seq 1 $((max_dir_length))))"
# Fail the job if any examples failed
if [[ "${results[*]}" == *"FAIL"* ]]; then
echo "Some examples failed.";
exit 1;
else
echo "All examples passed.";
fi
- name: Restore coverage reports
shell: bash
run: |
cp .tmp/coverage/.coverage.* .
- uses: actions/upload-artifact@v7
with:
name: coverage-examples
include-hidden-files: true
path: |
.coverage.*
healthcheck:
name: Verification / healthcheck
runs-on: ubuntu-latest
needs: [compatibility]
container:
image: python:3.14.5-slim-trixie
steps:
# Git LFS requires git
- name: Install Git LFS
shell: bash
run: |
apt-get update
apt-get install -y --no-install-recommends git git-lfs
- uses: actions/checkout@v7
with:
# # Remove Git LFS on purpose to check the LFS downloader
lfs: false
- uses: ./.github/actions/setup
with:
coverage: 'true'
- name: Run healthcheck with coverage
shell: bash
run: |
source .venv/bin/activate
coverage run --data-file=".coverage.verify" -m pyhope --verify tutorials
- uses: actions/upload-artifact@v7
with:
name: coverage-healthcheck
include-hidden-files: true
path: |
.coverage.*
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# FLEXI convergence tests
# ----------------------------------------------------------------------------------------------------------------------------------------------------
convergence:
name: Verification / convergence
runs-on: ubuntu-latest
needs: [compatibility]
container:
image: ghcr.io/hopr-framework/nrg-fedora:43-x86_64
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v7
# with: Reduce Git LFS bandwidth
# fetch-depth: 0
# fetch-tags: true
# lfs: true
- uses: ./.github/actions/setup
with:
coverage: 'true'
- name: Run FLEXI convergence tests
shell: bash
run: |
source .venv/bin/activate
bash ./.github/scripts/convergence.sh
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# Code coverage
# ----------------------------------------------------------------------------------------------------------------------------------------------------
documentation:
name: Verification / documentation
runs-on: ubuntu-latest
needs: [examples, healthcheck]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v5
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
# Install MkDocs
- run: pip install mkdocs-material mkdocs-autorefs mkdocs-glightbox
# Build documentation
- run: mkdocs build
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# Code coverage
# ----------------------------------------------------------------------------------------------------------------------------------------------------
coverage:
name: Verification / coverage
runs-on: ubuntu-latest
needs: [examples, healthcheck]
container:
image: python:3.14.5-slim-trixie
steps:
- uses: actions/checkout@v7
# with:
# fetch-depth: 0
# fetch-tags: true
# - uses: actions/setup-node@v6
# with:
# node-version: 'latest'
- uses: ./.github/actions/setup
with:
minimal: 'true'
coverage: 'true'
- name: Download coverage artifacts
# act doesn't support GitHub Actions artifact service
# if: ${{ !env.ACT }}
uses: actions/download-artifact@v8
with:
pattern: coverage-*
# include-hidden-files: true
merge-multiple: true
- name: Combine and report coverage
shell: bash
run: |
source .venv/bin/activate
uv pip install --no-cache-dir coverage
# Combine coverage reports from all jobs
echo "Combining coverage reports..."
coverage combine --keep
# Generate the coverage report in XML format
echo "Generating coverage report..."
coverage xml
coverage report --skip-empty --precision=2
- uses: actions/upload-artifact@v7
with:
name: coverage-report
# include-hidden-files: true
path: |
coverage.xml
coverage-bot:
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' }}
runs-on: ubuntu-latest
needs: [coverage]
steps:
- name: Download coverage artifacts
# act doesn't support GitHub Actions artifact service
# if: ${{ !env.ACT }}
uses: actions/download-artifact@v8
with:
pattern: coverage-report
# include-hidden-files: true
merge-multiple: true
- name: Report coverage
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
thresholdAll: 0.85
thresholdNew: 0.90
# passIcon: ✅
# failIcon: ❌