Update cmake-multi-platform.yml #2
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
| # CMake CI across multiple platforms + artifacts + release on tag | |
| name: CMake on multiple platforms | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: [ "v*" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| # Needed so we can create releases | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| build_type: [Release] | |
| c_compiler: [gcc, clang, cl] | |
| include: | |
| - os: windows-latest | |
| c_compiler: cl | |
| cpp_compiler: cl | |
| - os: ubuntu-latest | |
| c_compiler: gcc | |
| cpp_compiler: g++ | |
| - os: ubuntu-latest | |
| c_compiler: clang | |
| cpp_compiler: clang++ | |
| exclude: | |
| - os: windows-latest | |
| c_compiler: gcc | |
| - os: windows-latest | |
| c_compiler: clang | |
| - os: ubuntu-latest | |
| c_compiler: cl | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set reusable strings | |
| id: strings | |
| shell: bash | |
| run: | | |
| echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | |
| # Artifact name includes OS, compiler, and build type | |
| echo "artifact-name=${{ runner.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" | |
| - name: Configure CMake | |
| run: > | |
| cmake -B ${{ steps.strings.outputs.build-output-dir }} | |
| -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | |
| -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
| -S ${{ github.workspace }} | |
| - name: Build | |
| run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} | |
| - name: Test | |
| working-directory: ${{ steps.strings.outputs.build-output-dir }} | |
| run: ctest --build-config ${{ matrix.build_type }} | |
| # Upload everything in the build directory | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.strings.outputs.artifact-name }} | |
| path: | | |
| ${{ steps.strings.outputs.build-output-dir }}/**/* | |
| if-no-files-found: warn | |
| retention-days: 7 | |
| release: | |
| # Only run when the ref is a tag (e.g., refs/tags/v1.2.3) | |
| if: startsWith(github.ref, 'refs/tags/') | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Generate checksums | |
| run: | | |
| cd dist | |
| find . -type f -print0 | xargs -0 sha256sum > SHA256SUMS.txt | |
| cd - | |
| - name: Create GitHub Release and upload files | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| dist/**/* | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |