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 22, 2024
1 parent 912cf35 commit e6dfeaf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 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 @@ -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 \
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 @@ -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)
Expand Down
67 changes: 47 additions & 20 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -xe
#!/bin/bash -xe
#
# Copyright 2019 Canonical Ltd.
#
Expand All @@ -15,6 +15,7 @@
# limitations under the License.

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

for p in "$@"
Expand All @@ -26,22 +27,33 @@ 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

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
Expand All @@ -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
)
1 change: 1 addition & 0 deletions scripts/streaming-sdk-files.allowlist
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LICENSE
android/anbox_streaming_sdk/consumer-rules.pro
android/anbox_streaming_sdk/.gitignore
android/anbox_streaming_sdk/src/
Expand Down
23 changes: 19 additions & 4 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

show_help() {
cat <<'EOF'
Expand All @@ -26,6 +27,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 @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)"

Expand Down

0 comments on commit e6dfeaf

Please sign in to comment.