From 94236637615e661e1f0d7d8422a98d7f95bdc7e7 Mon Sep 17 00:00:00 2001 From: richardo2016x Date: Thu, 17 Oct 2024 18:07:47 +0800 Subject: [PATCH] build: test stable zip. --- scripts/autobuild.sh | 22 ++++++++--------- scripts/fns.sh | 40 ++++++++++++++++++++++++++++++ scripts/notify-lark.js | 9 +++++-- scripts/pack-debug.sh | 55 +++++++++++++++++++++++++++++++++--------- 4 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 scripts/fns.sh diff --git a/scripts/autobuild.sh b/scripts/autobuild.sh index 8295ea905cc..7880fa40b99 100755 --- a/scripts/autobuild.sh +++ b/scripts/autobuild.sh @@ -4,6 +4,8 @@ set -e script_dir="$( cd "$( dirname "$0" )" && pwd )" project_dir=$(dirname "$script_dir") +. $script_dir/fns.sh --source-only + export VERSION=$(node --eval="process.stdout.write(require('./package.json').version)"); export RABBY_GIT_HASH=$(git rev-parse --short HEAD); export CURRENT_TIME=$(date +%Y%m%d%H%M%S); @@ -19,18 +21,11 @@ if [ -z $NO_BUILD ]; then fi echo "[pack] built finished"; -DIST_DIR=$project_dir/dist; - -rm -rf $project_dir/tmp/ && mkdir -p $project_dir/tmp/; -if [ -d $DIST_DIR ]; then - cd $DIST_DIR; - zip -r $TARGET_FILE ./* -else - echo "[pack] dist dir not found: $DIST_DIR"; -fi +cd $project_dir; +rm -f $TARGET_FILE; +pack_dist_to_zip $TARGET_FILE; cd $project_dir; -# cp $TARGET_FILE $project_dir/tmp/RabbyDebug-latest.zip # upload to storage if [ -z $NO_UPLOAD ]; then @@ -42,12 +37,15 @@ if [ -z $NO_UPLOAD ]; then QUIET_PARASM="" fi echo "[pack] start upload..."; - aws s3 cp $QUIET_PARASM $project_dir/tmp/ s3://$RABBY_BUILD_BUCKET/rabby/autobuild/RabbyDebug-$CURRENT_TIME --recursive --exclude="*" --include "*.zip" --acl public-read + # aws s3 cp $QUIET_PARASM $project_dir/tmp/ s3://$RABBY_BUILD_BUCKET/rabby/autobuild/RabbyDebug-$CURRENT_TIME --recursive --exclude="*" --include "*.zip" --acl public-read echo "[pack] uploaded. DOWNLOAD_URL is $DOWNLOAD_URL"; if [ ! -z $notify_lark ]; then echo "[pack] update latest link..."; - node ./scripts/notify-lark.js "$DOWNLOAD_URL" + md5_value=$(md5 -q $TARGET_FILE); + + echo "[pack] (md5: $TARGET_FILE) $md5_value"; + node ./scripts/notify-lark.js "$DOWNLOAD_URL" "$md5_value" else echo "[pack] skip notify."; fi diff --git a/scripts/fns.sh b/scripts/fns.sh new file mode 100644 index 00000000000..7040e79a8f3 --- /dev/null +++ b/scripts/fns.sh @@ -0,0 +1,40 @@ +script_dir="$( cd "$( dirname "$0" )" && pwd )" +project_dir=$(dirname "$script_dir") +systype=$(uname -s) + +pack_dist_to_zip() { + local entry_dir=$project_dir; + local files=$(find "$entry_dir/dist" -type f | sort) + local dest_zip=$1 + + if [ -z $dest_zip ]; then + echo "dest_zip is required" + exit 1 + fi + + if [ -z $build_type ]; then + build_type="debug" + fi + + git_committish=$(git log --format="%h" -n 1) + # e.g. '2024-01-01 01:01:01 +0000' + git_tz_time_linux=$(git log --format="%cd" -n 1 --date=format:'%Y-%m-%d %H:%M:%S %z') + # SetFile format, e.g. '01/01/2024 01:01:01 +0000' + git_tz_time_setfile=$(git log --format="%cd" -n 1 --date=format:'%m/%d/%Y %H:%M:%S %z') + + for file in $files; do + if [ "$systype" = "Darwin" ]; then + SetFile -d "$git_tz_time_setfile" "$file" + SetFile -m "$git_tz_time_setfile" "$file" + elif [ "$systype" = "Linux" ]; then + touch -a -d "$git_tz_time_linux" "$file" + touch -m -d "$git_tz_time_linux" "$file" + fi + + local relname=${file#$entry_dir/} + zip -X "$dest_zip" "$relname" + done + + echo "git_tz_time_setfile is $git_tz_time_setfile" + echo "git_tz_time_linux is $git_tz_time_linux" +} \ No newline at end of file diff --git a/scripts/notify-lark.js b/scripts/notify-lark.js index e90c5c04ef7..1bc86f586c8 100644 --- a/scripts/notify-lark.js +++ b/scripts/notify-lark.js @@ -33,6 +33,7 @@ if (!secret) { // sendMessage with axios async function sendMessage({ downloadURL = '', + md5Value = '', actionsJobUrl = '', gitCommitURL = '', gitRefURL = '', @@ -65,6 +66,9 @@ async function sendMessage({ { "tag": "text", "text": `Download URL: ` }, { "tag": "a", "href": downloadURL, "text": downloadURL } ], + [ + { "tag": "text", "text": `MD5: ${md5Value}` }, + ], [ { "tag": "text", "text": `---------` }, ], @@ -99,8 +103,9 @@ const args = process.argv.slice(2); if (args[0]) { sendMessage({ downloadURL: args[0], - actionsJobUrl: args[1] || process.env.ACTIONS_JOB_URL, - gitCommitURL: args[2] || process.env.GIT_COMMIT_URL, + md5Value: args[1], + actionsJobUrl: args[2] || process.env.ACTIONS_JOB_URL, + gitCommitURL: args[3] || process.env.GIT_COMMIT_URL, gitRefURL: process.env.GIT_REF_URL, triggers: [ process.env.GITHUB_TRIGGERING_ACTOR, diff --git a/scripts/pack-debug.sh b/scripts/pack-debug.sh index 1b1e9cffe76..1bf35abcc1b 100755 --- a/scripts/pack-debug.sh +++ b/scripts/pack-debug.sh @@ -3,18 +3,51 @@ script_dir="$( cd "$( dirname "$0" )" && pwd )" project_dir=$(dirname "$script_dir") systype=$(uname -s) +if [ -z $build_type ]; then + build_type="debug" +fi cd $project_dir; app_ver=$(node -p "require('./package.json').version") git_committish=$(git log --format="%h" -n 1) +# e.g. '2024-01-01 01:01:01 +0000' +git_tz_time_linux=$(git log --format="%cd" -n 1 --date=format:'%Y-%m-%d %H:%M:%S %z') +# SetFile format, e.g. '01/01/2024 01:01:01 +0000' +git_tz_time_setfile=$(git log --format="%cd" -n 1 --date=format:'%m/%d/%Y %H:%M:%S %z') pack_dist() { - rm -rf ./tmp/ && mkdir -p ./tmp/ && \ - zip -r ./tmp/Rabby_v${app_ver}_debug.${git_committish}.zip ./dist + rm -rf $project_dir/tmp/*.zip && mkdir -p $project_dir/tmp/; + + local entry_dir=$project_dir; + + if [ ! -d "$entry_dir/dist" ]; then + echo "dist not exists" + exit 1 + fi + + local files=$(find "$entry_dir/dist" -type f | sort) + local dest_zip="$project_dir/tmp/Rabby_v${app_ver}_${build_type}.${git_committish}.zip" + for file in $files; do + if [ "$systype" = "Darwin" ]; then + SetFile -d "$git_tz_time_setfile" "$file" + SetFile -m "$git_tz_time_setfile" "$file" + elif [ "$systype" = "Linux" ]; then + touch -c -d "$git_tz_time_linux" "$file" + touch -c -m "$git_tz_time_linux" "$file" + fi + + local relname=${file#$entry_dir/} + zip -X "$dest_zip" "$relname" + done + + echo "git_tz_time_setfile is $git_tz_time_setfile" + echo "git_tz_time_linux is $git_tz_time_linux" + cd $project_dir; + } build() { - yarn build:debug; + yarn build:${build_type}; } if [ "$1" = "--pack-only" ]; then @@ -23,11 +56,11 @@ else build && pack_dist; fi -case $systype in - "Darwin") - open ./tmp/ - ;; - MSYS_NT*|MINGW*) - start "" .\\tmp - ;; -esac \ No newline at end of file +# case $systype in +# "Darwin") +# open ./tmp/ +# ;; +# MSYS_NT*|MINGW*) +# start "" .\\tmp +# ;; +# esac \ No newline at end of file