From 63702d04d46fd7b4f04bb71cdfa8eb41c2256e26 Mon Sep 17 00:00:00 2001 From: LangLang03 Date: Thu, 24 Sep 2026 02:58:35 +0800 Subject: [PATCH] ci: cache builds and avoid duplicate master checks --- .github/workflows/ci.yml | 45 +++++++++++++++++-------- .github/workflows/release.yml | 7 ++-- tools/generate_android_library_graph.sh | 17 ++++++++++ 3 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 tools/generate_android_library_graph.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c89a35e5..e5a8b087 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,10 @@ name: CI -# Push only. A push to a branch that has an open pull request raises both the -# `push` and the `pull_request` event, so listening to both ran every check -# twice for one commit. Fork pull requests are not tested by this workflow; -# their commits are not pushed here. +# Pull requests to protected master are already checked on dev. The merge +# commit starts Release when the version changes, so it does not need CI again. on: push: - branches: [master, dev] + branches: [dev] workflow_dispatch: permissions: @@ -20,6 +18,10 @@ jobs: native-tests: name: C++23 / GoogleTest runs-on: ubuntu-latest + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_MAXSIZE: 500M # Ubuntu 24.04 ships GCC 13 and the toolchain PPA only offers a March 2026 # GCC 16 snapshot; both mis-compile this codebase (a spurious # -Wfree-nonheap-object, then an internal compiler error in gimplify). The @@ -38,7 +40,7 @@ jobs: set -euo pipefail apt-get update apt-get install --yes --no-install-recommends \ - ninja-build libgtest-dev libsqlite3-dev libssl-dev zlib1g-dev \ + ninja-build ccache libgtest-dev libsqlite3-dev libssl-dev zlib1g-dev \ libcurl4-openssl-dev cmake curl git ca-certificates \ libgtk-4-1 libgraphene-1.0-0 libepoxy0 libsoup-3.0-0 \ libgstreamer-plugins-base1.0-0 @@ -48,6 +50,17 @@ jobs: g++ --version | head -1 cmake --version | head -1 + - name: Restore C++ compilation cache + uses: actions/cache@v4 + with: + path: .ccache + key: ccache-gcc16.2-${{ runner.os }}-${{ github.sha }} + restore-keys: | + ccache-gcc16.2-${{ runner.os }}- + + - name: Reset C++ cache statistics + run: ccache --zero-stats + - name: Install HuxerUI SDK 0.3.0 timeout-minutes: 10 run: | @@ -68,7 +81,9 @@ jobs: cp -a "$HOME/.local/share/HuxerUI" "$HUXERUI_HOME" fi cmake -S tests -B build/tests-ninja -G Ninja \ - -DCMAKE_BUILD_TYPE=Release + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Build tests timeout-minutes: 30 @@ -76,6 +91,9 @@ jobs: HUXERUI_HOME: ${{ github.workspace }}/.huxerui-sdk run: cmake --build build/tests-ninja --parallel 8 + - name: Report C++ cache statistics + run: ccache --show-stats + - name: Run GoogleTest suite timeout-minutes: 15 run: ctest --test-dir build/tests-ninja --output-on-failure -j8 @@ -99,6 +117,10 @@ jobs: - name: Set up Gradle cache uses: gradle/actions/setup-gradle@v4 + with: + # dev is not the default branch, so setup-gradle otherwise reads + # caches without writing the updated dependency/build cache back. + cache-read-only: false - name: Install Android build dependencies run: | @@ -115,12 +137,7 @@ jobs: - name: Generate HuxerUI Android library graph env: HUXERUI_HOME: /home/runner/.local/share/HuxerUI - CMAKE_BUILD_PARALLEL_LEVEL: 8 - # `--source` names a HuxerUI *source checkout*, not this project, so - # passing the repository root made the CLI reject it as an invalid - # checkout. Run from the project root and let it default to the - # working directory. - run: /home/runner/.local/share/HuxerUI/bin/huxerui build android --profile debug + run: bash tools/generate_android_library_graph.sh - name: Make Gradle wrapper executable run: chmod +x platform/android/gradlew @@ -128,7 +145,7 @@ jobs: - name: Lint and build debug APK env: HUXERUI_HOME: /home/runner/.local/share/HuxerUI - run: ./platform/android/gradlew -p platform/android :app:lintDebug :app:assembleDebug --max-workers=8 --console=plain + run: ./platform/android/gradlew -p platform/android :app:lintDebug :app:assembleDebug --build-cache --max-workers=8 --console=plain - name: Upload debug APK uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0786dc7f..284d5c13 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,8 @@ jobs: - name: Set up Gradle cache uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: false # The SDK manager sometimes stalls on one download; bound the step so a # slow mirror fails on its own instead of consuming the job's budget. @@ -61,8 +63,7 @@ jobs: timeout-minutes: 30 env: HUXERUI_HOME: /home/runner/.local/share/HuxerUI - CMAKE_BUILD_PARALLEL_LEVEL: 8 - run: /home/runner/.local/share/HuxerUI/bin/huxerui build android --profile debug + run: bash tools/generate_android_library_graph.sh - name: Validate signing secrets env: @@ -116,7 +117,7 @@ jobs: chmod +x platform/android/gradlew ./platform/android/gradlew -p platform/android \ :app:validateReleaseSigning :app:assembleRelease \ - --max-workers=8 --console=plain + --build-cache --max-workers=8 --console=plain - name: Prepare release artifacts env: diff --git a/tools/generate_android_library_graph.sh b/tools/generate_android_library_graph.sh new file mode 100644 index 00000000..26dfe484 --- /dev/null +++ b/tools/generate_android_library_graph.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +: "${HUXERUI_HOME:?HUXERUI_HOME must point to the installed SDK}" +project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +graph_file="$project_root/.huxerui/generated/libraries.json" + +# The HuxerUI CLI also assembles a Debug APK. Gradle builds the requested +# variant later; this configure-only mode supplies its library graph. +mkdir -p "$(dirname "$graph_file")" +cmake -S "$project_root" \ + -B "$project_root/.huxerui/build/library-graph" \ + -G Ninja \ + -DHUXERUI_LIBRARY_GRAPH_ONLY=ON \ + -DHUXERUI_LIBRARY_GRAPH_OUTPUT="$graph_file" \ + -DHUXERUI_HOME="$HUXERUI_HOME" +test -s "$graph_file"