|
| 1 | +name: CMake with Ninja and GitHub Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: [ "v*" ] # Trigger only on version tag pushes (e.g., v1.0.0) |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ${{ matrix.os }} |
| 10 | + |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + os: [ubuntu-latest, windows-latest] |
| 15 | + build_type: [Release] |
| 16 | + c_compiler: [gcc, clang, cl] |
| 17 | + include: |
| 18 | + - os: windows-latest |
| 19 | + c_compiler: cl |
| 20 | + cpp_compiler: cl |
| 21 | + - os: ubuntu-latest |
| 22 | + c_compiler: gcc |
| 23 | + cpp_compiler: g++ |
| 24 | + - os: ubuntu-latest |
| 25 | + c_compiler: clang |
| 26 | + cpp_compiler: clang++ |
| 27 | + exclude: |
| 28 | + - os: windows-latest |
| 29 | + c_compiler: gcc |
| 30 | + - os: windows-latest |
| 31 | + c_compiler: clang |
| 32 | + - os: ubuntu-latest |
| 33 | + c_compiler: cl |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Install Ninja (Linux only) |
| 40 | + if: runner.os == 'Linux' |
| 41 | + run: sudo apt-get update && sudo apt-get install -y ninja-build |
| 42 | + |
| 43 | + - name: Set reusable strings |
| 44 | + id: strings |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" |
| 48 | + echo "artifact-name=release-${{ matrix.os }}-${{ matrix.c_compiler }}" >> "$GITHUB_OUTPUT" |
| 49 | +
|
| 50 | + - name: Setup MSVC Developer Command Prompt |
| 51 | + if: runner.os == 'Windows' |
| 52 | + uses: ilammy/msvc-dev-cmd@v1 |
| 53 | + |
| 54 | + - name: Configure CMake (Ninja) |
| 55 | + run: > |
| 56 | + cmake -G Ninja |
| 57 | + -B ${{ steps.strings.outputs.build-output-dir }} |
| 58 | + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} |
| 59 | + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} |
| 60 | + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} |
| 61 | + -S ${{ github.workspace }} |
| 62 | +
|
| 63 | +
|
| 64 | + - name: Build |
| 65 | + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} |
| 66 | + |
| 67 | + - name: Archive Build Artifacts |
| 68 | + shell: pwsh |
| 69 | + run: | |
| 70 | + New-Item -ItemType Directory -Force -Path release |
| 71 | + Copy-Item -Path "${{ steps.strings.outputs.build-output-dir }}\*" -Destination release -Recurse |
| 72 | + Compress-Archive -Path release\* -DestinationPath "${{ steps.strings.outputs.artifact-name }}.zip" |
| 73 | +
|
| 74 | + - name: Upload Artifact to CI |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + with: |
| 77 | + name: ${{ steps.strings.outputs.artifact-name }} |
| 78 | + path: ${{ steps.strings.outputs.artifact-name }}.zip |
| 79 | + |
| 80 | + - name: Upload to GitHub Release |
| 81 | + uses: softprops/action-gh-release@v2 |
| 82 | + with: |
| 83 | + tag_name: ${{ github.ref_name }} |
| 84 | + name: Release ${{ github.ref_name }} |
| 85 | + files: ${{ steps.strings.outputs.artifact-name }}.zip |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments