Skip to content

Commit 9998c42

Browse files
authored
Merge pull request #22 from EnergySystemsModellingLab/add-notebook-tests-to-ci
add nbmake dependency and run in CI
2 parents 0b1c5a3 + f4eebea commit 9998c42

3 files changed

Lines changed: 104 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Test and build
2-
32
on:
43
push:
54
branches: [main]
@@ -9,18 +8,27 @@ on:
98

109
jobs:
1110
test:
12-
runs-on: ${{matrix.os}}
11+
runs-on: ${{ matrix.os }}
1312
strategy:
1413
fail-fast: false
1514
matrix:
16-
os:
17-
- ubuntu-latest
18-
- windows-latest
19-
- macos-latest
20-
python-version: ['3.14']
15+
include:
16+
- os: ubuntu-latest
17+
python-version: '3.14'
18+
muse2_asset: muse2_linux.tar.gz
19+
muse2_exe: muse2
20+
- os: windows-latest
21+
python-version: '3.14'
22+
muse2_asset: muse2_windows.zip
23+
muse2_exe: muse2.exe
24+
- os: macos-latest
25+
python-version: '3.14'
26+
muse2_asset: muse2_macos_arm.tar.gz
27+
muse2_exe: muse2
2128

2229
steps:
2330
- uses: actions/checkout@v6
31+
2432
- uses: astral-sh/setup-uv@v7
2533
with:
2634
enable-cache: true
@@ -31,6 +39,75 @@ jobs:
3139
- name: Install dependencies
3240
run: uv sync
3341

42+
# Query the GitHub API for the latest MUSE2 release tag (e.g. "v2.0.0").
43+
# The tag is written to GITHUB_OUTPUT so subsequent steps can reference it.
44+
- name: Get latest MUSE2 release tag
45+
id: muse2_release
46+
shell: bash
47+
run: |
48+
TAG=$(curl -sSf \
49+
-H "Accept: application/vnd.github+json" \
50+
-H "Authorization: Bearer ${{ github.token }}" \
51+
https://api.github.com/repos/EnergySystemsModellingLab/MUSE2/releases/latest \
52+
| jq -r '.tag_name')
53+
54+
if [[ -z "$TAG" || "$TAG" == "null" ]]; then
55+
echo "::error::Failed to retrieve latest MUSE2 release tag."
56+
exit 1
57+
fi
58+
59+
echo "Resolved latest MUSE2 release: $TAG"
60+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
61+
62+
# Download the platform-appropriate MUSE2 release asset.
63+
# 'shell: bash' is used on all platforms
64+
- name: Download MUSE2 release asset
65+
shell: bash
66+
run: |
67+
curl -sSfL \
68+
"https://github.com/EnergySystemsModellingLab/MUSE2/releases/download/${{ steps.muse2_release.outputs.tag }}/${{ matrix.muse2_asset }}" \
69+
--output "muse2_asset_download"
70+
71+
- name: Extract MUSE2 and set environment variable (Linux / macOS)
72+
if: runner.os == 'Linux' || runner.os == 'macOS'
73+
shell: bash
74+
run: |
75+
mkdir -p muse2_bin
76+
tar -xf muse2_asset_download -C muse2_bin
77+
chmod +x "muse2_bin/${{ matrix.muse2_exe }}"
78+
echo "MUSE2_PATH=${{ github.workspace }}/muse2_bin/${{ matrix.muse2_exe }}" >> "$GITHUB_ENV"
79+
80+
- name: Extract MUSE2 and set environment variable (Windows)
81+
if: runner.os == 'Windows'
82+
shell: pwsh
83+
run: |
84+
New-Item -ItemType Directory -Force -Path muse2_bin | Out-Null
85+
Rename-Item -Path "muse2_asset_download" -NewName "muse2_asset_download.zip"
86+
Expand-Archive -Path "muse2_asset_download.zip" -DestinationPath muse2_bin -Force
87+
$exePath = "${{ github.workspace }}\muse2_bin\${{ matrix.muse2_exe }}"
88+
echo "MUSE2_PATH=$exePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
89+
90+
# Confirm the muse2 executable is present and the environment variable is set correctly.
91+
- name: Verify MUSE2 installation (Linux / macOS)
92+
if: runner.os == 'Linux' || runner.os == 'macOS'
93+
shell: bash
94+
run: |
95+
if [[ ! -f "$MUSE2_PATH" ]]; then
96+
echo "::error::MUSE2 executable not found at: $MUSE2_PATH"
97+
exit 1
98+
fi
99+
echo "MUSE2_PATH is set to: $MUSE2_PATH"
100+
101+
- name: Verify MUSE2 installation (Windows)
102+
if: runner.os == 'Windows'
103+
shell: pwsh
104+
run: |
105+
if (-not (Test-Path -Path $env:MUSE2_PATH -PathType Leaf)) {
106+
Write-Error "MUSE2 executable not found at: $env:MUSE2_PATH"
107+
exit 1
108+
}
109+
Write-Host "MUSE2_PATH is set to: $env:MUSE2_PATH"
110+
34111
- name: Run mypy
35112
run: mypy .
36113

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dev = [
1818
"pytest>=9.0.2",
1919
"pytest-cov>=7.0.0",
2020
"pytest-mock>=3.15.1",
21+
"nbmake>=1.5.5",
2122
]
2223

2324

@@ -34,7 +35,7 @@ module = "tests.*"
3435
disallow_untyped_defs = false
3536

3637
[tool.pytest.ini_options]
37-
addopts = "-v -p no:warnings --cov=muse2_data_analysis --cov-branch --cov-report=html --cov-report=xml --doctest-modules --ignore=docs/"
38+
addopts = "-v -p no:warnings --cov=muse2_data_analysis --cov-branch --cov-report=html --cov-report=xml --doctest-modules --ignore=docs/ --nbmake"
3839

3940
[tool.ruff]
4041
target-version = "py314"

uv.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)