From 6fe1c19eacbe19f10a2f9677d67b5df23f5065e7 Mon Sep 17 00:00:00 2001 From: Matthew Rodusek <7519129+bitwizeshift@users.noreply.github.com> Date: Fri, 27 Sep 2024 00:37:26 +0000 Subject: [PATCH] Decompose GitHub actions The `prepare-runner` GitHub action was getting bloated, so this decomposes it into smaller more granular and reusable actions instead. This should improve caching and reduce the amount of `apt-get`s being done. --- .github/actions/prepare-runner/action.yaml | 134 ++---------------- .github/actions/setup-boxer/action.yaml | 19 +++ .github/actions/setup-clang/action.yaml | 28 ++++ .github/actions/setup-glfw/action.yaml | 23 +++ .github/actions/setup-openal-soft/action.yaml | 26 ++++ .github/actions/setup-vulkan/action.yaml | 81 +++++++++++ .github/actions/update-apt/action.yaml | 14 ++ 7 files changed, 203 insertions(+), 122 deletions(-) create mode 100644 .github/actions/setup-boxer/action.yaml create mode 100644 .github/actions/setup-clang/action.yaml create mode 100644 .github/actions/setup-glfw/action.yaml create mode 100644 .github/actions/setup-openal-soft/action.yaml create mode 100644 .github/actions/setup-vulkan/action.yaml create mode 100644 .github/actions/update-apt/action.yaml diff --git a/.github/actions/prepare-runner/action.yaml b/.github/actions/prepare-runner/action.yaml index 44eb1f3..4819818 100644 --- a/.github/actions/prepare-runner/action.yaml +++ b/.github/actions/prepare-runner/action.yaml @@ -4,133 +4,23 @@ description: "Prepares the underlying runner for building this project" runs: using: "composite" steps: - # Install base dependencies + - name: Setup Clang + uses: ./.github/actions/setup-clang - # ubuntu-latest, windows-latest, and macos-latest all come with cmake and - # clang, so we don't need any of these base dependencies. - # - # See: - # - https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md - # - https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md - # - https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md + - name: Update package cache + uses: ./.github/actions/update-apt - - name: Prepare compiler - shell: bash - if: runner.os == 'Linux' - run: | - echo "CC=clang-18" >> "${GITHUB_ENV}" - echo "CXX=clang++-18" >> "${GITHUB_ENV}" + - name: Setup OpenAL Soft + uses: ./.github/actions/setup-openal-soft - - name: Prepare compiler - shell: bash - if: runner.os == 'macOS' - run: | - echo "CC=$(brew --prefix llvm@15)/bin/clang" >> "${GITHUB_ENV}" - echo "CXX=$(brew --prefix llvm@15)/bin/clang++" >> "${GITHUB_ENV}" + - name: Setup GLFW + uses: ./.github/actions/setup-glfw - # OpenAL + - name: Setup Boxer + uses: ./.github/actions/setup-boxer - # macOS and Windows both use builtin audio-requirements, so only the linux - # runners need to install the audio dependencies in order to work. - - - name: Install OpenAL requirements - shell: bash - if: runner.os == 'Linux' - run: | - # Install pulseaudio, portaudio, ALSA, JACK dependencies for - # corresponding backends. - # Install Qt5 dependency for alsoft-config. - sudo apt-get update -y - sudo apt-get install -y -qq \ - libpulse-dev \ - portaudio19-dev \ - libasound2-dev \ - libjack-dev \ - qtbase5-dev - - # GLFW - - # macOS and Windows both use builtin requirements for GLFW, so only the linux - # runners need to install dependencies. - - - name: Install GLFW requirements - shell: bash - if: runner.os == 'Linux' - run: | - sudo apt-get update -y - sudo apt-get install -y -qq \ - libxrandr-dev \ - libxinerama-dev \ - libxcursor-dev \ - libxi-dev \ - libx11-dev - - # Boxer - - - name: Install Boxer requirements - shell: bash - if: runner.os == 'Linux' - run: | - sudo apt-get install -y -qq \ - libgtk-3-dev - - # Vulkan - - - name: Cache vulkan-sdk.dmg - uses: actions/cache@v4 - if: runner.os == 'macOS' - id: download-vulkan - with: - path: vulkan-sdk.dmg - key: vulkan-sdk-${{ runner.os }} - - - name: Create Temp Directory - shell: bash - id: dir - run: | - path="${{ runner.temp }}/vulkan-sdk" - mkdir -p "${path}" - echo path="${path}" >> "${GITHUB_OUTPUT}" - - - name: Install Vulkan SDK - if: runner.os == 'Linux' - shell: bash - working-directory: "${{ steps.dir.outputs.path }}" - run: | - wget https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz - tar -xf vulkan-sdk.tar.xz - root=$(dirname "$(find . -type d -name "bin")") - echo VULKAN_SDK="${root}" >> "${GITHUB_ENV}" - echo LD_LIBRARY_PATH="${root}/lib:$LD_LIBRARY_PATH" >> "${GITHUB_ENV}" - echo VK_ADD_LAYER_PATH="${root}/share/vulkan/explicit_layer.d${VK_ADD_LAYER_PATH:+:$VK_ADD_LAYER_PATH}" >> "${GITHUB_ENV}" - echo "${root}/bin" >> "${GITHUB_PATH}" - - - name: Download vulkan-sdk.dmg - shell: bash - if: runner.os == 'macOS' && steps.download-vulkan.outputs.cache-hit != 'true' - run: | - wget https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg - - - name: Install Vulkan SDK - shell: bash - if: runner.os == 'macOS' - run: | - hdiutil attach vulkan-sdk.dmg -mountpoint vulkan-sdk - vulkan_root="${HOME}/VulkanSDK" - ./vulkan-sdk/InstallVulkan.app/Contents/MacOS/InstallVulkan \ - --root "${vulkan_root}" \ - --accept-licenses \ - --default-answer \ - --confirm-command install - - export VULKAN_SDK="${vulkan_root}/macOS" - echo VULKAN_SDK="${VULKAN_SDK}" >> "${GITHUB_ENV}" - echo DYLD_LIBRARY_PATH="$VULKAN_SDK/lib:$DYLD_LIBRARY_PATH" >> "${GITHUB_ENV}" - echo LD_LIBRARY_PATH="$VULKAN_SDK/lib:$LD_LIBRARY_PATH" >> "${GITHUB_ENV}" - echo VK_ICD_FILENAMES="$VULKAN_SDK/etc/vulkan/icd.d/MoltenVK_icd.json" >> "${GITHUB_ENV}" - echo VK_LAYER_PATH="$VULKAN_SDK/share/vulkan/explicit_layer.d" >> "${GITHUB_ENV}" - echo "$VULKAN_SDK/bin" >> "${GITHUB_PATH}" - ls -la $VULKAN_SDK/lib + - name: Setup Vulkan + uses: ./.github/actions/setup-vulkan - name: Checkout 3rd-party uses: ./.github/actions/checkout diff --git a/.github/actions/setup-boxer/action.yaml b/.github/actions/setup-boxer/action.yaml new file mode 100644 index 0000000..f6144dc --- /dev/null +++ b/.github/actions/setup-boxer/action.yaml @@ -0,0 +1,19 @@ +name: Setup Boxer +description: | + Installs prerequisites to be able to build and run Boxer. + +runs: + using: composite + steps: + - name: Update Apt + if: runner.os == 'Linux' + uses: ./.github/actions/update-apt + + # macOS and Windows both use builtin requirements for Boxer, so only the linux + # runners need to install dependencies. + - name: Install Boxer requirements + shell: bash + if: runner.os == 'Linux' + run: | + sudo apt-get install -y -qq \ + libgtk-3-dev diff --git a/.github/actions/setup-clang/action.yaml b/.github/actions/setup-clang/action.yaml new file mode 100644 index 0000000..4795dcc --- /dev/null +++ b/.github/actions/setup-clang/action.yaml @@ -0,0 +1,28 @@ +name: Setup Clang +description: | + Prepares the runner image for compiling with `clang`. + +runs: + using: composite + steps: + # ubuntu-latest, windows-latest, and macos-latest all come with cmake and + # clang, so we don't need any of these base dependencies. + # + # See: + # - https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md + # - https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md + # - https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md + + - name: Prepare compiler + shell: bash + if: runner.os == 'Linux' + run: | + echo "CC=clang-18" >> "${GITHUB_ENV}" + echo "CXX=clang++-18" >> "${GITHUB_ENV}" + + - name: Prepare compiler + shell: bash + if: runner.os == 'macOS' + run: | + echo "CC=$(brew --prefix llvm@18)/bin/clang" >> "${GITHUB_ENV}" + echo "CXX=$(brew --prefix llvm@18)/bin/clang++" >> "${GITHUB_ENV}" diff --git a/.github/actions/setup-glfw/action.yaml b/.github/actions/setup-glfw/action.yaml new file mode 100644 index 0000000..0142818 --- /dev/null +++ b/.github/actions/setup-glfw/action.yaml @@ -0,0 +1,23 @@ +name: Setup GLFW +description: | + Installs prerequisites to be able to build and run GLFW. + +runs: + using: composite + steps: + - name: Update Apt + if: runner.os == 'Linux' + uses: ./.github/actions/update-apt + + # macOS and Windows both use builtin requirements for GLFW, so only the linux + # runners need to install dependencies. + - name: Install GLFW requirements + shell: bash + if: runner.os == 'Linux' + run: | + sudo apt-get install -y -qq \ + libxrandr-dev \ + libxinerama-dev \ + libxcursor-dev \ + libxi-dev \ + libx11-dev diff --git a/.github/actions/setup-openal-soft/action.yaml b/.github/actions/setup-openal-soft/action.yaml new file mode 100644 index 0000000..bec17c8 --- /dev/null +++ b/.github/actions/setup-openal-soft/action.yaml @@ -0,0 +1,26 @@ +name: Setup GLEW +description: | + Installs prerequisites to be able to build GLEW + +runs: + using: composite + steps: + - name: Update Apt + if: runner.os == 'Linux' + uses: ./.github/actions/update-apt + + # macOS and Windows both use builtin audio-requirements, so only the linux + # runners need to install the audio dependencies in order to work. + - name: Install OpenAL requirements + shell: bash + if: runner.os == 'Linux' + run: | + # Install pulseaudio, portaudio, ALSA, JACK dependencies for + # corresponding backends. + # Install Qt5 dependency for alsoft-config. + sudo apt-get install -y -qq \ + libpulse-dev \ + portaudio19-dev \ + libasound2-dev \ + libjack-dev \ + qtbase5-dev diff --git a/.github/actions/setup-vulkan/action.yaml b/.github/actions/setup-vulkan/action.yaml new file mode 100644 index 0000000..6340fba --- /dev/null +++ b/.github/actions/setup-vulkan/action.yaml @@ -0,0 +1,81 @@ +name: Setup Vulkan +description: | + Installs prerequisites to be able to build Vulkan. + +runs: + using: composite + steps: + - name: Create Temp Directory + shell: bash + id: dir + run: | + path="${{ runner.temp }}/vulkan-sdk" + mkdir -p "${path}" + echo path="${path}" >> "${GITHUB_OUTPUT}" + + - name: Prepare download path + shell: bash + id: prepare + run: | + if [[ "${{ runner.os }}" == "Linux" ]]; then + path="${{ steps.dir.outputs.path }}/vulkan-sdk.tar.xz" + else + path="${{ steps.dir.outputs.path }}/vulkan-sdk.dmg" + fi + echo "sdk-binary=${path}" >> "${GITHUB_OUTPUT}" + + - name: Cache vulkan-sdk + uses: actions/cache@v4 + id: cache-vulkan + with: + path: ${{ steps.prepare.outputs.sdk-binary }} + key: vulkan-sdk-${{ runner.os }} + + - name: Download vulkan-sdk + shell: bash + if: steps.cache-vulkan.outputs.cache-hit != 'true' + working-directory: "${{ steps.dir.outputs.path }}" + id: download + run: | + if [[ "${{ runner.os }}" == "Linux" ]]; then + wget https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz + else + wget https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg + fi + + - name: Install Vulkan SDK (Linux) + if: runner.os == 'Linux' + shell: bash + working-directory: "${{ steps.dir.outputs.path }}" + run: | + tar -xf "${{ steps.download.outputs.path }}" + export VULKAN_SDK=$(dirname "$(find . -type d -name "bin")") + echo VULKAN_SDK="${VULKAN_SDK}" >> "${GITHUB_ENV}" + echo LD_LIBRARY_PATH="${VULKAN_SDK}/lib:$LD_LIBRARY_PATH" >> "${GITHUB_ENV}" + echo VK_ADD_LAYER_PATH="${VULKAN_SDK}/share/vulkan/explicit_layer.d${VK_ADD_LAYER_PATH:+:$VK_ADD_LAYER_PATH}" >> "${GITHUB_ENV}" + echo "${VULKAN_SDK}/bin" >> "${GITHUB_PATH}" + + - name: Install Vulkan SDK (macOS) + shell: bash + if: runner.os == 'macOS' + run: | + hdiutil attach "${{ steps.download.outputs.path }}" -mountpoint vulkan-sdk + vulkan_root="${HOME}/VulkanSDK" + ./vulkan-sdk/InstallVulkan.app/Contents/MacOS/InstallVulkan \ + --root "${vulkan_root}" \ + --accept-licenses \ + --default-answer \ + --confirm-command install + + export VULKAN_SDK="${vulkan_root}/macOS" + echo VULKAN_SDK="${VULKAN_SDK}" >> "${GITHUB_ENV}" + echo DYLD_LIBRARY_PATH="$VULKAN_SDK/lib:$DYLD_LIBRARY_PATH" >> "${GITHUB_ENV}" + echo LD_LIBRARY_PATH="$VULKAN_SDK/lib:$LD_LIBRARY_PATH" >> "${GITHUB_ENV}" + echo VK_ICD_FILENAMES="$VULKAN_SDK/etc/vulkan/icd.d/MoltenVK_icd.json" >> "${GITHUB_ENV}" + echo VK_LAYER_PATH="$VULKAN_SDK/share/vulkan/explicit_layer.d" >> "${GITHUB_ENV}" + echo "$VULKAN_SDK/bin" >> "${GITHUB_PATH}" + + - name: Print SDK Contents + shell: bash + run: | + find "${VULKAN_SDK}" -type f diff --git a/.github/actions/update-apt/action.yaml b/.github/actions/update-apt/action.yaml new file mode 100644 index 0000000..419c824 --- /dev/null +++ b/.github/actions/update-apt/action.yaml @@ -0,0 +1,14 @@ +name: Update Apt +description: | + Updates the apt cache for the runner, caching whether the cache was already + updated. If run on a non-Linux runner, this action will do nothing. + +runs: + using: composite + steps: + - name: Install Boxer requirements + shell: bash + if: runner.os == 'Linux' && env.APT_UPDATED != 'true' + run: | + sudo apt-get update -y -qq + echo "APT_UPDATED=true" >> "${GITHUB_ENV}"