Skip to content

Commit

Permalink
Include runner name in cache key when using cargo for builds
Browse files Browse the repository at this point in the history
If we're running cargo, we need to add the runner name to the cache. Otherwise things that link
against system packages, like openssl, can break when we use the same cache across different
versions of the runner OS. For example, when going from Ubuntu 20.04 to 22.04, we move from OpenSSL
1.1.x to 3.x.
  • Loading branch information
autarch committed Dec 24, 2024
1 parent 7180715 commit f192f07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ runs:
set -o pipefail
# This will get the inputs JSON from the `RUST_CACHE_PARAMETERS` env var. This avoids
# any string interpolation issues, since the inputs will contain quotes.
parse-rust-cache-parameters.py "${{ inputs.target }}"
parse-rust-cache-parameters.py "${{ inputs.target }}" "${{ steps.set-build-command.outputs.build-command }}" "${{ runner.name }}"
env:
RUST_CACHE_PARAMETERS: ${{ inputs.rust-cache-parameters }}
if: inputs.use-rust-cache == 'true'
Expand Down
15 changes: 13 additions & 2 deletions parse-rust-cache-parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
import os
import sys

target = sys.argv[1]
build_command = sys.argv[2]
runner_name = sys.argv[3]

parameters = json.loads(os.environ["RUST_CACHE_PARAMETERS"])
if "key" not in parameters:
parameters["key"] = sys.argv[1]
parameters["key"] = target
else:
parameters["key"] = "{}-{}".format(parameters["key"], sys.argv[1])
parameters["key"] = "{}-{}".format(parameters["key"], target)

# If we're running cargo, we need to add the runner name to the cache. Otherwise things that link
# against system packages, like openssl, can break when we use the same cache across different
# versions of the runner OS. For example, when going from Ubuntu 20.04 to 22.04, we move from
# OpenSSL 1.1.x to 3.x.
if build_command == "cargo":
parameters["key"] = "{}-{}".format(parameters["key"], runner_name)

file = os.environ["GITHUB_OUTPUT"]
with open(file, "w") as f:
Expand Down

0 comments on commit f192f07

Please sign in to comment.