test-run-for-ci #4
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: CI | |
| on: | |
| push: | |
| branches: [ release, staging ] | |
| pull_request: | |
| branches: [ release, staging ] | |
| jobs: | |
| build: | |
| name: ${{ matrix.os }} / ${{ matrix.compiler }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # , macos-13, macos-14, windows-latest | |
| os: [ubuntu-22.04, ubuntu-24.04] | |
| compiler: [gcc-13, gcc-14, gcc-15, clang-14, clang-15, clang-17] | |
| include: | |
| - compiler: gcc-13 | |
| compiler-version: 13 | |
| - compiler: gcc-14 | |
| compiler-version: 14 | |
| - compiler: gcc-15 | |
| compiler-version: 15 | |
| - compiler: clang-14 | |
| compiler-version: 14 | |
| - compiler: clang-15 | |
| compiler-version: 15 | |
| - compiler: clang-17 | |
| compiler-version: 17 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set badge output directory | |
| id: path | |
| run: | | |
| if [[ "${GITHUB_REF##*/}" == "staging" ]]; then | |
| echo "dir=status-staging" >> $GITHUB_OUTPUT | |
| else | |
| echo "dir=status" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check skip list | |
| id: skip_check | |
| shell: bash | |
| run: | | |
| skip_list=( | |
| "ubuntu-22.04:gcc-13" | |
| "ubuntu-22.04:gcc-14" | |
| "ubuntu-22.04:gcc-15" | |
| "ubuntu-22.04:clang-14" | |
| "ubuntu-22.04:clang-15" | |
| "ubuntu-22.04:clang-17" | |
| "ubuntu-24.04:gcc-13" | |
| "ubuntu-24.04:gcc-14" | |
| "ubuntu-24.04:gcc-15" | |
| "ubuntu-24.04:clang-14" | |
| "ubuntu-24.04:clang-15" | |
| "macos-13:gcc-13" | |
| "macos-13:gcc-14" | |
| "macos-13:gcc-15" | |
| "windows-latest:gcc-13" | |
| "windows-latest:gcc-14" | |
| "windows-latest:gcc-15" | |
| ) | |
| combo="${{ matrix.os }}:${{ matrix.compiler }}" | |
| echo "Checking combination: $combo" | |
| for skip in "${skip_list[@]}"; do | |
| if [[ "$combo" == "$skip" ]]; then | |
| echo "SKIP_COMPILE=true" >> "$GITHUB_ENV" | |
| exit 0 | |
| fi | |
| done | |
| echo "SKIP_COMPILE=false" >> "$GITHUB_ENV" | |
| # Linux compiler setup | |
| - name: Setup compiler on Linux | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Linux' }} | |
| run: | | |
| compiler="${{ matrix.compiler }}" | |
| version="${{ matrix.compiler-version }}" | |
| if [[ "$compiler" == clang-* ]]; then | |
| sudo apt-get update | |
| sudo apt-get install -y wget gnupg lsb-release software-properties-common | |
| wget https://apt.llvm.org/llvm.sh | |
| chmod +x llvm.sh | |
| sudo DISTRIB_CODENAME=jammy ./llvm.sh "$version" all | |
| CXX="clang++-$version" | |
| elif [[ "$compiler" == gcc-* ]]; then | |
| sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y | |
| sudo apt-get update | |
| sudo apt-get install -y g++-"$version" | |
| CXX="g++-$version" | |
| else | |
| CXX="g++" | |
| fi | |
| which "$CXX" || { echo "$CXX not found in PATH"; exit 1; } | |
| echo "CXX=$(which $CXX)" >> "$GITHUB_ENV" | |
| # macOS compiler setup | |
| - name: Setup compiler on macOS | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'macOS' }} | |
| run: | | |
| brew install llvm@${{ matrix.compiler-version }} | |
| echo "CC=$(brew --prefix llvm@${{ matrix.compiler-version }})/bin/clang" >> $GITHUB_ENV | |
| echo "CXX=$(brew --prefix llvm@${{ matrix.compiler-version }})/bin/clang++" >> $GITHUB_ENV | |
| # Windows compiler setup | |
| - name: Setup compiler on Windows | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Windows' }} | |
| shell: pwsh | |
| run: | | |
| $version = "${{ matrix.compiler-version }}" | |
| choco install llvm --version=$version -y | |
| echo "CXX=clang++" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # --- Install HDF5 on all OSes --- | |
| - name: Install HDF5 on Linux | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Linux' }} | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libhdf5-dev | |
| - name: Install HDF5 on macOS | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'macOS' }} | |
| run: | | |
| brew install hdf5 | |
| - name: Install HDF5 on Windows | |
| if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Windows' }} | |
| shell: pwsh | |
| run: | | |
| choco install hdf5 -y | |
| # --- Build/Test --- | |
| - name: Configure | |
| if: env.SKIP_COMPILE == 'false' | |
| run: cmake -B build -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release | |
| - name: Build | |
| if: env.SKIP_COMPILE == 'false' | |
| run: cmake --build build --parallel | |
| - name: Test | |
| if: env.SKIP_COMPILE == 'false' | |
| run: ctest --test-dir build --output-on-failure | |
| - name: Record Badge Status | |
| if: always() | |
| run: | | |
| mkdir -p badge-status | |
| status="skipped" | |
| if [[ "$SKIP_COMPILE" == "false" ]]; then | |
| status="${{ job.status }}" | |
| fi | |
| cat <<EOF > badge-status/status-${{ matrix.os }}-${{ matrix.compiler }}.json | |
| { | |
| "os": "${{ matrix.os }}", | |
| "compiler": "${{ matrix.compiler }}", | |
| "status": "$status" | |
| } | |
| EOF | |
| - name: Upload Status Artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: status-${{ matrix.os }}-${{ matrix.compiler }} | |
| path: badge-status/status-${{ matrix.os }}-${{ matrix.compiler }}.json | |
| generate-badges: | |
| name: Generate SVG Badges | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: always() | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Determine badge target directory | |
| id: badge_dir | |
| run: | | |
| if [[ "${GITHUB_REF##*/}" == "staging" ]]; then | |
| echo "dir=badges-staging" >> $GITHUB_OUTPUT | |
| else | |
| echo "dir=badges" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Download all badge status artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: badge-status | |
| pattern: status-* | |
| merge-multiple: true | |
| - name: Generate SVG Badges | |
| run: | | |
| mkdir -p ${{ steps.badge_dir.outputs.dir }} | |
| for f in badge-status/*.json; do | |
| echo "file name: $f" | |
| [[ ! -f "$f" ]] && continue | |
| os=$(jq -r .os "$f") | |
| compiler=$(jq -r .compiler "$f") | |
| status=$(jq -r .status "$f") | |
| color="gray" | |
| symbol="□" | |
| [[ "$status" == "success" ]] && { symbol="✔"; color="green"; prefix="ok"; } | |
| [[ "$status" == "skipped" ]] && { symbol="○"; color="gray"; prefix="na"; } | |
| [[ "$status" == "failure" ]] && { symbol="✘"; color="red"; prefix="failed"; } | |
| label="${os}-${compiler}" | |
| badge="${{ steps.badge_dir.outputs.dir }}/${label}.svg" | |
| echo "https://img.shields.io/badge/${prefix}-${symbol}-${color}.svg $badge" | |
| curl -s "https://img.shields.io/badge/${prefix}-${symbol}-${color}.svg" -o "$badge" | |
| done | |
| - name: Upload badge folder to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./${{ steps.badge_dir.outputs.dir }} | |
| destination_dir: ${{ steps.badge_dir.outputs.dir }} |