Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
82 changes: 82 additions & 0 deletions .github/workflows/mofmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Format the Modelica code with mofmt (https://github.com/ErykMroczek/mofmt).
#
# - Pull request from a branch of this repository, or manual run: mofmt is
# applied and a "style: format Modelica code with mofmt" commit is pushed
# to the branch (run "git pull" afterwards).
# - Pull request from a fork, or direct push to master: nothing is pushed,
# the job fails if some files are not formatted.
#
# Commits pushed with GITHUB_TOKEN do not trigger other workflows, so the
# OpenModelica tests are not re-run on the formatting commit.

name: mofmt

on:
pull_request:
branches: [master]
paths: ['**.mo', '.github/workflows/mofmt.yml']
push:
branches: [master]
paths: ['**.mo', '.github/workflows/mofmt.yml']
workflow_dispatch:

permissions:
contents: write # needed to push the formatting commit

concurrency:
group: mofmt-${{ github.ref }}
cancel-in-progress: true

env:
MOFMT_VERSION: 0.6.0

jobs:
mofmt:
runs-on: ubuntu-latest
steps:
# On pull requests, check out the branch itself (not the merge commit)
# so the formatting commit can be pushed to it.
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.ref || github.ref }}

- name: Cache mofmt
id: cache
uses: actions/cache@v4
with:
path: ~/.cargo/bin/mofmt
key: mofmt-${{ env.MOFMT_VERSION }}-${{ runner.os }}

- name: Install mofmt
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install mofmt --version "$MOFMT_VERSION" --locked

# mofmt panics on files starting with a UTF-8 BOM, which some Windows
# editors add. Does nothing on files without BOM.
- name: Strip UTF-8 BOM
run: find . -name '*.mo' -not -path './.git/*' -exec sed -i '1s/^\xEF\xBB\xBF//' {} +

- name: Format
run: mofmt .

- name: Commit formatting
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
run: |
if git diff --quiet; then echo "Already formatted"; exit 0; fi
git diff --stat
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "style: format Modelica code with mofmt"
git push

# Pull requests from forks have no write access, and master should only
# receive formatted code through pull requests: report only.
- name: Report unformatted files
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
run: |
if git diff --quiet; then echo "Already formatted"; exit 0; fi
git diff --stat
echo "::error::Some .mo files are not formatted with mofmt $MOFMT_VERSION. Run 'mofmt .' at the repository root."
exit 1
121 changes: 121 additions & 0 deletions .github/workflows/openmodelica-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Test TAeZoSysPro Examples and Tests models with OpenModelica, using
# ModelicaTests (https://gitlab.pam-retd.fr/thermosysproandco/modelicatests),
# and compare them with the master branch of EDF-Lab/TAeZoSysPro:
# - .test/config_new_openmodelica.json tests the checked out version,
# - .test/config_ref_openmodelica.json tests master, cloned by ModelicaTests.
# If the reference cannot be tested (for instance while master still has the
# library at the repository root instead of src/TAeZoSysPro), the checked out
# version is tested alone. The run summary, written by .test/report.py, shows
# the results table of the ModelicaTests HTML report for the tested version,
# and the comparison with the reference (fixed, regression, results changed).
#
# Required repository settings (Settings > Secrets and variables > Actions):
# - secret MODELICATESTS_TOKEN: GitLab token with read_repository access to
# the ModelicaTests project.
# - variable OPENMODELICA_IMAGE (optional): OpenModelica Docker image.
#
# Failing models do not fail the workflow: they are reported in the run
# summary, and in the uploaded HTML/CSV reports and OpenModelica logs. The
# workflow only fails on infrastructure errors (library or MSL not loadable,
# ModelicaTests crash).

name: OpenModelica tests

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-openmodelica:
# Pull requests from forks have no access to secrets, so the private
# ModelicaTests repository cannot be cloned: skip the job instead of failing.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
container:
image: ${{ vars.OPENMODELICA_IMAGE || 'openmodelica/openmodelica:v1.26.7-ompython' }}
steps:
# git is needed to clone ModelicaTests; python3-venv is used to avoid
# installing Python packages as root.
- name: Install system dependencies
run: |
apt-get update
apt-get install -y --no-install-recommends git ca-certificates python3-venv

# The library is in src/TAeZoSysPro: OpenModelica requires the directory
# containing package.mo to be named after the package.
- name: Checkout TAeZoSysPro
uses: actions/checkout@v4
with:
path: TAeZoSysPro

- name: Clone ModelicaTests
env:
MODELICATESTS_TOKEN: ${{ secrets.MODELICATESTS_TOKEN }}
run: git clone --depth 1 "https://oauth2:${MODELICATESTS_TOKEN}@gitlab.pam-retd.fr/thermosysproandco/modelicatests.git" modelicatests

# Copy TAeZoSysPro test configuration files into the ModelicaTests test
# directory, where the runner expects them.
- name: Configure ModelicaTests
run: |
cp TAeZoSysPro/.test/*.json modelicatests/tests/
cat > modelicatests/tests/local_config.json <<'JSON'
{
"dymola": {
"egg": "",
"exe": ""
},
"openmodelica": {
"exe": "/usr/bin/omc"
}
}
JSON

# Docker jobs run as root. OpenModelica refuses to start its ZMQ server
# as root, and omc4py needs that server, so the tests run as ciuser.
# If the run with the reference fails, its outputs are removed and the
# checked out version is tested alone (report.py then skips the comparison).
- name: Run ModelicaTests
run: |
useradd --create-home --shell /bin/bash ciuser
chown -R ciuser:ciuser "$GITHUB_WORKSPACE"
su ciuser -c "cd '$GITHUB_WORKSPACE/modelicatests' && python3 -m venv .venv && . .venv/bin/activate && python -m pip install --upgrade pip && python -m pip install ."
cd modelicatests/tests
su ciuser -c ". ../.venv/bin/activate && python3 run_cli.py config_ref_openmodelica.json config_new_openmodelica.json --ncpus 4 --timeout 120" || {
echo "::warning::ModelicaTests failed with the reference (master), see the log above: testing the checked out version alone."
rm -rf config_ref_openmodelica.csv config_ref_openmodelica.html config_ref_openmodelica-* TMP_*
su ciuser -c ". ../.venv/bin/activate && python3 run_cli.py config_new_openmodelica.json --ncpus 4 --timeout 120"
}

# Written to a file first: ciuser cannot write to $GITHUB_STEP_SUMMARY.
- name: Write results summary
if: always()
run: |
su ciuser -c "cd '$GITHUB_WORKSPACE/modelicatests/tests' && . ../.venv/bin/activate && python3 '$GITHUB_WORKSPACE/TAeZoSysPro/.test/report.py' config_ref_openmodelica.csv config_new_openmodelica.csv > report.md"
cat modelicatests/tests/report.md >> "$GITHUB_STEP_SUMMARY"

- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: modelicatests-report
retention-days: 7
# TMP_*/<model>/ holds the OpenModelica check, build and simulation
# logs of each model, needed to understand a failure.
path: |
modelicatests/tests/*.csv
modelicatests/tests/*.html
modelicatests/tests/*-junit.xml
modelicatests/tests/report.md
modelicatests/tests/TMP_*/*/*.log
modelicatests/tests/TMP_*/*/*.txt
if-no-files-found: warn
23 changes: 23 additions & 0 deletions .test/config_new_openmodelica.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"software": "OpenModelica",
"dymola": {
"advanced_flags":["Advanced.LogNonLinearIterationVariables=true","Advanced.GenerateBlockTimers=true"]
},
"openmodelica": {
"modelica_version": "3.2.3",
"compiler_flags":{
"--matchingAlgorithm":"PFPlusExt",
"-d":"initialization,iterationVars,stateselection,backenddaeinfo,stateselection,aliasConflicts,bltdump"
},
"simflags":{
"-jacobian":"coloredNumerical"
}
},
"libs": {
"TAeZoSysPro": {
"path": "../../TAeZoSysPro/src/TAeZoSysPro/package.mo",
"models_filter": "\\.(Examples|Tests)\\.",
"vars_filter": ".*"
}
}
}
27 changes: 27 additions & 0 deletions .test/config_ref_openmodelica.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"software": "OpenModelica",
"dymola": {
"advanced_flags":["Advanced.LogNonLinearIterationVariables=true","Advanced.GenerateBlockTimers=true"]
},
"openmodelica": {
"modelica_version": "3.2.3",
"compiler_flags":{
"--matchingAlgorithm":"PFPlusExt",
"-d":"initialization,iterationVars,stateselection,backenddaeinfo,stateselection,aliasConflicts,bltdump"
},
"simflags":{
"-jacobian":"coloredNumerical"
}
},
"libs": {
"TAeZoSysPro": {
"path": {
"url": "https://github.com/EDF-Lab/TAeZoSysPro.git",
"target": "master",
"package_path": "src/TAeZoSysPro/package.mo"
},
"models_filter": "\\.(Examples|Tests)\\.",
"vars_filter": ".*"
}
}
}
Loading
Loading