From 547951f9f3b9d9a33e3149b6f6676c1884b3107b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Arg=C3=A9rus?= Date: Fri, 10 May 2024 13:10:51 +0200 Subject: [PATCH] Fix caching --- .../workflows/kuksa_databroker-cli_build.yml | 2 +- .github/workflows/kuksa_databroker_build.yml | 2 +- scripts/build-databroker-cli.sh | 35 +++++++++--------- scripts/build-databroker.sh | 36 +++++++++---------- ...nsecuration.yaml => license_curation.yaml} | 0 5 files changed, 37 insertions(+), 38 deletions(-) rename scripts/{licensecuration.yaml => license_curation.yaml} (100%) diff --git a/.github/workflows/kuksa_databroker-cli_build.yml b/.github/workflows/kuksa_databroker-cli_build.yml index ed2f73ed..f3e29449 100644 --- a/.github/workflows/kuksa_databroker-cli_build.yml +++ b/.github/workflows/kuksa_databroker-cli_build.yml @@ -89,7 +89,7 @@ jobs: ~/.cargo/.crates.toml ~/.cargo/.crates2.json ~/.cache/pip/ - target-*/ + target/ key: databroker-cli-release-${{ matrix.platform.name }}-${{ hashFiles('**/Cargo.lock') }} - name: Install build prerequisites working-directory: ${{github.workspace}}/ diff --git a/.github/workflows/kuksa_databroker_build.yml b/.github/workflows/kuksa_databroker_build.yml index 9d0dd872..4e0ea41a 100644 --- a/.github/workflows/kuksa_databroker_build.yml +++ b/.github/workflows/kuksa_databroker_build.yml @@ -80,7 +80,7 @@ jobs: ~/.cargo/.crates.toml ~/.cargo/.crates2.json ~/.cache/pip/ - target-*/ + target/ key: databroker-coverage-${{ hashFiles('**/Cargo.lock') }} - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov diff --git a/scripts/build-databroker-cli.sh b/scripts/build-databroker-cli.sh index e9e09c97..dec158f8 100755 --- a/scripts/build-databroker-cli.sh +++ b/scripts/build-databroker-cli.sh @@ -60,9 +60,6 @@ echo >${TARGET_MAP}/amd64 x86_64-unknown-linux-musl # yet supported echo >${TARGET_MAP}/riscv64 riscv64gc-unknown-linux-gnu -CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse - - # Check if a certain feature set was requested if [ -z "$KUKSA_DATABROKERCLI_FEATURES" ]; then # If not set, assign a default value @@ -71,7 +68,7 @@ fi SBOM=0 # Check whether to build SBOM -if [ ! -z "$KUKSA_DATABROKERCLI_SBOM" ]; then +if [ -n "$KUKSA_DATABROKERCLI_SBOM" ]; then # If set, check whether it is "y" if [[ $KUKSA_DATABROKERCLI_SBOM =~ ^[Yy](es)?$ || $KUKSA_DATABROKER_SBOM =~ ^[Tt](rue)?$ ]]; then SBOM=1 @@ -91,8 +88,8 @@ echo "Building with features: $KUKSA_DATABROKERCLI_FEATURES" # Rust target triplett (i.e. x86_64-unknown-linux-musl) and the corresponding docker # architecture (i.e. amd64) as input function build_target() { - target_rust=$1 - target_docker=$2 + target=$1 + platform=$2 # Need to set different target dir for different platforms, becasue cargo mixes things up # when recycling the default target dir. When you do not do this, and e.g. first build amd64 @@ -106,20 +103,22 @@ function build_target() { # /target/release/build/libc-2dd22ab6b5fb9fd2/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by /target/release/build/libc-2dd22ab6b5fb9fd2/build-script-build) # # this is solved by using different target-dirs for each platform - echo "Building databroker-cli for target $target_rust" - cross build --target $target_rust --target-dir ./target-$target_docker --features $KUKSA_DATABROKERCLI_FEATURES --bin databroker-cli --release + echo "Building databroker-cli for target $target" + target_dir="./target/cross-$target" + cross build --target "$target" --target-dir "$target_dir" --features "$KUKSA_DATABROKERCLI_FEATURES" --bin databroker-cli --release - echo "Prepare $target_docker dist folder" - rm -rf ./dist/$target_docker || true - mkdir ./dist/$target_docker - cp ./target-$target_docker/$target_rust/release/databroker-cli ./dist/$target_docker + echo "Prepare $platform dist folder" + dist_dir="./dist/$platform" + rm -rf "$dist_dir" || true + mkdir "$dist_dir" + cp "$target_dir/$target"/release/databroker-cli "$dist_dir" if [[ $SBOM -eq 1 ]]; then - echo "Create $target_rust SBOM" - cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ./Cargo.toml - cp ./databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/sbom.json - rm -rf ./dist/$target_docker/thirdparty-licenses || true - collectlicensefiles ./databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./scripts/licensecuration.yaml + echo "Create $target SBOM" + cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target "$target" --manifest-path ./Cargo.toml + cp ./databroker-cli/databroker-cli_bin.cdx.json "$dist_dir/sbom.json" + rm -rf "$dist_dir"/thirdparty-licenses || true + collectlicensefiles ./databroker-cli/databroker-cli_bin.cdx.json "$dist_dir"/thirdparty-licenses --curation ./scripts/license_curation.yaml fi } @@ -142,7 +141,7 @@ mkdir -p ./dist for platform in "$@" do target=$(cat ${TARGET_MAP}/$platform) - build_target $target $platform + build_target "$target" "$platform" done rm -rf ${TARGET_MAP} diff --git a/scripts/build-databroker.sh b/scripts/build-databroker.sh index 7567d913..4fe7262c 100755 --- a/scripts/build-databroker.sh +++ b/scripts/build-databroker.sh @@ -64,8 +64,6 @@ echo >${TARGET_MAP}/amd64 x86_64-unknown-linux-musl # yet supported echo >${TARGET_MAP}/riscv64 riscv64gc-unknown-linux-gnu -CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse - # Check if a certain feature set was requested if [ -z "$KUKSA_DATABROKER_FEATURES" ]; then # If not set, assign a default value @@ -74,7 +72,7 @@ fi SBOM=0 # Check whether to build SBOM -if [ ! -z "$KUKSA_DATABROKER_SBOM" ]; then +if [ -n "$KUKSA_DATABROKER_SBOM" ]; then # If set, check whether it is "y" if [[ $KUKSA_DATABROKER_SBOM =~ ^[Yy](es)?$ || $KUKSA_DATABROKER_SBOM =~ ^[Tt](rue)?$ ]]; then SBOM=1 @@ -96,8 +94,8 @@ echo "Building with features: $KUKSA_DATABROKER_FEATURES" # Rust target triplett (i.e. x86_64-unknown-linux-musl) and the corresponding docker # architecture (i.e. amd64) as input function build_target() { - target_rust=$1 - target_docker=$2 + target=$1 + platform=$2 # Need to set different target dir for different platforms, becasue cargo mixes things up # when recycling the default target dir. When you do not do this, and e.g. first build amd64 @@ -111,20 +109,22 @@ function build_target() { # /target/release/build/libc-2dd22ab6b5fb9fd2/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by /target/release/build/libc-2dd22ab6b5fb9fd2/build-script-build) # # this is solved by using different target-dirs for each platform - echo "Building databroker for target $target_rust" - cross build --target $target_rust --target-dir ./target-$target_docker --features $KUKSA_DATABROKER_FEATURES --bin databroker --release + echo "Building databroker for target $target" + target_dir="./target-$platform" + cross build --target "$target" --target-dir "$target_dir" --features "$KUKSA_DATABROKER_FEATURES" --bin databroker --release - echo "Prepare $target_docker dist folder" - rm -rf ./dist/$target_docker || true - mkdir ./dist/$target_docker - cp ./target-$target_docker/$target_rust/release/databroker ./dist/$target_docker + echo "Prepare $platform dist folder" + dist_dir="./dist/$platform" + rm -rf "$dist_dir" || true + mkdir "$dist_dir" + cp "$target_dir/$target"/release/databroker "$dist_dir" if [[ $SBOM -eq 1 ]]; then - echo "Create $target_rust SBOM" - cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ./Cargo.toml - cp ./databroker/databroker_bin.cdx.json ./dist/$target_docker/sbom.json - rm -rf ./dist/$target_docker/thirdparty-licenses || true - collectlicensefiles ./databroker/databroker_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./scripts/licensecuration.yaml + echo "Create $target SBOM" + cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target "$target" --manifest-path ./Cargo.toml + cp ./databroker/databroker_bin.cdx.json "$dist_dir"/sbom.json + rm -rf "$dist_dir"/thirdparty-licenses || true + collectlicensefiles ./databroker/databroker_bin.cdx.json "$dist_dir"/thirdparty-licenses --curation ./scripts/license_curation.yaml fi } @@ -147,8 +147,8 @@ mkdir -p ./dist for platform in "$@" do - target=$(cat ${TARGET_MAP}/$platform) - build_target $target $platform + target=$(cat "${TARGET_MAP}/$platform") + build_target "$target" "$platform" done rm -rf ${TARGET_MAP} diff --git a/scripts/licensecuration.yaml b/scripts/license_curation.yaml similarity index 100% rename from scripts/licensecuration.yaml rename to scripts/license_curation.yaml