瀏覽代碼

Clean up GitHub actions

Anonymous Maarten 3 月之前
父節點
當前提交
4c5aee621e
共有 4 個文件被更改,包括 140 次插入38 次删除
  1. 62 0
      .github/actions/setup-ninja/action.yml
  2. 55 18
      .github/workflows/main.yml
  3. 0 20
      .github/workflows/os2.yml
  4. 23 0
      cmake/test/CMakeLists.txt

+ 62 - 0
.github/actions/setup-ninja/action.yml

@@ -0,0 +1,62 @@
+name: 'Setup ninja'
+description: 'Download ninja and add it to the PATH environment variable'
+inputs:
+  version:
+    description: 'Ninja version'
+    default: '1.13.1'
+runs:
+  using: 'composite'
+  steps:
+    - name: 'Calculate variables'
+      id: calc
+      shell: sh
+      run: |
+        case "${{ runner.os }}-${{ runner.arch }}" in
+          "Linux-X86" | "Linux-X64")
+            archive="ninja-linux.zip"
+            ;;
+          "Linux-ARM64")
+            archive="ninja-linux-aarch64.zip"
+            ;;
+          "macOS-X86" | "macOS-X64" | "macOS-ARM64")
+            archive="ninja-mac.zip"
+            ;;
+          "Windows-X86" | "Windows-X64")
+            archive="ninja-win.zip"
+            ;;
+          "Windows-ARM64")
+            archive="ninja-winarm64.zip"
+            ;;
+          *)
+            echo "Unsupported ${{ runner.os }}-${{ runner.arch }}"
+            exit 1;
+            ;;
+        esac
+        echo "archive=${archive}" >> ${GITHUB_OUTPUT}
+        echo "cache-key=${archive}-${{ inputs.version }}-${{ runner.os }}-${{ runner.arch }}" >> ${GITHUB_OUTPUT}
+    - name: 'Restore cached ${{ steps.calc.outputs.archive }}'
+      id: cache-restore
+      uses: actions/cache/restore@v4
+      with:
+        path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
+        key: ${{ steps.calc.outputs.cache-key }}
+    - name: 'Download ninja ${{ inputs.version }} for ${{ runner.os }} (${{ runner.arch }})'
+      if: ${{ (!steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false') }}
+      shell: pwsh
+      run: |
+        Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v${{ inputs.version }}/${{ steps.calc.outputs.archive }}" -OutFile "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
+    - name: 'Cache ${{ steps.calc.outputs.archive }}'
+      if: ${{ (!steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false') }}
+      uses: actions/cache/save@v4
+      with:
+        path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
+        key: ${{ steps.calc.outputs.cache-key }}
+    - name: 'Extract ninja'
+      shell: pwsh
+      run: |
+        7z "-o${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" x "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
+    - name: 'Set output variables'
+      id: final
+      shell: pwsh
+      run: |
+        echo "${{ runner.temp }}/ninja-${{ inputs.version }}-${{ runner.arch }}" >> $env:GITHUB_PATH

+ 55 - 18
.github/workflows/main.yml

@@ -3,28 +3,65 @@ name: Build
 on: [push, pull_request]
 
 jobs:
-  Build:
+  desktop:
     name: ${{ matrix.platform.name }}
     runs-on: ${{ matrix.platform.os }}
+    defaults:
+      run:
+        shell: sh
     strategy:
+      fail-fast: false
       matrix:
         platform:  # !!! FIXME: figure out an efficient way to get SDL2 on the Windows/Mac bots.
-        - { name: Linux,   os: ubuntu-latest, flags: -GNinja }
-        - { name: MinGW,   os: windows-latest, flags: -GNinja -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_SYSTEM_NAME=Windows }
-        - { name: Windows, os: windows-latest }
-        - { name: MacOS,   os: macos-latest }
+        - { name: Linux,   os: ubuntu-latest }
+        - { name: MinGW,   os: windows-latest, flags: -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_SYSTEM_NAME=Windows }
+        - { name: Windows, os: windows-latest, msvc: true }
+        - { name: macOS,   os: macos-latest }
     steps:
-    - name: Setup Linux dependencies
-      if: runner.os == 'Linux'
-      run: |
-        sudo apt-get update
-        sudo apt-get install ninja-build
-    - name: Setup MinGW dependencies
-      if: contains(matrix.platform.name, 'MinGW')
-      run:  choco install ninja
     - name: Get PhysicsFS sources
-      uses: actions/checkout@v4
-    - name: Configure CMake
-      run: cmake -B build ${{ matrix.platform.flags }}
-    - name: Build
-      run: cmake --build build/
+      uses: actions/checkout@v6
+    - uses: ilammy/msvc-dev-cmd@v1
+      if: ${{ !!matrix.platform.msvc }}
+      with:
+        arch: x64
+    - name: Set up ninja
+      uses: ./.github/actions/setup-ninja
+    - name: Configure (CMake)
+      run: |
+        cmake -B build -GNinja \
+          -DCMAKE_BUILD_TYPE=Release \
+          -DCMAKE_INSTALL_PREFIX=prefix_cmake \
+          ${{ matrix.platform.flags }}
+    - name: Build (CMake)
+      run: |
+        cmake --build build/ --verbose
+    - name: Install (CMake)
+      run: |
+        set -eu
+        cmake --install build/
+        echo "PhysFS_ROOT=$(pwd)/prefix_cmake" >> $GITHUB_ENV
+    - name: Verify CMake configuration files
+      run: |
+        cmake -S cmake/test -B cmake_config_build \
+          -DCMAKE_BUILD_TYPE=Release \
+          -DTEST_SHARED=${{ matrix.platform.shared }} \
+          -DTEST_STATIC=${{ matrix.platform.static }}
+        cmake --build cmake_config_build --verbose
+    - name: 'Test versioning'
+      run: |
+        build-scripts/test-versioning.sh
+
+  os2:
+    name: OS/2
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v6
+      - uses: open-watcom/setup-watcom@v0
+      - name: Build physfs.dll
+        run: |
+          cd src
+          wmake -sn -f Makefile.os2
+      - name: distclean
+        run: |
+          cd src
+          wmake -sn -f Makefile.os2 distclean

+ 0 - 20
.github/workflows/os2.yml

@@ -1,20 +0,0 @@
-name: Build (OS/2)
-
-on: [push, pull_request]
-
-jobs:
-  os2:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v4
-      - uses: open-watcom/setup-watcom@v0
-      - name: Build physfs.dll
-        run: |
-          cd src
-          wmake -f Makefile.os2
-          cd ..
-      - name: distclean
-        run: |
-          cd src
-          wmake -f Makefile.os2 distclean
-          cd ..

+ 23 - 0
cmake/test/CMakeLists.txt

@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.0...4.0)
+project(test_physfs C)
+
+# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3_mixer outside of sysroot
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
+
+option(TEST_STATIC "Test static PhysFS library" ON)
+if(TEST_STATIC)
+    find_package(PhysFS CONFIG REQUIRED COMPONENTS PhysFS-static)
+    add_executable(a-static ../../test/test_physfs.c)
+    target_link_libraries(a-static PRIVATE PhysFS::PhysFS-static)
+endif()
+
+option(TEST_SHARED "Test shared PhysFS library" ON)
+if(TEST_SHARED)
+    find_package(PhysFS CONFIG REQUIRED COMPONENTS PhysFS-shared)
+    add_executable(a-shared ../../test/test_physfs.c)
+    target_link_libraries(a-shared PRIVATE PhysFS::PhysFS-shared)
+endif()
+
+find_package(PhysFS CONFIG REQUIRED COMPONENTS PhysFS)
+add_executable(a ../../test/test_physfs.c)
+target_link_libraries(a PRIVATE PhysFS::PhysFS)