diff --git a/.github/actions/cache-key/action.yml b/.github/actions/cache-key/action.yml new file mode 100644 index 00000000..ca839451 --- /dev/null +++ b/.github/actions/cache-key/action.yml @@ -0,0 +1,36 @@ +name: Cache key +description: Generate cache key for ccache + +inputs: + conan_profile: + description: Conan profile name + required: true + build_type: + description: Current build type (e.g. Release, Debug) + required: true + default: Release + code_coverage: + description: Whether code coverage is on + required: true + default: "false" + +outputs: + key: + description: Generated cache key for ccache + value: ${{ steps.key_without_commit.outputs.key }}-${{ steps.git_common_ancestor.outputs.commit }} + restore_keys: + description: Cache restore keys for fallback + value: ${{ steps.key_without_commit.outputs.key }} + +runs: + using: composite + steps: + - name: Find common commit + id: git_common_ancestor + uses: ./.github/actions/git-common-ancestor + + - name: Set cache key without commit + id: key_without_commit + shell: bash + run: | + echo "key=clio-ccache-${{ runner.os }}-${{ inputs.build_type }}${{ inputs.code_coverage == 'true' && '-code_coverage' || '' }}-${{ inputs.conan_profile }}-develop" >> "${GITHUB_OUTPUT}" diff --git a/.github/actions/restore-cache/action.yml b/.github/actions/restore-cache/action.yml deleted file mode 100644 index 99774047..00000000 --- a/.github/actions/restore-cache/action.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Restore cache -description: Find and restores ccache cache - -inputs: - conan_profile: - description: Conan profile name - required: true - ccache_dir: - description: Path to .ccache directory - required: true - build_type: - description: Current build type (e.g. Release, Debug) - required: true - default: Release - code_coverage: - description: Whether code coverage is on - required: true - default: "false" - -outputs: - ccache_cache_hit: - description: True if ccache cache has been downloaded - value: ${{ steps.ccache_cache.outputs.cache-hit }} - -runs: - using: composite - steps: - - name: Find common commit - id: git_common_ancestor - uses: ./.github/actions/git-common-ancestor - - - name: Restore ccache cache - uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 - id: ccache_cache - if: ${{ env.CCACHE_DISABLE != '1' }} - with: - path: ${{ inputs.ccache_dir }} - key: clio-ccache-${{ runner.os }}-${{ inputs.build_type }}${{ inputs.code_coverage == 'true' && '-code_coverage' || '' }}-${{ inputs.conan_profile }}-develop-${{ steps.git_common_ancestor.outputs.commit }} diff --git a/.github/actions/save-cache/action.yml b/.github/actions/save-cache/action.yml deleted file mode 100644 index fee1e8ae..00000000 --- a/.github/actions/save-cache/action.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Save cache -description: Save ccache cache for develop branch - -inputs: - conan_profile: - description: Conan profile name - required: true - ccache_dir: - description: Path to .ccache directory - required: true - build_type: - description: Current build type (e.g. Release, Debug) - required: true - default: Release - code_coverage: - description: Whether code coverage is on - required: true - default: "false" - - ccache_cache_hit: - description: Whether ccache cache has been downloaded - required: true - ccache_cache_miss_rate: - description: How many ccache cache misses happened - -runs: - using: composite - steps: - - name: Find common commit - id: git_common_ancestor - uses: ./.github/actions/git-common-ancestor - - - name: Save ccache cache - if: ${{ inputs.ccache_cache_hit != 'true' || inputs.ccache_cache_miss_rate == '100.0' }} - uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 - with: - path: ${{ inputs.ccache_dir }} - key: clio-ccache-${{ runner.os }}-${{ inputs.build_type }}${{ inputs.code_coverage == 'true' && '-code_coverage' || '' }}-${{ inputs.conan_profile }}-develop-${{ steps.git_common_ancestor.outputs.commit }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b0f6f3bb..a7fe15d4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -105,20 +105,7 @@ updates: target-branch: develop - package-ecosystem: github-actions - directory: .github/actions/restore-cache/ - schedule: - interval: weekly - day: monday - time: "04:00" - timezone: Etc/GMT - reviewers: - - XRPLF/clio-dev-team - commit-message: - prefix: "ci: [DEPENDABOT] " - target-branch: develop - - - package-ecosystem: github-actions - directory: .github/actions/save-cache/ + directory: .github/actions/cache-key/ schedule: interval: weekly day: monday diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef78c922..f18f3bfa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,7 +83,7 @@ jobs: conan_profile: gcc build_type: Debug download_ccache: true - upload_ccache: false + upload_ccache: true code_coverage: true static: true upload_clio_server: false diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index a94e4897..aa4f806c 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -48,13 +48,6 @@ jobs: with: disable_ccache: true - - name: Restore cache - uses: ./.github/actions/restore-cache - id: restore_cache - with: - conan_profile: ${{ env.CONAN_PROFILE }} - ccache_dir: ${{ env.CCACHE_DIR }} - - name: Run conan uses: ./.github/actions/conan with: diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 38452464..88af4a4a 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -107,16 +107,24 @@ jobs: if: ${{ runner.os == 'macOS' }} run: ./.github/scripts/conan/init.sh - - name: Restore cache - if: ${{ inputs.download_ccache }} - uses: ./.github/actions/restore-cache - id: restore_cache + - name: Generate cache key + uses: ./.github/actions/cache-key + id: cache_key with: conan_profile: ${{ inputs.conan_profile }} - ccache_dir: ${{ env.CCACHE_DIR }} build_type: ${{ inputs.build_type }} code_coverage: ${{ inputs.code_coverage }} + - name: Restore ccache cache + if: ${{ inputs.download_ccache }} + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + id: restore_cache + with: + path: ${{ env.CCACHE_DIR }} + key: ${{ steps.cache_key.outputs.key }} + restore-keys: | + ${{ steps.cache_key.outputs.restore_keys }} + - name: Run conan uses: ./.github/actions/conan with: @@ -161,6 +169,13 @@ jobs: echo "miss_rate=${miss_rate}" >> $GITHUB_OUTPUT cat /tmp/ccache.stats + - name: Save ccache cache + if: ${{ inputs.upload_ccache && github.ref == 'refs/heads/develop' && (steps.restore_cache.outputs.cache-hit != 'true' || steps.ccache_stats.outputs.miss_rate == '100.0') }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ env.CCACHE_DIR }} + key: ${{ steps.cache_key.outputs.key }} + - name: Strip unit_tests if: ${{ !endsWith(inputs.conan_profile, 'san') && !inputs.code_coverage && !inputs.analyze_build_time }} run: strip build/clio_tests @@ -197,18 +212,6 @@ jobs: name: clio_deb_package_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }} path: build/*.deb - - name: Save cache - if: ${{ inputs.upload_ccache && github.ref == 'refs/heads/develop' }} - uses: ./.github/actions/save-cache - with: - conan_profile: ${{ inputs.conan_profile }} - ccache_dir: ${{ env.CCACHE_DIR }} - build_type: ${{ inputs.build_type }} - code_coverage: ${{ inputs.code_coverage }} - - ccache_cache_hit: ${{ steps.restore_cache.outputs.ccache_cache_hit }} - ccache_cache_miss_rate: ${{ steps.ccache_stats.outputs.miss_rate }} - # This is run as part of the build job, because it requires the following: # - source code # - conan packages