瀏覽代碼

Better cache key.

Yao Wei Tjong 姚伟忠 5 年之前
父節點
當前提交
cf113394cb
共有 3 個文件被更改,包括 29 次插入9 次删除
  1. 11 0
      .github/workflows/ci_cd.rake
  2. 15 9
      .github/workflows/main.yml
  3. 3 0
      Rakefile

+ 11 - 0
.github/workflows/ci_cd.rake

@@ -57,4 +57,15 @@ task :ci do
   %w[URHO3D_DATABASE_SQLITE URHO3D_EXTRAS].each { |it| ENV[it] = '1' }
 end
 
+desc 'Generate the SHA256 digest based on all the C/C++ source files'
+task :source_checksum do
+  require 'digest'
+  sha256_final = Digest::SHA256.new
+  sha256_iter = Digest::SHA256
+  Dir['Source/**/*.{c,h}*'].each { |it|
+    sha256_final << sha256_iter.file(it).hexdigest
+  }
+  puts "::set-output name=hexdigest::#{sha256_final.hexdigest}"
+end
+
 # vi: set ts=2 sw=2 expandtab:

+ 15 - 9
.github/workflows/main.yml

@@ -25,9 +25,9 @@
 name: CI/CD
 on:
   push:
-    branches: ['*']
+    branches: [ '*' ]
   pull_request:
-    branches: ['*']
+    branches: [ '*' ]
 jobs:
   linux:
     name: 🐧
@@ -48,9 +48,9 @@ jobs:
           - 64bit
           - 32bit
         include:
-          - {platform: android, lib-type: STATIC}
-          - {platform: android, lib-type: SHARED}
-          - {platform: web, lib-type: STATIC}
+          - { platform: android, lib-type: STATIC }
+          - { platform: android, lib-type: SHARED }
+          - { platform: web, lib-type: STATIC }
     env:
       HOST: ${{ github.job }}
       PLATFORM: ${{ matrix.platform }}
@@ -68,6 +68,9 @@ jobs:
       - name: Free up space
         run: sudo rm -rf microsoft mssql-toos cni hostedtoolcache /usr/local/share/boost /usr/share/dotnet /usr/local/lib/android /opt/ghc "$AGENT_TOOLSDIRECTORY"
         if: matrix.platform == 'android'
+      - name: Source checksum
+        id: source_checksum
+        run: rake source_checksum
       - name: Cache
         uses: actions/cache@v2
         with:
@@ -75,8 +78,11 @@ jobs:
             build/cache/.ccache
             build/cache/.gradle/caches
             build/cache/.gradle/wrapper
-          key: ${{ env.DBE_TAG }}-${{ matrix.platform }}-${{ matrix.lib-type }}-${{ matrix.architecture }}-${{ github.sha }}
-          restore-keys: ${{ env.DBE_TAG }}-${{ matrix.platform }}-${{ matrix.lib-type }}-${{ matrix.architecture }}
+          key: |
+            test2-${{ matrix.platform }}-${{ matrix.lib-type }}-${{ matrix.architecture }}-${{ env.DBE_TAG }}-${{ steps.source_checksum.outputs.hexdigest }}
+          restore-keys: |
+            test2-${{ matrix.platform }}-${{ matrix.lib-type }}-${{ matrix.architecture }}-${{ env.DBE_TAG }}
+            test2-${{ matrix.platform }}-${{ matrix.lib-type }}-${{ matrix.architecture }}
       - name: Build
         run: |
           docker volume create $(id -u).urho3d_home_dir >/dev/null
@@ -97,8 +103,8 @@ jobs:
           - STATIC
           - SHARED
         include:
-          - {platform: iOS, lib-type: STATIC}
-          - {platform: tvOS, lib-type: STATIC}
+          - { platform: iOS, lib-type: STATIC }
+          - { platform: tvOS, lib-type: STATIC }
     env:
       HOST: ${{ github.job }}
       PLATFORM: ${{ matrix.platform }}

+ 3 - 0
Rakefile

@@ -65,6 +65,8 @@ task build: [:cmake] do
   system "ccache -z" if ENV['CI'] && ENV['USE_CCACHE']
   if ENV['PLATFORM'] == 'android'
     Rake::Task['gradle'].invoke('build')
+    puts
+    system "ccache -s" if ENV['CI'] && ENV['USE_CCACHE']
     next
   end
   config = /xcode|vs/ =~ ENV['GENERATOR'] ? "--config #{ENV.fetch('CONFIG', 'Release')}" : ''
@@ -91,6 +93,7 @@ task build: [:cmake] do
     concurrent = "-j#{$max_jobs}"
   end
   system %Q{cmake --build "#{build_tree}" #{config} #{target} -- #{concurrent} #{ENV['BUILD_PARAMS']}} or abort
+  puts
   system "ccache -s" if ENV['CI'] && ENV['USE_CCACHE']
 end