[GitHub Actions] Make caching of dependencies depend on image version (#6677)
authorAndres Noetzli <andres.noetzli@gmail.com>
Thu, 3 Jun 2021 22:26:52 +0000 (15:26 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Jun 2021 22:26:52 +0000 (15:26 -0700)
Our Clang builds started to fail to link when the environment changed. This commit changes our CI to only use cached dependencies if the build environment has not changed.

.github/workflows/ci.yml

index b9ec42af3d7d2088ffda47521204dc200d6226e4..95c6c035c7a88cedc515f0ea3c84f03abe792471 100644 (file)
@@ -77,6 +77,11 @@ jobs:
         sudo cmake .
         sudo cmake --build . --target install
         cd -
+        # Make ImageVersion accessible as env.image_version. Environment
+        # variables of the runner are not automatically imported:
+        #
+        # https://github.com/actions/runner/blob/master/docs/adrs/0278-env-context.md#dont-populate-the-env-context-with-environment-variables-from-runner-machine
+        echo "image_version=$ImageVersion" >> $GITHUB_ENV
         echo "/usr/lib/ccache" >> $GITHUB_PATH
 
     # Note: macOS comes with a libedit; it does not need to brew-installed
@@ -93,6 +98,11 @@ jobs:
         python3 -m pip install toml
         python3 -m pip install setuptools
         python3 -m pip install pexpect
+        # Make ImageVersion accessible as env.image_version. Environment
+        # variables of the runner are not automatically imported:
+        #
+        # https://github.com/actions/runner/blob/master/docs/adrs/0278-env-context.md#dont-populate-the-env-context-with-environment-variables-from-runner-machine
+        echo "image_version=$ImageVersion" >> $GITHUB_ENV
         echo "/usr/local/opt/ccache/libexec" >> $GITHUB_PATH
 
     - name: Install Python Dependencies
@@ -170,7 +180,9 @@ jobs:
       uses: actions/cache@v2
       with:
         path: build/deps
-        key: cvc5-deps-${{ runner.os }}-${{ matrix.cache-key }}-${{ hashFiles('cmake/Find**', 'cmake/deps-helper.cmake') }}-${{ hashFiles('.github/workflows/ci.yml') }}
+        # The cache depends on the image version to make sure that we do not
+        # restore the dependencies if the build environment has changed.
+        key: cvc5-deps-${{ runner.os }}-${{ env.image_version }}-${{ matrix.cache-key }}-${{ hashFiles('cmake/Find**', 'cmake/deps-helper.cmake') }}-${{ hashFiles('.github/workflows/ci.yml') }}
 
     - name: Configure
       run: |