From 6d979c2aec5e0e9f15589eda2ed17838a68db303 Mon Sep 17 00:00:00 2001 From: Michal Toman Date: Fri, 20 Nov 2020 16:22:57 +0100 Subject: [PATCH] jenkins_build.sh: refactor the code for balena.img handling No functional change, just refactor a section of the script to make it more readable. Signed-off-by: Michal Toman --- automation/jenkins_build.sh | 65 ++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/automation/jenkins_build.sh b/automation/jenkins_build.sh index 5ebbc16d4..eb6fdb3b3 100755 --- a/automation/jenkins_build.sh +++ b/automation/jenkins_build.sh @@ -84,22 +84,9 @@ deploy_build () { cp -v "$YOCTO_BUILD_DEPLOY/kernel_modules_headers.tar.gz" "$_deploy_dir" || true cp -v "$YOCTO_BUILD_DEPLOY/kernel_source.tar.gz" "$_deploy_dir" || true cp -v "$MACHINE.svg" "$_deploy_dir/logo.svg" - if [ "${_compressed}" != 'true' ]; then - # uncompressed, just copy and we're done - cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena.img" - if [ -n "$_deploy_flasher_artifact" ]; then - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img" - cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img" - elif [ "$_image" = "resin-image-flasher" ]; then - # backwards compatibility - deployFlasherArtifact is not set and deployArtifact contains flasher - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-flasher.img" - else - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img" - fi - return - fi - if [ "${_archive}" = 'true' ]; then + if [ "${_archive}" = 'true' ] && [ "${_compressed}" = 'true' ]; then + # Archive and we are done cp -rv "$YOCTO_BUILD_DEPLOY"/"$_deploy_artifact"/* "$_deploy_dir"/image/ (cd "$_deploy_dir/image/" && zip -r "../$_deploy_artifact.zip" .) if [ -n "$_deploy_flasher_artifact" ]; then @@ -109,28 +96,40 @@ deploy_build () { if [ "$_remove_compressed_file" = "true" ]; then rm -rf $_deploy_dir/image fi + return + fi + + cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena-raw.img" + if [ -n "$_deploy_flasher_artifact" ]; then + cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img" + elif [ "$_image" = "resin-image-flasher" ]; then + # deployFlasherArtifact is not set and deployArtifact contains flasher + mv "$_deploy_dir/image/balena-raw.img" "$_deploy_dir/image/balena-flasher.img" + fi + + # Create the unflagged balena.img for backwards compatibility + if [ "$_image" = "resin-image-flasher" ]; then + cp -v "$_deploy_dir/image/balena-flasher.img" "$_deploy_dir/image/balena.img" else - cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_artifact") "$_deploy_dir/image/balena.img" - (cd "$_deploy_dir/image" && zip balena.img.zip balena.img) - if [ -n "$_deploy_flasher_artifact" ]; then - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img" - (cd "$_deploy_dir/image" && zip balena-raw.img.zip balena-raw.img) - cp -v $(readlink --canonicalize "$YOCTO_BUILD_DEPLOY/$_deploy_flasher_artifact") "$_deploy_dir/image/balena-flasher.img" - (cd "$_deploy_dir/image" && zip balena-flasher.img.zip balena-flasher.img) - elif [ "$_image" = "resin-image-flasher" ]; then - # backwards compatibility - deployFlasherArtifact is not set and deployArtifact contains flasher - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-flasher.img" - (cd "$_deploy_dir/image" && zip balena-flasher.img.zip balena-flasher.img) - else - cp -v "$_deploy_dir/image/balena.img" "$_deploy_dir/image/balena-raw.img" - (cd "$_deploy_dir/image" && zip balena-raw.img.zip balena-raw.img) + cp -v "$_deploy_dir/image/balena-raw.img" "$_deploy_dir/image/balena.img" + fi + + if [ "${_compressed}" != 'true' ]; then + # uncompressed, just copy and we're done + return + fi + + for filename in balena.img balena-raw.img balena-flasher.img; do + if [ ! -f "$_deploy_dir/image/$filename" ]; then + continue fi + + (cd "$_deploy_dir/image" && zip "$filename.zip" "$filename") + if [ "$_remove_compressed_file" = "true" ]; then - rm -rf $_deploy_dir/image/balena.img - rm -rf $_deploy_dir/image/balena-raw.img - rm -rf $_deploy_dir/image/balena-flasher.img + rm -rf "$_deploy_dir/image/$filename" fi - fi + done if [ -d "${WORKSPACE}/layers/meta-balena/tests" ] then