From e6dfeafa18550949c46928d0ba7a0c4ec1786178 Mon Sep 17 00:00:00 2001 From: gary-wzl77 Date: Wed, 27 Dec 2023 20:15:57 +0800 Subject: [PATCH] feat(scripts): support build artifact without compression The github action `upload-artifact` always creates a zip tarball when collecting it and this caused double-zip a zip in our case. See the following issue for details: https://github.com/actions/upload-artifact/issues/39 This change adds a cli parameter to build artifact without zip compression. And let the action to create a tarball for us. Test: build --- examples/scripts/build-with-docker.sh | 2 +- examples/scripts/clean-build.sh | 2 - scripts/build.sh | 67 +++++++++++++++++++-------- scripts/streaming-sdk-files.allowlist | 1 + scripts/validate.sh | 23 +++++++-- 5 files changed, 68 insertions(+), 27 deletions(-) diff --git a/examples/scripts/build-with-docker.sh b/examples/scripts/build-with-docker.sh index acf47e0..91d28ee 100755 --- a/examples/scripts/build-with-docker.sh +++ b/examples/scripts/build-with-docker.sh @@ -170,7 +170,7 @@ EOF mkdir -p "$workdir"/results/ builddir=$(mktemp -p "$PWD" -d .build.XXXXXX) - cp "$sdk" "$builddir"/sdk.zip + cp -ra "$sdk" "$builddir"/sdk cp -ra * "$builddir" docker run --rm \ diff --git a/examples/scripts/clean-build.sh b/examples/scripts/clean-build.sh index 3ba89a4..c3dc510 100755 --- a/examples/scripts/clean-build.sh +++ b/examples/scripts/clean-build.sh @@ -29,8 +29,6 @@ sudo apt-get update -qq sudo apt-get clean cd /work/src -(mkdir -p /work/src/sdk; unzip /work/src/sdk.zip; mv /work/src/anbox-streaming-sdk_*/* /work/src/sdk) - # NOTE: Only build Android example APK on x86_64 host. if [ $(uname -m) = x86_64 ]; then # For Anbox Streaming SDK library(AAR) diff --git a/scripts/build.sh b/scripts/build.sh index 658427b..cfbb735 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh -xe +#!/bin/bash -xe # # Copyright 2019 Canonical Ltd. # @@ -15,6 +15,7 @@ # limitations under the License. PROXY= +CREATE_TARBALL=false VERSION=$(scripts/gen-version.sh) for p in "$@" @@ -26,11 +27,19 @@ do --version=*) VERSION=${p#*=} ;; + --create-tarball) + CREATE_TARBALL=true + ;; *) echo "unrecognized option $p" esac done +mkdir_cp() { + local dest="${!#}" + mkdir -p "$dest" && cp -av "${@:1:${#}-1}" "$dest" +} + builddir=$(mktemp -d -p $PWD .buildXXXXXX) topdir="$PWD" trap "rm -rf ${builddir}" INT EXIT @@ -38,10 +47,13 @@ trap "rm -rf ${builddir}" INT EXIT sdkname=anbox-streaming-sdk_${VERSION} sdkdir="$builddir"/"$sdkname" +mkdir_cp LICENSE "$sdkdir" + for f in examples js android; do mkdir -p "$sdkdir"/"$f" done +# Modify the JS SDK version sed -i "s/@VERSION@/${VERSION}/" js/anbox-stream-sdk.js # Only copy the JS SDK and markdown file to the js folder @@ -60,36 +72,51 @@ for d in `find $sdkdir/examples -name js -type d`; do done for d in `find $sdkdir/examples -name assets -type d`; do - mkdir -p $d/js && cp js/anbox-stream-sdk.js $d/js + mkdir_cp js/anbox-stream-sdk.js "$d"/js done -(cd "$builddir" ; zip -r "$topdir"/"$sdkname".zip *) +if [ "$CREATE_TARBALL" = true ]; then + (cd "$builddir" ; zip -r "$topdir"/"$sdkname".zip *) +fi # Do a test build of our examples with the generated SDK package ( # Copy the anbox-stream-sdk.js file to examples folders for d in `find $topdir/examples -name assets -type d`; do - mkdir -p $d/js && cp js/anbox-stream-sdk.js $d/js + mkdir_cp js/anbox-stream-sdk.js "$d"/js done # Create a symbol link for anbox_streaming_sdk to example/android folder so that we # can create the sdk library alongside with Android example when building the APKs. - cp -av "$topdir"/android/anbox_streaming_sdk "$topdir"/examples/android/anbox_streaming_sdk; \ - cd examples; \ - scripts/build-with-docker.sh --proxy="${PROXY}" \ - --version="${VERSION}" \ - --anbox-stream-sdk="$topdir"/"$sdkname".zip; \ + cp -av "$topdir"/android/anbox_streaming_sdk "$topdir"/examples/android/anbox_streaming_sdk; + cd examples; + scripts/build-with-docker.sh --proxy="${PROXY}" \ + --version="${VERSION}" \ + --anbox-stream-sdk="$builddir" + # To repack zip taball which includes APKs file later - mkdir -p "$sdkname"/examples/android/apks; \ - cp results/*.apk "$sdkname"/examples/android/apks; mv results/*.apk "$topdir"; \ + mkdir_cp results/*.apk "$sdkname"/examples/android/apks; + mv results/*.apk "$topdir"; # To repack zip taball which includes JAR/AAR files built during the docker runtime - mkdir -p "$sdkname"/android/libs && cp results/*.aar "$sdkname"/android/libs; \ - mkdir -p "$sdkname"/examples/android/enhanced_webview_streaming/app/libs && cp results/*.aar \ - "$sdkname"/examples/android/enhanced_webview_streaming/app/libs/; \ - zip -r "$topdir"/"$sdkname".zip "$sdkname"/examples/android/apks/*.apk "$sdkname"/android/libs/*.aar \ - "$sdkname"/examples/android/enhanced_webview_streaming/app/libs/*.aar - - # Validate the streaming sdk to ensure we don't accidentally leak unwanted files. - "$topdir"/scripts/validate.sh --sdk-zip-tarball="$topdir"/"$sdkname".zip \ - --allowlist="$topdir"/scripts/streaming-sdk-files.allowlist + mkdir_cp results/*.aar "$sdkname"/android/libs + mkdir_cp results/*.aar "$sdkname"/examples/android/enhanced_webview_streaming/app/libs + + if [ "$CREATE_TARBALL" = true ]; then + zip -r "$topdir"/"$sdkname".zip "$sdkname"/examples/android/apks/*.apk "$sdkname"/android/libs/*.aar \ + "$sdkname"/examples/android/enhanced_webview_streaming/app/libs/*.aar + + # Validate the streaming sdk to ensure we don't accidentally leak unwanted files. + "$topdir"/scripts/validate.sh --sdk-zip-tarball="$topdir"/"$sdkname".zip \ + --allowlist="$topdir"/scripts/streaming-sdk-files.allowlist + else + mkdir_cp "$sdkname"/examples/android/apks/*.apk "$sdkdir"/examples/android/apks/ + mkdir_cp "$sdkname"/android/libs/*.aar "$sdkdir"/android/libs/ + mkdir_cp "$sdkname"/examples/android/enhanced_webview_streaming/app/libs/*.aar \ + "$sdkdir"/examples/android/enhanced_webview_streaming/app/libs/ + + "$topdir"/scripts/validate.sh --sdk-path="$sdkdir" \ + --allowlist="$topdir"/scripts/streaming-sdk-files.allowlist + + mv "$builddir" "$topdir"/results + fi ) diff --git a/scripts/streaming-sdk-files.allowlist b/scripts/streaming-sdk-files.allowlist index 55cca43..0fd85d0 100644 --- a/scripts/streaming-sdk-files.allowlist +++ b/scripts/streaming-sdk-files.allowlist @@ -1,3 +1,4 @@ +LICENSE android/anbox_streaming_sdk/consumer-rules.pro android/anbox_streaming_sdk/.gitignore android/anbox_streaming_sdk/src/ diff --git a/scripts/validate.sh b/scripts/validate.sh index 424d2d6..22b9f35 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -16,6 +16,7 @@ ALLOWLIST="./sdk-files.allowlist" SDK_ZIP_TARBALL="./anbox-streaming-sdk.zip" +SDK_PATH= show_help() { cat <<'EOF' @@ -26,6 +27,7 @@ Validates Anbox Streaming SDK by checking that all included source files are in optional arguments: --allowlist= Path to the file holding the list of allowed files into the sdk (default: ./sdk-files.allowlist) --sdk-zip-tarball= Path to the streaming sdk zip tarball (default: ./anbox-streaming-sdk.zip) + --sdk-path= Path to the folder path that include the Anbox Streaming SDK EOF } @@ -39,6 +41,10 @@ while [ -n "$1" ]; do ALLOWLIST=${1#*=} shift ;; + --sdk-path*) + SDK_PATH=${1#*=} + shift + ;; --sdk-zip-tarball=*) SDK_ZIP_TARBALL=${1#*=} shift @@ -50,8 +56,13 @@ while [ -n "$1" ]; do esac done -if [ ! -f "$SDK_ZIP_TARBALL" ]; then - echo "Anbox Streaming SDK is missing" +if [ ! -f "$SDK_ZIP_TARBALL" ] ; then + if [ ! -d "$SDK_PATH" ] ; then + echo "Anbox Streaming SDK is missing" + exit 1 + fi +elif [ -d "$SDK_PATH" ] ; then + echo "parameter '--sdk-path' and '--sdk-zip-tarbll' are mutually exclusive" exit 1 fi @@ -89,11 +100,15 @@ search_for_remaining_files() { ( tmpfolder=$(mktemp -d) cleanup() { - rm -rf "$tmpfolder" + rm -rf "$tmpfolder" } trap cleanup EXIT INT - unzip -qq "$SDK_ZIP_TARBALL" -d "$tmpfolder" + if [ -d "$SDK_PATH" ]; then + cp -ra "$SDK_PATH" "$tmpfolder" + else + unzip -qq "$SDK_ZIP_TARBALL" -d "$tmpfolder" + fi cd "$tmpfolder"/anbox-streaming-sdk_* sdk_version="$(pwd | cut -d_ -f2)"