Debian Codegraph @

.github/workflows/CI.yml

raw
1 name: CI
2
3 on:
4 push:
5 pull_request:
6 release:
7 types: [published]
8
9 env:
10 CI: "ON" # We can detect this in the build system and other vendors implement it
11 HOMEBREW_NO_ANALYTICS: "ON" # Make Homebrew installation a little quicker
12 HOMEBREW_NO_AUTO_UPDATE: "ON"
13 HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: "ON"
14 HOMEBREW_NO_GITHUB_API: "ON"
15 HOMEBREW_NO_INSTALL_CLEANUP: "ON"
16
17 jobs:
18
19 build:
20 runs-on: ${{ matrix.os }}
21 strategy:
22 fail-fast: false
23 matrix:
24 os: [ubuntu-latest, macos-14, macos-15-intel, windows-latest]
25 toolchain:
26 - {compiler: gcc, version: 10}
27 - {compiler: gcc, version: 11}
28 - {compiler: gcc, version: 12}
29 - {compiler: gcc, version: 13}
30 - {compiler: gcc, version: 14}
31 - {compiler: gcc, version: 15}
32 - {compiler: intel, version: 2025.2}
33 exclude:
34 - os: macos-14 # No Intel on MacOS anymore since 2024
35 toolchain: {compiler: intel, version: '2025.1'}
36 - os: macos-14 # Intel compiler does not support ARM (macos-14)
37 toolchain: {compiler: intel, version: '2025.2'}
38 - os: macos-14 # gcc@10 not available on macos-14 (ARM64)
39 toolchain: {compiler: gcc, version: 10}
40 - os: macos-15-intel # Intel compiler not available on macOS
41 toolchain: {compiler: intel, version: '2025.2'}
42 - os: macos-15-intel # gcc@10 not available on macos-15
43 toolchain: {compiler: gcc, version: 10}
44 - os: windows-latest # Doesn't pass build and tests yet
45 toolchain: {compiler: intel, version: '2025.2'}
46 - os: windows-latest # gcc 14 not available on Windows yet
47 toolchain: {compiler: gcc, version: 14}
48 - os: windows-latest # gcc 15 not available on Windows yet
49 toolchain: {compiler: gcc, version: 15}
50 - os: ubuntu-latest # gcc 15 not available on Ubuntu via setup-fortran yet
51 toolchain: {compiler: gcc, version: 15}
52 include:
53 - os: ubuntu-latest
54 os-arch: linux-x86_64
55 release-flags: --flag '--static -g -fbacktrace -O3'
56 - os: macos-14
57 os-arch: macos-arm64
58 release-flags: --flag '-g -fbacktrace -O3'
59 - os: macos-15-intel
60 os-arch: macos-x86_64
61 release-flags: --flag '-g -fbacktrace -O3'
62 - os: windows-latest
63 os-arch: windows-x86_64
64 release-flags: --flag '--static -g -fbacktrace -O3'
65 exe: .exe
66 - os: macos-14
67 toolchain: {compiler: gcc, version: 15}
68 release-flags: --flag '-g -fbacktrace -Og -fcheck=all,no-recursion -Wno-external-argument-mismatch'
69
70 steps:
71 - name: Checkout code
72 uses: actions/checkout@v6
73
74 - name: Setup Fortran compiler
75 uses: fortran-lang/[email protected]
76 id: setup-fortran
77 with:
78 compiler: ${{ matrix.toolchain.compiler }}
79 version: ${{ matrix.toolchain.version }}
80
81 # Phase 1: Bootstrap fpm with existing version
82 - name: Install fpm
83 uses: fortran-lang/setup-fpm@v9
84 with:
85 fpm-version: 'v0.12.0'
86
87 # Backport gfortran shared libraries to the paths expected by the bootstrap fpm binary.
88 # The macOS x86_64 release used for bootstrapping has hardcoded library paths from the gcc version
89 # it was built with. If the versions match, skip this step. Otherwise, create symlinks.
90 # On ARM64 it runs under Rosetta 2 and needs /usr/local paths.
91 - name: MacOS patch libgfortran
92 if: contains(matrix.os, 'macos')
93 run: |
94 which gfortran-${{ matrix.toolchain.version }}
95 which gfortran
96 BREW_PREFIX=$(brew --prefix)
97
98 # Query the actual library paths that fpm expects
99 echo "Checking library dependencies of fpm bootstrap binary..."
100 otool -L $(which fpm)
101
102 # Extract the gcc version from the bootstrap binary's library paths
103 BOOTSTRAP_GCC_VERSION=$(otool -L $(which fpm) | grep -o 'gcc@[0-9]\+' | head -n 1 | cut -d@ -f2)
104 if [ -z "$BOOTSTRAP_GCC_VERSION" ]; then
105 # Try alternative pattern: /lib/gcc/13/ -> extract 13
106 BOOTSTRAP_GCC_VERSION=$(otool -L $(which fpm) | grep libgfortran | grep -o '/lib/gcc/[0-9]\+/' | grep -o '[0-9]\+' | head -n 1)
107 fi
108
109 echo "Bootstrap fpm built with gcc@$BOOTSTRAP_GCC_VERSION"
110 echo "Current toolchain: gcc@${{ matrix.toolchain.version }}"
111
112 if [ "$BOOTSTRAP_GCC_VERSION" == "${{ matrix.toolchain.version }}" ]; then
113 echo "✓ Bootstrap gcc version matches current toolchain - no patching needed"
114 exit 0
115 fi
116
117 echo "⚠ Version mismatch detected - creating compatibility symlinks..."
118
119 # Find the actual Cellar path by following the symlink
120 if [ -L "${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}" ]; then
121 GCC_CELLAR_PATH=$(cd -P "${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}" && pwd)
122 else
123 GCC_CELLAR_PATH="${BREW_PREFIX}/Cellar/gcc@${{ matrix.toolchain.version }}"/*
124 fi
125 echo "GCC Cellar path: $GCC_CELLAR_PATH"
126
127 # Find the actual library files
128 CURRENT_GFORTRAN=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ matrix.toolchain.version }} -name "libgfortran.*.dylib" 2>/dev/null | head -n 1)
129 CURRENT_QUADMATH=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ matrix.toolchain.version }} -name "libquadmath.*.dylib" 2>/dev/null | head -n 1)
130 CURRENT_GCC_S=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ matrix.toolchain.version }} -name "libgcc_s.*.dylib" 2>/dev/null | head -n 1)
131
132 echo "Current gcc@${{ matrix.toolchain.version }} libraries:"
133 echo " libgfortran: $CURRENT_GFORTRAN"
134 echo " libquadmath: $CURRENT_QUADMATH"
135 echo " libgcc_s: $CURRENT_GCC_S"
136
137 # Extract the expected libgfortran path and create symlink
138 LIBGFORTRAN_PATH=$(otool -L $(which fpm) | grep libgfortran | awk '{print $1}' | head -n 1)
139 if [ -n "$LIBGFORTRAN_PATH" ] && [ -n "$CURRENT_GFORTRAN" ]; then
140 TARGET_DIR=$(dirname "$LIBGFORTRAN_PATH")
141 echo "Creating directory: $TARGET_DIR"
142 sudo mkdir -p "$TARGET_DIR"
143 echo "Linking $CURRENT_GFORTRAN to $LIBGFORTRAN_PATH"
144 sudo ln -fs "$CURRENT_GFORTRAN" "$LIBGFORTRAN_PATH"
145 fi
146
147 # Extract the expected libquadmath path and create symlink
148 LIBQUADMATH_PATH=$(otool -L $(which fpm) | grep libquadmath | awk '{print $1}' | head -n 1)
149 if [ -n "$LIBQUADMATH_PATH" ] && [ -n "$CURRENT_QUADMATH" ]; then
150 TARGET_DIR=$(dirname "$LIBQUADMATH_PATH")
151 echo "Creating directory: $TARGET_DIR"
152 sudo mkdir -p "$TARGET_DIR"
153 echo "Linking $CURRENT_QUADMATH to $LIBQUADMATH_PATH"
154 sudo ln -fs "$CURRENT_QUADMATH" "$LIBQUADMATH_PATH"
155 fi
156
157 # Extract the expected libgcc_s path and create symlink
158 LIBGCC_PATH=$(otool -L $(which fpm) | grep libgcc_s | awk '{print $1}' | head -n 1)
159 if [ -n "$LIBGCC_PATH" ] && [ -n "$CURRENT_GCC_S" ]; then
160 TARGET_DIR=$(dirname "$LIBGCC_PATH")
161 echo "Creating directory: $TARGET_DIR"
162 sudo mkdir -p "$TARGET_DIR"
163 echo "Linking $CURRENT_GCC_S to $LIBGCC_PATH"
164 sudo ln -fs "$CURRENT_GCC_S" "$LIBGCC_PATH"
165 fi
166
167 # gcc and g++ will point to clang/clang++: use versioned alias for fpm
168 - name: MacOS patch C and C++ compilers
169 if: contains(matrix.os, 'macos')
170 run: |
171 echo "CC=gcc-${{ matrix.toolchain.version }}" >> $GITHUB_ENV
172 echo "FPM_CC=gcc-${{ matrix.toolchain.version }}" >> $GITHUB_ENV
173 echo "CXX=g++-${{ matrix.toolchain.version }}" >> $GITHUB_ENV
174 echo "FPM_CXX=g++-${{ matrix.toolchain.version }}" >> $GITHUB_ENV
175 echo "FPM_LDFLAGS=-lstdc++" >> $GITHUB_ENV
176
177 - name: Remove fpm from path
178 shell: bash
179 run: |
180 mv $(which fpm) fpm-bootstrap${{ matrix.exe }}
181 echo "BOOTSTRAP=$PWD/fpm-bootstrap" >> $GITHUB_ENV
182
183 - name: Build Fortran fpm (bootstrap)
184 shell: bash
185 run: |
186 ${{ env.BOOTSTRAP }} build
187
188 - name: Run Fortran fpm (bootstrap)
189 shell: bash
190 run: |
191 ${{ env.BOOTSTRAP }} run
192 ${{ env.BOOTSTRAP }} run -- --version
193 ${{ env.BOOTSTRAP }} run -- --help
194
195 - name: Test Fortran fpm (bootstrap)
196 shell: bash
197 run: |
198 ${{ env.BOOTSTRAP }} test --flag " -Wno-external-argument-mismatch"
199
200 - name: Install Fortran fpm (bootstrap)
201 shell: bash
202 run: |
203 ${{ env.BOOTSTRAP }} install
204
205 # Phase 2: Bootstrap fpm with itself
206 - name: Replace bootstrapping version
207 shell: bash
208 run: |
209 ${{ env.BOOTSTRAP }} run --runner cp -- fpm-debug${{ matrix.exe }}
210 rm -v ${{ env.BOOTSTRAP }}
211 echo "FPM=$PWD/fpm-debug" >> $GITHUB_ENV
212
213 - name: Get version (normal)
214 if: github.event_name != 'release'
215 shell: bash
216 run: |
217 VERSION=$(git rev-parse --short HEAD)
218 echo "VERSION=$VERSION" >> $GITHUB_ENV
219
220 - name: Get version (release)
221 if: github.event_name == 'release'
222 shell: bash
223 run: |
224 VERSION=$(echo ${{ github.ref }} | cut -dv -f2)
225 echo "VERSION=$VERSION" >> $GITHUB_ENV
226 FPM_VERSION=$(${{ env.FPM }} --version | grep -o '${{ env.REGEX }}')
227 [ "$VERSION" = "$FPM_VERSION" ]
228 env:
229 REGEX: '[0-9]\{1,4\}\.[0-9]\{1,4\}\.[0-9]\{1,4\}'
230
231 - name: Build Fortran fpm
232 shell: bash
233 run: |
234 ${{ env.FPM }} build ${{ matrix.release-flags }}
235
236 - name: Run Fortran fpm
237 shell: bash
238 run: |
239 ${{ env.FPM }} run ${{ matrix.release-flags }}
240 ${{ env.FPM }} run ${{ matrix.release-flags }} -- --version
241 ${{ env.FPM }} run ${{ matrix.release-flags }} -- --help
242
243 - name: Test Fortran fpm
244 shell: bash
245 run: |
246 ${{ env.FPM }} test ${{ matrix.release-flags }}
247
248 - name: Install Fortran fpm
249 shell: bash
250 run: |
251 ${{ env.FPM }} install ${{ matrix.release-flags }}
252
253 - name: Package release version
254 shell: bash
255 run: |
256 ${{ env.FPM }} run ${{ matrix.release-flags }} --runner cp -- ${{ env.EXE }}
257 rm -v ${{ env.FPM }}
258 echo "FPM_RELEASE=${{ env.EXE }}" >> $GITHUB_ENV
259 env:
260 EXE: fpm-${{ env.VERSION }}-${{ matrix.os-arch }}-gcc-${{ matrix.toolchain.version }}${{ matrix.exe }}
261
262 - name: Run release version
263 shell: bash
264 run: |
265 ci/run_tests.sh "$PWD/${{ env.FPM_RELEASE }}"
266
267 - name: Upload artifact
268 uses: actions/upload-artifact@v6
269 with:
270 name: ${{ env.FPM_RELEASE }}
271 path: ${{ env.FPM_RELEASE }}
272
273
274 make-installer:
275 if: ${{ github.event_name == 'release' && contains(github.ref, 'v') || github.event_name == 'push' }}
276 runs-on: windows-latest
277 needs:
278 - build
279 strategy:
280 fail-fast: false
281 matrix:
282 gcc_v: [11,12,13]
283
284 steps:
285 - uses: actions/checkout@v6
286
287 - name: Download Artifacts
288 id: download_windows_artifacts
289 uses: actions/download-artifact@v7
290 with:
291 path: ${{ github.workspace }}
292 pattern: fpm-*-windows-*-gcc-${{ matrix.gcc_v }}.exe
293
294 - name: Get version (normal)
295 if: github.event_name != 'release'
296 shell: bash
297 run: |
298 VERSION=$(git rev-parse --short HEAD)
299 echo "VERSION=$VERSION" >> $GITHUB_ENV
300
301 - name: Get version (release)
302 if: github.event_name == 'release'
303 shell: bash
304 run: |
305 VERSION=$(echo ${{ github.ref }} | cut -dv -f2)
306 echo "VERSION=$VERSION" >> $GITHUB_ENV
307 env:
308 REGEX: '[0-9]\{1,4\}\.[0-9]\{1,4\}\.[0-9]\{1,4\}'
309
310 - name: Setup MinGW (MSYS2)
311 uses: msys2/setup-msys2@v2
312 with:
313 msystem: MINGW64
314 update: false
315 install: >-
316 wget
317 unzip
318
319 - name: Fetch Windows executable
320 shell: msys2 {0}
321 run: |
322 set -e
323 download_path='${{ steps.download_windows_artifacts.outputs.download-path }}'
324 download_path=$(printf '%s\n' "$download_path" | head -n1)
325 if [ -z "$download_path" ]; then
326 echo "download-artifact did not report a download path" >&2
327 exit 1
328 fi
329 if command -v cygpath >/dev/null 2>&1; then
330 posix_path=$(cygpath -u "$download_path")
331 else
332 posix_path="$download_path"
333 fi
334 exe_path=$(find "$posix_path" -maxdepth 2 -type f -name "fpm-*-windows-*-gcc-${{ matrix.gcc_v }}.exe" | head -n 1)
335 if [ -z "$exe_path" ]; then
336 echo "Windows executable not found under $posix_path" >&2
337 ls -al "$posix_path" || true
338 exit 1
339 fi
340 cp "$exe_path" ./ci/fpm.exe
341
342 - name: Fetch Git for Windows
343 shell: msys2 {0}
344 run: |
345 cd ./ci
346 wget ${{ env.git_download }} -O MinGit.zip
347 unzip MinGit.zip -d MinGit
348 env:
349 git_download: "https://github.com/git-for-windows/git/releases/download/v2.33.1.windows.1/MinGit-2.33.1-64-bit.zip"
350
351 - name: Fetch EnVar Plugin for NSIS
352 shell: msys2 {0}
353 run: |
354 cd ./ci
355 wget ${{ env.envar_download }} -O EnVar-Plugin.zip
356 mkdir EnVar_plugin
357 unzip EnVar-Plugin.zip -d EnVar_plugin
358 env:
359 envar_download: "https://github.com/GsNSIS/EnVar/releases/download/v0.3.1/EnVar-Plugin.zip"
360
361 - name: Install NSIS
362 run: choco install nsis -y
363 shell: pwsh
364
365 - name: Add NSIS to PATH
366 shell: pwsh
367 run: |
368 $dirs = @(
369 "${env:ProgramFiles(x86)}\NSIS",
370 "${env:ProgramFiles}\NSIS"
371 ) | Where-Object { $_ -and (Test-Path $_) }
372 if (-not $dirs) { throw "NSIS not found under Program Files." }
373 $dirs | ForEach-Object { $_ | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append }
374
375 - name: Generate installer
376 run: |
377 cd ./ci
378 makensis fpm-installer.nsi
379 move fpm-installer.exe fpm-installer-${{ env.VERSION }}-gcc-${{ matrix.gcc_v }}.exe
380
381 - name: Upload artifact
382 uses: actions/upload-artifact@v6
383 with:
384 name: fpm-installer-gcc-${{ matrix.gcc_v }}
385 path: ci/fpm-installer-${{ env.VERSION }}-gcc-${{ matrix.gcc_v }}.exe
386
387 upload-artifacts:
388 if: ${{ github.event_name == 'release' && contains(github.ref, 'v') || github.event_name == 'push' }}
389 runs-on: ubuntu-latest
390 needs:
391 - build
392 - make-installer
393
394 steps:
395 - id: deploy-on-push
396 if: ${{ github.event_name == 'push' }}
397 run:
398 echo "::set-output name=result::${{ env.DEPLOY_BRANCH }}"
399 env:
400 DEPLOY_BRANCH: ${{ secrets.DEPLOY_BRANCH && contains(github.ref, secrets.DEPLOY_BRANCH) && 1 || 0 }}
401
402 - uses: actions/checkout@v6
403 if: ${{ github.event_name == 'push' }}
404
405 - name: Download Artifacts
406 uses: actions/download-artifact@v7
407 with:
408 path: fpm-cd-artifacts
409 pattern: 'fpm-*-gcc-12*'
410 merge-multiple: true
411
412 - name: Normalize file names for continuous delivery
413 if: ${{ github.event_name == 'push' }}
414 run: |
415 cd fpm-cd-artifacts
416 for output in fpm-*; do
417 mv -v $(basename $output) $(basename $output | sed -E '${{ env.replace }}')
418 done
419 env:
420 replace: 's/-([0-9]+\.[0-9]+\.[0-9]+-[0-9]+-g)?[0-9a-f]+//'
421
422 - name: Create SHA256 checksums
423 run: |
424 cd fpm-cd-artifacts
425 for output in fpm-*; do
426 sha256sum $(basename "$output") | tee $(basename "$output").sha256
427 done
428
429 - name: Move/Create continuous tag
430 if: ${{ github.event_name == 'push' && steps.deploy-on-push.outputs.result != 0 }}
431 run: |
432 git tag --force 'current' ${{ github.sha }}
433 git push --tags --force
434
435 - name: Upload assets
436 uses: svenstaro/upload-release-action@v2
437 if: ${{ github.event_name == 'release' || steps.deploy-on-push.outputs.result != 0 }}
438 with:
439 repo_token: ${{ secrets.GITHUB_TOKEN }}
440 file: fpm-cd-artifacts/*
441 file_glob: true
442 tag: ${{ github.event_name == 'release' && github.ref || 'current'}}
443 overwrite: true