Skip to content

Commit

Permalink
Merge branch 'topic/default/ci-release-and-github' into 'branch/default'
Browse files Browse the repository at this point in the history
More nox + release in CI + Github Actions

See merge request fluiddyn/fluidsimfoam!112
  • Loading branch information
paugier committed Jan 21, 2024
2 parents f069232 + 9650288 commit 5f05bc2
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI Linux

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
env:
WM_PROJECT_DIR: /usr/share/openfoam
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: apt install
run: |
sudo apt install -y openfoam
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pdm nox
- name: Test
run: |
icoFoam -help
nox -s test
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)
files: coverage.xml
45 changes: 40 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ variables:
WM_PROJECT_DIR: "/usr/share/openfoam"
OMPI_ALLOW_RUN_AS_ROOT: "1"
OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: "1"
PDM_CACHE_DIR: ${CI_PROJECT_DIR}/.pdm-cache

stages:
- image
- test
- publish
- build
- release

cache:
# Required to keep artifacts from old builds, e.g. from default
paths:
- public

before_script:
- pdm install


# Build an image for the above tasks; this should be a scheduled job, as
# it is quite unnecessary to run on every invocation.
Expand All @@ -32,8 +32,6 @@ CI image:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
before_script:
- ""
script:
- |
cat > /kaniko/.docker/config.json <<EOF
Expand All @@ -57,6 +55,7 @@ CI image:
pytest:
stage: test
script:
- pdm sync --clean -G test -G pyvista
- pdm run pytest tests doc/examples --cov --cov-report term --cov-report xml
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
artifacts:
Expand All @@ -69,6 +68,7 @@ pytest:
pages:
stage: publish
script:
- pdm sync --clean -G pyvista -G doc
- pdm run xvfb-run --auto-servernum sphinx-build -W -b html -d doc/_build/doctrees doc doc/_build/html
- mkdir -p public/$CI_COMMIT_REF_NAME
- rsync -rvc --delete doc/_build/html/* public/$CI_COMMIT_REF_NAME/
Expand All @@ -85,3 +85,38 @@ pages:
- public
expire_in: 5 days
when: always


build:package:
stage: build
before_script:
- pdm config cache_dir ${PDM_CACHE_DIR}
script:
- pdm build || pdm lock --group :all --refresh
needs: []
artifacts:
when: always
paths:
- pdm.lock
- dist
expire_in: 24 hrs
cache:
when: always
key: pdmcache-$CI_COMMIT_BRANCH
paths:
- ${PDM_CACHE_DIR}


# manually set PDM_PUBLISH_PASSWORD in web interface to your pypi API token
release:package:
stage: release
rules:
- if: '$CI_MERGE_REQUEST_ID'
when: never
- if: '$CI_COMMIT_TAG'
when: on_success
variables:
PDM_PUBLISH_USERNAME: __token__
script:
- pdm publish --no-build
needs: [ "build:package" ]
10 changes: 9 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
nox.options.reuse_existing_virtualenvs = 1


@nox.session
def test(session):
session.run_always(
"pdm", "sync", "-G", "test", "-G", "pyvista", "--clean", external=True
)
session.run("pdm", "run", "cov-xml", external=True)


@nox.session
def doc(session):
session.run_always("pdm", "sync", "-G", "doc", external=True)
session.run_always("pdm", "sync", "-G", "doc", "--clean", external=True)
session.chdir("doc")
session.run("make", "cleanall", external=True)
session.run("make", external=True)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ doc = [

[tool.pdm.scripts]
cov = "pytest tests doc/examples/ --cov --cov-report term --cov-report html"
cov-xml = "pytest tests doc/examples --cov --cov-report term --cov-report xml"
black = "black -l 82 src tests doc dev"
isort = "isort src tests doc dev"
format = {composite = ["black", "isort"]}
Expand Down
7 changes: 6 additions & 1 deletion src/fluidsimfoam/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ def get_openfoam_version():
process = run(["icoFoam", "-help"], text=True, capture_output=True)
except FileNotFoundError:
return None
version = process.stdout.split("Using: OpenFOAM-")[1].split()[0]
try:
version = process.stdout.split("Using: OpenFOAM-")[1].split()[0]
except IndexError as err:
raise RuntimeError(
f"Cannot get OpenFOAM version from icoFoam help: '{process.stdout}'"
) from err
return version.removeprefix("v").removeprefix("(").removesuffix(")")

0 comments on commit 5f05bc2

Please sign in to comment.