diff --git a/.github/actions/xahau-configure-ccache/action.yml b/.github/actions/xahau-configure-ccache/action.yml index 2b0a3d98b..44414b98a 100644 --- a/.github/actions/xahau-configure-ccache/action.yml +++ b/.github/actions/xahau-configure-ccache/action.yml @@ -14,6 +14,18 @@ inputs: description: 'How to check compiler for changes' required: false default: 'content' + is_main_branch: + description: 'Whether the current branch is the main branch' + required: false + default: 'false' + main_cache_dir: + description: 'Path to the main branch cache directory' + required: false + default: '~/.ccache-main' + current_cache_dir: + description: 'Path to the current branch cache directory' + required: false + default: '~/.ccache-current' runs: using: 'composite' @@ -21,11 +33,31 @@ runs: - name: Configure ccache shell: bash run: | + # Create cache directories + mkdir -p ${{ inputs.main_cache_dir }} ${{ inputs.current_cache_dir }} + + # Set compiler check globally + ccache -o compiler_check=${{ inputs.compiler_check }} + + # Use a single config file location mkdir -p ~/.ccache - export CONF_PATH="${CCACHE_CONFIGPATH:-${CCACHE_DIR:-$HOME/.ccache}/ccache.conf}" - mkdir -p $(dirname "$CONF_PATH") + export CONF_PATH="$HOME/.ccache/ccache.conf" + + # Apply common settings echo "max_size = ${{ inputs.max_size }}" > "$CONF_PATH" echo "hash_dir = ${{ inputs.hash_dir }}" >> "$CONF_PATH" echo "compiler_check = ${{ inputs.compiler_check }}" >> "$CONF_PATH" + + if [ "${{ inputs.is_main_branch }}" == "true" ]; then + # Main branch: use main branch cache + ccache --set-config=cache_dir="${{ inputs.main_cache_dir }}" + echo "CCACHE_DIR=${{ inputs.main_cache_dir }}" >> $GITHUB_ENV + else + # Feature branch: use current branch cache with main as secondary + ccache --set-config=cache_dir="${{ inputs.current_cache_dir }}" + ccache --set-config=secondary_storage="file:${{ inputs.main_cache_dir }}" + echo "CCACHE_DIR=${{ inputs.current_cache_dir }}" >> $GITHUB_ENV + fi + ccache -p # Print config for verification ccache -z # Zero statistics before the build \ No newline at end of file diff --git a/.github/actions/xahau-ga-build/action.yml b/.github/actions/xahau-ga-build/action.yml index 417190472..3387f0391 100644 --- a/.github/actions/xahau-ga-build/action.yml +++ b/.github/actions/xahau-ga-build/action.yml @@ -48,12 +48,23 @@ runs: SAFE_BRANCH=$(echo "${{ github.ref_name }}" | tr -c 'a-zA-Z0-9_.-' '-') echo "name=${SAFE_BRANCH}" >> $GITHUB_OUTPUT - - name: Restore ccache directory + - name: Restore ccache directory for default branch if: inputs.ccache_enabled == 'true' id: ccache-restore uses: actions/cache/restore@v4 with: - path: ~/.ccache + path: ~/.ccache-main + key: ${{ runner.os }}-ccache-v${{ inputs.cache_version }}-${{ inputs.compiler-id }}-${{ inputs.configuration }}-${{ inputs.main_branch }} + restore-keys: | + ${{ runner.os }}-ccache-v${{ inputs.cache_version }}-${{ inputs.compiler-id }}-${{ inputs.configuration }}- + ${{ runner.os }}-ccache-v${{ inputs.cache_version }}-${{ inputs.compiler-id }}- + + - name: Restore ccache directory for current branch + if: inputs.ccache_enabled == 'true' && steps.safe-branch.outputs.name != inputs.main_branch + id: ccache-restore-current-branch + uses: actions/cache/restore@v4 + with: + path: ~/.ccache-current key: ${{ runner.os }}-ccache-v${{ inputs.cache_version }}-${{ inputs.compiler-id }}-${{ inputs.configuration }}-${{ steps.safe-branch.outputs.name }} restore-keys: | ${{ runner.os }}-ccache-v${{ inputs.cache_version }}-${{ inputs.compiler-id }}-${{ inputs.configuration }}-${{ inputs.main_branch }} @@ -75,6 +86,7 @@ runs: export CXX="${{ inputs.cxx }}" fi + # Configure ccache launcher args CCACHE_ARGS="" if [ "${{ inputs.ccache_enabled }}" = "true" ]; then @@ -99,9 +111,16 @@ runs: shell: bash run: ccache -s - - name: Save ccache directory - if: inputs.ccache_enabled == 'true' + - name: Save ccache directory for default branch + if: always() && inputs.ccache_enabled == 'true' && steps.safe-branch.outputs.name == inputs.main_branch uses: actions/cache/save@v4 with: - path: ~/.ccache - key: ${{ steps.ccache-restore.outputs.cache-primary-key }} \ No newline at end of file + path: ~/.ccache-main + key: ${{ steps.ccache-restore.outputs.cache-primary-key }} + + - name: Save ccache directory for current branch + if: always() && inputs.ccache_enabled == 'true' && steps.safe-branch.outputs.name != inputs.main_branch + uses: actions/cache/save@v4 + with: + path: ~/.ccache-current + key: ${{ steps.ccache-restore-current-branch.outputs.cache-primary-key }} diff --git a/.github/actions/xahau-ga-dependencies/action.yml b/.github/actions/xahau-ga-dependencies/action.yml index b57a9e69e..d295e20eb 100644 --- a/.github/actions/xahau-ga-dependencies/action.yml +++ b/.github/actions/xahau-ga-dependencies/action.yml @@ -42,6 +42,26 @@ runs: SAFE_BRANCH=$(echo "${{ github.ref_name }}" | tr -c 'a-zA-Z0-9_.-' '-') echo "name=${SAFE_BRANCH}" >> $GITHUB_OUTPUT + - name: Check conanfile changes + if: inputs.cache_enabled == 'true' + id: check-conanfile-changes + shell: bash + run: | + # Check if we're on the main branch + if [ "${{ github.ref_name }}" == "${{ inputs.main_branch }}" ]; then + echo "should-save-conan-cache=true" >> $GITHUB_OUTPUT + else + # Fetch main branch for comparison + git fetch origin ${{ inputs.main_branch }} + + # Check if conanfile.txt or conanfile.py has changed compared to main branch + if git diff --quiet origin/${{ inputs.main_branch }}..HEAD -- '**/conanfile.txt' '**/conanfile.py'; then + echo "should-save-conan-cache=false" >> $GITHUB_OUTPUT + else + echo "should-save-conan-cache=true" >> $GITHUB_OUTPUT + fi + fi + - name: Restore Conan cache if: inputs.cache_enabled == 'true' id: cache-restore-conan @@ -76,7 +96,7 @@ runs: .. - name: Save Conan cache - if: inputs.cache_enabled == 'true' && steps.cache-restore-conan.outputs.cache-hit != 'true' + if: always() && inputs.cache_enabled == 'true' && steps.cache-restore-conan.outputs.cache-hit != 'true' && steps.check-conanfile-changes.outputs.should-save-conan-cache == 'true' uses: actions/cache/save@v4 with: path: | diff --git a/.github/workflows/xahau-ga-macos.yml b/.github/workflows/xahau-ga-macos.yml index 5c802c7e9..efb1a2001 100644 --- a/.github/workflows/xahau-ga-macos.yml +++ b/.github/workflows/xahau-ga-macos.yml @@ -5,6 +5,8 @@ on: branches: ["dev", "candidate", "release"] pull_request: branches: ["dev", "candidate", "release"] + schedule: + - cron: '0 0 * * *' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -74,6 +76,7 @@ jobs: max_size: 2G hash_dir: true compiler_check: content + is_main_branch: ${{ github.ref_name == env.MAIN_BRANCH_NAME }} - name: Check environment run: | @@ -113,4 +116,4 @@ jobs: - name: Test run: | - ${{ env.build_dir }}/rippled --unittest --unittest-jobs $(nproc) \ No newline at end of file + ${{ env.build_dir }}/rippled --unittest --unittest-jobs $(nproc) diff --git a/.github/workflows/xahau-ga-nix.yml b/.github/workflows/xahau-ga-nix.yml index 486518033..eca5a660a 100644 --- a/.github/workflows/xahau-ga-nix.yml +++ b/.github/workflows/xahau-ga-nix.yml @@ -5,6 +5,8 @@ on: branches: ["dev", "candidate", "release"] pull_request: branches: ["dev", "candidate", "release"] + schedule: + - cron: '0 0 * * *' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -48,6 +50,7 @@ jobs: max_size: 2G hash_dir: true compiler_check: content + is_main_branch: ${{ github.ref_name == env.MAIN_BRANCH_NAME }} - name: Configure Conan run: |