|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ release, staging ] |
| 6 | + pull_request: |
| 7 | + branches: [ release, staging ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: ${{ matrix.os }} / ${{ matrix.compiler }} |
| 12 | + runs-on: ${{ matrix.os }} |
| 13 | + |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + os: [ubuntu-22.04, ubuntu-24.04] |
| 18 | + compiler: [gcc-13, gcc-14, gcc-15, clang-17, clang-18, clang-19, clang-20] |
| 19 | + include: |
| 20 | + - compiler: gcc-13 |
| 21 | + compiler-version: 13 |
| 22 | + - compiler: gcc-14 |
| 23 | + compiler-version: 14 |
| 24 | + - compiler: gcc-15 |
| 25 | + compiler-version: 15 |
| 26 | + - compiler: clang-17 |
| 27 | + compiler-version: 17 |
| 28 | + - compiler: clang-18 |
| 29 | + compiler-version: 18 |
| 30 | + - compiler: clang-19 |
| 31 | + compiler-version: 19 |
| 32 | + - compiler: clang-20 |
| 33 | + compiler-version: 20 |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Set badge output directory |
| 38 | + id: path |
| 39 | + run: | |
| 40 | + if [[ "${GITHUB_REF##*/}" == "staging" ]]; then |
| 41 | + echo "dir=status-staging" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "dir=status" >> $GITHUB_OUTPUT |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Check skip list |
| 47 | + id: skip_check |
| 48 | + run: | |
| 49 | + skip_list=( |
| 50 | + "ubuntu-22.04:gcc-14" |
| 51 | + "ubuntu-22.04:gcc-15" |
| 52 | + "ubuntu-24.04:gcc-15" |
| 53 | + "ubuntu-24.04:clang-17" |
| 54 | + "macos-13:gcc-13" |
| 55 | + "macos-13:gcc-14" |
| 56 | + "macos-13:gcc-15" |
| 57 | + ) |
| 58 | +
|
| 59 | + combo="${{ matrix.os }}:${{ matrix.compiler }}" |
| 60 | + echo "Checking combination: $combo" |
| 61 | + for skip in "${skip_list[@]}"; do |
| 62 | + if [[ "$combo" == "$skip" ]]; then |
| 63 | + echo "SKIP_COMPILE=true" >> "$GITHUB_ENV" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + done |
| 67 | + echo "SKIP_COMPILE=false" >> "$GITHUB_ENV" |
| 68 | +
|
| 69 | + - name: Setup compiler on macOS |
| 70 | + if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'macOS' }} |
| 71 | + run: | |
| 72 | + brew install llvm@${{ matrix.compiler-version }} |
| 73 | + echo "CC=$(brew --prefix llvm@${{ matrix.compiler-version }})/bin/clang" >> $GITHUB_ENV |
| 74 | + echo "CXX=$(brew --prefix llvm@${{ matrix.compiler-version }})/bin/clang++" >> $GITHUB_ENV |
| 75 | +
|
| 76 | + - name: Setup compiler on Linux |
| 77 | + if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Linux' }} |
| 78 | + run: | |
| 79 | + compiler="${{ matrix.compiler }}" |
| 80 | + version="${{ matrix.compiler-version }}" |
| 81 | +
|
| 82 | + if [[ "$compiler" == clang-* ]]; then |
| 83 | + sudo apt-get update |
| 84 | + sudo apt-get install -y wget gnupg lsb-release software-properties-common |
| 85 | + wget https://apt.llvm.org/llvm.sh |
| 86 | + chmod +x llvm.sh |
| 87 | + sudo DISTRIB_CODENAME=jammy ./llvm.sh "$version" all |
| 88 | + CXX="clang++-$version" |
| 89 | + elif [[ "$compiler" == gcc-* ]]; then |
| 90 | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y |
| 91 | + sudo apt-get update |
| 92 | + sudo apt-get install -y g++-"$version" |
| 93 | + CXX="g++-$version" |
| 94 | + else |
| 95 | + CXX="g++" |
| 96 | + fi |
| 97 | +
|
| 98 | + which "$CXX" || { echo "$CXX not found in PATH"; exit 1; } |
| 99 | + echo "CXX=$(which $CXX)" >> "$GITHUB_ENV" |
| 100 | +
|
| 101 | + - name: Checkout |
| 102 | + uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + fetch-depth: 0 |
| 105 | + |
| 106 | + - name: Install system dependencies on macOS |
| 107 | + if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'macOS' }} |
| 108 | + run: | |
| 109 | + brew update |
| 110 | + brew install hdf5 |
| 111 | +
|
| 112 | + - name: Install system dependencies on Linux |
| 113 | + if: ${{ env.SKIP_COMPILE == 'false' && runner.os == 'Linux' }} |
| 114 | + run: sudo apt-get update && sudo apt-get install -y libhdf5-dev |
| 115 | + |
| 116 | + |
| 117 | + - name: Configure |
| 118 | + if: env.SKIP_COMPILE == 'false' |
| 119 | + run: cmake -B build -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release |
| 120 | + |
| 121 | + - name: Build |
| 122 | + if: env.SKIP_COMPILE == 'false' |
| 123 | + run: cmake --build build --parallel |
| 124 | + |
| 125 | + - name: Test |
| 126 | + if: env.SKIP_COMPILE == 'false' |
| 127 | + run: ctest --test-dir build --output-on-failure |
| 128 | + |
| 129 | + - name: Record Badge Status |
| 130 | + if: always() |
| 131 | + run: | |
| 132 | + mkdir -p badge-status |
| 133 | + status="skipped" |
| 134 | + if [[ "$SKIP_COMPILE" == "false" ]]; then |
| 135 | + status="${{ job.status }}" |
| 136 | + fi |
| 137 | +
|
| 138 | + cat <<EOF > badge-status/status-${{ matrix.os }}-${{ matrix.compiler }}.json |
| 139 | + { |
| 140 | + "os": "${{ matrix.os }}", |
| 141 | + "compiler": "${{ matrix.compiler }}", |
| 142 | + "status": "$status" |
| 143 | + } |
| 144 | + EOF |
| 145 | + - name: Upload Status Artifact |
| 146 | + if: always() |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: status-${{ matrix.os }}-${{ matrix.compiler }} |
| 150 | + path: badge-status/status-${{ matrix.os }}-${{ matrix.compiler }}.json |
| 151 | + |
| 152 | + generate-badges: |
| 153 | + name: Generate SVG Badges |
| 154 | + runs-on: ubuntu-latest |
| 155 | + needs: build |
| 156 | + if: always() |
| 157 | + |
| 158 | + steps: |
| 159 | + - uses: actions/checkout@v4 |
| 160 | + |
| 161 | + - name: Determine badge target directory |
| 162 | + id: badge_dir |
| 163 | + run: | |
| 164 | + if [[ "${GITHUB_REF##*/}" == "staging" ]]; then |
| 165 | + echo "dir=badges-staging" >> $GITHUB_OUTPUT |
| 166 | + else |
| 167 | + echo "dir=badges" >> $GITHUB_OUTPUT |
| 168 | + fi |
| 169 | +
|
| 170 | + - name: Download all badge status artifacts |
| 171 | + uses: actions/download-artifact@v4 |
| 172 | + with: |
| 173 | + path: badge-status |
| 174 | + pattern: status-* |
| 175 | + merge-multiple: true |
| 176 | + |
| 177 | + - name: Generate SVG Badges |
| 178 | + run: | |
| 179 | + mkdir -p ${{ steps.badge_dir.outputs.dir }} |
| 180 | + for f in badge-status/*.json; do |
| 181 | + echo "file name: $f" |
| 182 | + [[ ! -f "$f" ]] && continue |
| 183 | + os=$(jq -r .os "$f") |
| 184 | + compiler=$(jq -r .compiler "$f") |
| 185 | + status=$(jq -r .status "$f") |
| 186 | +
|
| 187 | + color="gray" |
| 188 | + symbol="□" |
| 189 | +
|
| 190 | + [[ "$status" == "success" ]] && { symbol="✔"; color="green"; prefix="ok"; } |
| 191 | + [[ "$status" == "skipped" ]] && { symbol="○"; color="gray"; prefix="na"; } |
| 192 | + [[ "$status" == "failure" ]] && { symbol="✘"; color="red"; prefix="failed"; } |
| 193 | +
|
| 194 | + label="${os}-${compiler}" |
| 195 | + badge="${{ steps.badge_dir.outputs.dir }}/${label}.svg" |
| 196 | + echo "https://img.shields.io/badge/${prefix}-${symbol}-${color}.svg $badge" |
| 197 | + curl -s "https://img.shields.io/badge/${prefix}-${symbol}-${color}.svg" -o "$badge" |
| 198 | + done |
| 199 | +
|
| 200 | + - name: Upload badge folder to GitHub Pages |
| 201 | + uses: peaceiris/actions-gh-pages@v3 |
| 202 | + with: |
| 203 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 204 | + publish_dir: ./${{ steps.badge_dir.outputs.dir }} |
| 205 | + destination_dir: ${{ steps.badge_dir.outputs.dir }} |
0 commit comments