Skip to content

Commit

Permalink
feat(scripts): support build artifact without compression
Browse files Browse the repository at this point in the history
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:
   actions/upload-artifact#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
  • Loading branch information
adglkh committed Feb 19, 2024
1 parent d724392 commit 8f89b41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/scripts/build-with-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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 \
Expand Down
2 changes: 0 additions & 2 deletions examples/scripts/clean-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,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)
Expand Down
37 changes: 30 additions & 7 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#

PROXY=
CREATE_TARBALL=false
VERSION=$(scripts/gen-version.sh)

for p in "$@"
Expand All @@ -16,11 +17,18 @@ do
--version=*)
VERSION=${p#*=}
;;
--create-tarball)
CREATE_TARBALL=true
;;
*)
echo "unrecognized option $p"
esac
done

mkdir_cp() {
mkdir -p $2 && cp -av $1 $2
}

builddir=$(mktemp -d -p $PWD .buildXXXXXX)
topdir="$PWD"
trap "rm -rf ${builddir}" INT EXIT
Expand Down Expand Up @@ -53,7 +61,9 @@ for d in `find $sdkdir/examples -name assets -type d`; do
mkdir -p $d/js && 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
(
Expand All @@ -68,18 +78,31 @@ done
cd examples; \
scripts/build-with-docker.sh --proxy="${PROXY}" \
--version="${VERSION}" \
--anbox-stream-sdk="$topdir"/"$sdkname".zip; \
--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"; \
# 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
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
)
23 changes: 19 additions & 4 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

ALLOWLIST="./sdk-files.allowlist"
SDK_ZIP_TARBALL="./anbox-streaming-sdk.zip"
SDK_PATH=

show_help() {
cat <<'EOF'
Expand All @@ -16,6 +17,7 @@ Validates Anbox Streaming SDK by checking that all included source files are in
optional arguments:
--allowlist=<path> Path to the file holding the list of allowed files into the sdk (default: ./sdk-files.allowlist)
--sdk-zip-tarball=<path> Path to the streaming sdk zip tarball (default: ./anbox-streaming-sdk.zip)
--sdk-path=<path> Path to the folder path that include the Anbox Streaming SDK
EOF
}

Expand All @@ -29,6 +31,10 @@ while [ -n "$1" ]; do
ALLOWLIST=${1#*=}
shift
;;
--sdk-path*)
SDK_PATH=${1#*=}
shift
;;
--sdk-zip-tarball=*)
SDK_ZIP_TARBALL=${1#*=}
shift
Expand All @@ -40,8 +46,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

Expand Down Expand Up @@ -79,11 +90,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)"

Expand Down

0 comments on commit 8f89b41

Please sign in to comment.