simplify #170
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Cross-compile | |
| on: [push, workflow_dispatch] | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ ubuntu-22.04, windows-2022 ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure and build (Linux) | |
| if: startsWith(runner.os, 'Linux') | |
| run: | | |
| cmake . -B build -DFMU4CPP_BUILD_EXAMPLES=ON -DFMU4CPP_BUILD_TESTS=OFF | |
| cmake --build build | |
| - name: Configure and build (Windows) | |
| if: startsWith(runner.os, 'Windows') | |
| run: | | |
| cmake . -B build -DFMU4CPP_BUILD_EXAMPLES=ON -DFMU4CPP_BUILD_TESTS=OFF -A x64 | |
| cmake --build build --config Release | |
| - name: Discover models and create per-model archives (Linux) | |
| if: startsWith(runner.os, 'Linux') | |
| run: | | |
| set -euo pipefail | |
| mkdir -p tmp/pkg artifacts model-descriptions | |
| # find model directories (relative to repo, without leading build/) | |
| find build/models -type f -name modelDescription.xml -printf '%h\n' 2>/dev/null | sed 's#^build/##' | sort -u > tmp/models.txt || true | |
| # build MODEL_PATHS as semicolon-separated for later use | |
| MODEL_PATHS="" | |
| while IFS= read -r line || [ -n "$line" ]; do | |
| line=$(echo "$line" | tr -d '\r' | xargs) | |
| [ -z "$line" ] && continue | |
| if [ -z "$MODEL_PATHS" ]; then MODEL_PATHS="$line"; else MODEL_PATHS="$MODEL_PATHS;$line"; fi | |
| done < tmp/models.txt | |
| printf 'MODEL_PATHS=%s\n' "$MODEL_PATHS" >> $GITHUB_ENV | |
| IFS=';' read -ra paths <<< "$MODEL_PATHS" | |
| for p in "${paths[@]}"; do | |
| p_trimmed=$(echo "$p" | tr -d '\r' | xargs) | |
| [ -z "$p_trimmed" ] && continue | |
| # use only the model directory name as the archive root (e.g. model_name_version) | |
| base=$(basename "$p_trimmed") | |
| safe=$(printf '%s' "$base" | sed 's#[/\\]#-#g; s/[^A-Za-z0-9._-]/_/g') | |
| src="build/${p_trimmed}/binaries" | |
| if [ -d "$src" ]; then | |
| # copy into temp package folder so zip root becomes $safe/binaries | |
| rm -rf "tmp/pkg/${safe}" | |
| mkdir -p "tmp/pkg/${safe}" | |
| cp -a "$src" "tmp/pkg/${safe}/binaries" | |
| (cd tmp/pkg && zip -r "${GITHUB_WORKSPACE}/artifacts/binaries-${safe}-${{ matrix.os }}.zip" "$safe" >/dev/null) | |
| else | |
| echo "::warning:: $src not found, skipping" | |
| fi | |
| md="build/${p_trimmed}/modelDescription.xml" | |
| if [ -f "$md" ]; then | |
| cp "$md" "model-descriptions/modelDescription-${safe}-${{ matrix.os }}.xml" | |
| fi | |
| done | |
| - name: Discover models and create per-model archives (Windows) | |
| if: startsWith(runner.os, 'Windows') | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path tmp\pkg,artifacts,model-descriptions | Out-Null | |
| $wd = $env:GITHUB_WORKSPACE | |
| $models = Get-ChildItem -Path (Join-Path $wd 'build\models') -Recurse -Filter 'modelDescription.xml' -File -ErrorAction SilentlyContinue | | |
| ForEach-Object { $_.Directory.FullName.Substring($wd.Length + 1) } | | |
| Sort-Object -Unique | |
| $models | Out-File -FilePath tmp\models.txt -Encoding UTF8 | |
| $paths = (Get-Content -Path tmp\models.txt | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }) | |
| $joined = $paths -join ';' | |
| "MODEL_PATHS=$joined" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding UTF8 | |
| foreach ($p in $paths) { | |
| $p_trimmed = $p.Trim() | |
| if ([string]::IsNullOrEmpty($p_trimmed)) { continue } | |
| # use only the model directory name as the archive root (e.g. model_name_version) | |
| $base = Split-Path -Path $p_trimmed -Leaf | |
| $safe = ($base -replace '[\\/]', '-') -replace '[^A-Za-z0-9._-]', '_' | |
| $src = Join-Path -Path $wd -ChildPath ("build\" + $p_trimmed + "\binaries") | |
| if (Test-Path $src) { | |
| $pkgDir = Join-Path -Path $wd -ChildPath ("tmp\pkg\" + $safe) | |
| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $pkgDir | |
| New-Item -ItemType Directory -Force -Path (Join-Path $pkgDir 'binaries') | Out-Null | |
| Copy-Item -Path (Join-Path $src '*') -Destination (Join-Path $pkgDir 'binaries') -Recurse -Force | |
| $dest = Join-Path -Path $wd -ChildPath ("artifacts\binaries-$safe-${{ matrix.os }}.zip") | |
| Remove-Item -Force -ErrorAction SilentlyContinue $dest | |
| Compress-Archive -Path $pkgDir -DestinationPath $dest -Force | |
| } else { | |
| Write-Warning "$src not found, skipping" | |
| } | |
| $md = Join-Path -Path $wd -ChildPath ("build\" + $p_trimmed + "\modelDescription.xml") | |
| if (Test-Path $md) { | |
| Copy-Item $md -Destination (Join-Path $wd ("model-descriptions\modelDescription-$safe-${{ matrix.os }}.xml")) -Force | |
| } | |
| } | |
| - name: Upload models | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: models-${{ matrix.os }} | |
| path: build/models | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: "Download models" | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: models-* | |
| path: models | |
| merge-multiple: true | |
| - name: "Set permissions" | |
| run: | | |
| sudo chmod -R +x models/binaries | |
| - name: "Upload merged models" | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: models | |
| path: models |