6 Commits

Author SHA1 Message Date
Dave Rolsky
07f5468cc3 Add release date for v1.0.0
Some checks failed
Lint / Check that code is lint clean using precious (push) Failing after 1m57s
Self-test / Test action (map[cache-cross-binary:false can_execute:true cross-version:19be834 expect_cross:--expect-cross expect_cross_version:19be834 expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 with cross 19be834 runs-on:ubuntu-22.04 target… (push) Failing after 1m13s
Self-test / Test action (map[cache-cross-binary:false can_execute:true cross-version:v0.2.3 expect_cross:--expect-cross expect_cross_version:0.2.3 expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 with cross v0.2.3 (no cache) runs-on:ubuntu-22.04… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:false can_execute:true expect_cross:--expect-cross expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 (no cache) runs-on:ubuntu-22.04 target:aarch64-unknown-linux-musl]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:false expect_cross:--expect-cross expect_file_re:x86-64.+FreeBSD expect_stripped: platform_name:FreeBSD-x86_64 runs-on:ubuntu-22.04 target:x86_64-unknown-freebsd]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:false expect_cross:--expect-cross expect_file_re:x86-64.+NetBSD expect_stripped: platform_name:NetBSD-x86_64 runs-on:ubuntu-22.04 target:x86_64-unknown-netbsd]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true cross-version:19be834 expect_cross:--expect-cross expect_cross_version:19be834 expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 with cross 19be834 runs-on:ubuntu-22.04 target:… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true cross-version:v0.2.3 expect_cross:--expect-cross expect_cross_version:0.2.3 expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 with cross v0.2.3 runs-on:ubuntu-22.04 target:aarc… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross: expect_file_re:ELF.+x86-64 expect_stripped:--expect-stripped platform_name:Linux-x86_64 runs-on:ubuntu-22.04 target:x86_64-unknown-linux-musl]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:32.+ARM expect_stripped: platform_name:Linux-arm runs-on:ubuntu-22.04 target:arm-unknown-linux-musleabi]) (push) Failing after 5s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:32.+PowerPC expect_stripped: platform_name:Linux-powerpc runs-on:ubuntu-22.04 target:powerpc-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:64.+PowerPC expect_stripped: platform_name:Linux-powerpc64 runs-on:ubuntu-22.04 target:powerpc64-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:64.+PowerPC expect_stripped: platform_name:Linux-powerpc64le runs-on:ubuntu-22.04 target:powerpc64le-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:64.+RISC-V expect_stripped: platform_name:Linux-riscv64 runs-on:ubuntu-22.04 target:riscv64gc-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:64.+S/390 expect_stripped: platform_name:Linux-s390x runs-on:ubuntu-22.04 target:s390x-unknown-linux-gnu]) (push) Failing after 4s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:ELF.+80386 expect_stripped: platform_name:Linux-i586 runs-on:ubuntu-22.04 target:i586-unknown-linux-musl]) (push) Failing after 4s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:ELF.+80386 expect_stripped: platform_name:Linux-i686 runs-on:ubuntu-22.04 target:i686-unknown-linux-musl]) (push) Failing after 5s
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross:--expect-cross expect_file_re:aarch64 expect_stripped: platform_name:Linux-aarch64 runs-on:ubuntu-22.04 target:aarch64-unknown-linux-musl]) (push) Failing after 4s
Self-test / Test validate-inputs (push) Successful in 4s
Self-test / Test action (map[cache-cross-binary:true can_execute:false expect_cross: expect_file_re:Aarch64.+Windows expect_stripped: platform_name:Windows-aarch64 runs-on:windows-latest target:aarch64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can_execute:false expect_cross: expect_file_re:Mach-O.+arm64 expect_stripped:--expect-stripped platform_name:macOS-aarch64 runs-on:macOS-latest target:aarch64-apple-darwin]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross: expect_file_re:80386.+Windows expect_stripped:--expect-stripped platform_name:Windows-i686 runs-on:windows-latest target:i686-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_cross: expect_file_re:Mach-O.+x86_64 expect_stripped:--expect-stripped platform_name:macOS-x86_64 runs-on:macOS-latest target:x86_64-apple-darwin]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can_execute:true expect_file_re:x86-64.+Windows expect_stripped:--expect-stripped platform_name:Windows-x86_64 runs-on:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
2025-01-11 11:57:27 -06:00
Dave Rolsky
1024265def Update Changes.md for caching changes since 1.0.0-beta1 2024-12-24 12:00:59 -06:00
Dave Rolsky
faf2f9fd0a Include the hash of the cross binary in the cache key
This protects against changes to the Docker images that `cross` uses.
2024-12-24 11:39:17 -06:00
Dave Rolsky
a183497a0a Include OS version in cache key when using cargo for builds
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.
2024-12-24 11:22:45 -06:00
Dave Rolsky
718071590b Don't try to install musl-tools if it's already installed 2024-12-22 15:17:51 -06:00
Dave Rolsky
a1777f5838 Add first step to print all inputs 2024-12-22 15:05:18 -06:00
5 changed files with 95 additions and 18 deletions

View File

@@ -1,3 +1,24 @@
## 1.0.0 - 2025-01-11
The addition of caching is a significant behavior change for this action, so the version has been
bumped to v1.0.0 because of this change.
- This action will now configure and use `Swatinem/rust-cache` by default for you. It will include
the `target` parameter as part of the cache key automatically, as well as the OS version when
using `cargo` on Linux. Suggested by @jennydaman (Jennings Zhang). GH #23.
- This action now validates its input and will exit early if they are not valid. GH #35.
- When compiling for `musl` targets, this action will not try to reinstall the `musl-tools` package
if it's already installed.
The following changes were made since the 1.0.0-beta1 release:
- The cache key includes information that causes the cache to not be re-used when the system running
`cargo` or `cross` changes. When using `cargo` on Linux, this is the OS version, like "Ubuntu
22.04". When using `cross`, this is the hash of the `cross` binary itself. This is needed because
the Docker images that `cross` uses can change when the binary is updated. This can include
changing the underlying Docker image base OS, in which case it's quite likely the old cache
contents would be incompatible with the the new image.
## 1.0.0-beta1 - 2024-12-21
The addition of caching is a significant behavior change for this action, so the version has been

View File

@@ -106,6 +106,15 @@ value for crates without a `Cargo.lock` file. The `key` parameter passed to this
include the value of the `target` input. If you specify a `key` parameter in
`rust-cache-parameters`, then the `target` input will be appended to the value you specify.
When running `cargo` on a Linux system, it will also include the output of running
`lsb_release --short --description` in the cache key. This is important for crates that link against
system libraries. If those library versions change across OS versions (e.g. Ubuntu 20.04 to 22.04),
then the cache will be broken for these cases.
When running `cross`, the hash of the `cross` binary will be included in the cache key. This is done
because the Docker images that `cross` uses can change when `cross` is updated. We want to make sure
that we do not re-use the cache across changes when these images change.
Finally, it will run `strip` to strip the binaries it builds if the `strip` parameter is true. This
is only possible for builds that are not done via `cross`. In addition, Windows builds for `aarch64`
cannot be stripped either.

View File

@@ -53,6 +53,10 @@ inputs:
runs:
using: composite
steps:
- name: Show inputs
shell: bash
run: |
echo '${{ toJSON(inputs) }}'
- name: Add this action's path to PATH
shell: bash
run: echo "${{ github.action_path }}" >> $GITHUB_PATH
@@ -107,7 +111,12 @@ runs:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
- name: Install musl-tools on Linux if target includes "musl"
shell: bash
run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools
run: |
if dpkg -l musl-tools | grep -q "^ii\s*musl-tools"; then
exit 0
fi
sudo apt-get update --yes && \
sudo apt-get install --yes musl-tools
if: steps.determine-cross-compile.outputs.needs-cross != 'true' && contains(inputs.target, 'musl')
- name: Set build command
id: set-build-command
@@ -124,9 +133,14 @@ runs:
set -e
set -x
set -o pipefail
OS_VERSION=""
if [ -x /usr/bin/lsb_release ]; then
# This will be something like "Ubuntu 22.04.5 LTS"
OS_VERSION="$( lsb_release --short --description )"
fi
# 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-and-set-rust-cache-parameters.py "${{ inputs.target }}" "${{ steps.set-build-command.outputs.build-command }}" "$OS_VERSION"
env:
RUST_CACHE_PARAMETERS: ${{ inputs.rust-cache-parameters }}
if: inputs.use-rust-cache == 'true'

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python3
import json
import os
import sys
import hashlib
def main():
target = sys.argv[1]
build_command = sys.argv[2]
os_version = sys.argv[3]
parameters = json.loads(os.environ["RUST_CACHE_PARAMETERS"])
if "key" not in parameters:
parameters["key"] = target
else:
parameters["key"] += "-{}".format(target)
if build_command == "cargo":
# If we're running cargo, we need to add the OS version 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.
parameters["key"] += "-{}".format(os_version)
else:
# Otherwise we want to include the `cross` binary's hash. The Docker images that `cross`
# uses can change when the binary is updated. This protects us from using the same cache
# inside containers that have changed.
parameters["key"] += "-cross-binary-hash-{}".format(
get_file_hash(build_command)
)
file = os.environ["GITHUB_OUTPUT"]
with open(file, "w") as f:
for key, value in parameters.items():
f.write(f"{key}={value}")
def get_file_hash(build_command):
with open(build_command, "rb") as f:
file_hash = hashlib.sha256()
while chunk := f.read(65536):
file_hash.update(chunk)
return file_hash.hexdigest()
main()

View File

@@ -1,16 +0,0 @@
#!/usr/bin/env python3
import json
import os
import sys
parameters = json.loads(os.environ["RUST_CACHE_PARAMETERS"])
if "key" not in parameters:
parameters["key"] = sys.argv[1]
else:
parameters["key"] = "{}-{}".format(parameters["key"], sys.argv[1])
file = os.environ["GITHUB_OUTPUT"]
with open(file, "w") as f:
for key, value in parameters.items():
f.write(f"{key}={value}")