diff --git a/.drone.yml b/.drone.yml index 8379d24..dcc4ce3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -61,7 +61,7 @@ steps: - name: windows构建上传exe和zip到iot测试接口platformAppAdd pull: if-not-exists - image: registry.cn-hangzhou.aliyuncs.com/qmiot/init:nsis20241218 + image: registry.cn-hangzhou.aliyuncs.com/qmiot/init:nsis20250102 environment: url_for_iotplatform: 'http://192.168.0.142:31667' url_for_iotfile: 'http://192.168.0.142:31666' diff --git a/IOTContainer/testci b/IOTContainer/testci new file mode 100644 index 0000000..d800886 --- /dev/null +++ b/IOTContainer/testci @@ -0,0 +1 @@ +123 \ No newline at end of file diff --git a/IOTContainer/testdir/aaa/bbb/123.txt b/IOTContainer/testdir/aaa/bbb/123.txt new file mode 100644 index 0000000..d800886 --- /dev/null +++ b/IOTContainer/testdir/aaa/bbb/123.txt @@ -0,0 +1 @@ +123 \ No newline at end of file diff --git a/iot_upload.py b/iot_upload.py index 7465384..da897f1 100644 --- a/iot_upload.py +++ b/iot_upload.py @@ -139,7 +139,7 @@ def platformProgramAdd(): # multipleProgramToOneProject() -def get_the_last_windowsAppZIP(name): +def get_the_last_windowsApp_GITversion(name): bodyjson = { 'name': name } @@ -155,19 +155,18 @@ def get_the_last_windowsAppZIP(name): print(f"name: {obj.get('name')}") print(f"packageName: {obj.get('packageName')}") print(f"packageUrl: {obj.get('packageUrl')}") - packageUrl=obj.get('packageUrl') + print(f"version: {obj.get('version')}") + the_last_windowsAppZIP_GITversion=obj.get('version') break # 找到第一个满足条件的对象后停止遍历 - # 忽略未经核实的SSL证书认证,linux下wget可能会有ssl问题 - context = ssl._create_unverified_context() - ssl._create_default_https_context = ssl._create_unverified_context - print('正在下载上一个版本的zip文件:') - download(cdn_url + packageUrl) - print(cdn_url + packageUrl) - the_last_windowsAppZIP = os.getcwd() + '/' + packageUrl.split("/")[-1] - return the_last_windowsAppZIP + print('正在git获取上一个版本的代码:') + os.system('mkdir -p /tmp/theLastCode/') + os.system('git clone' + os.getenv('DRONE_GIT_HTTP_URL') + ' /tmp/theLastCode/IOTContainer/' ) + os.system('cd /tmp/theLastCode/ && git checkout ' + the_last_windowsAppZIP_GITversion) + return the_last_windowsAppZIP_GITversion else: return None + def build_for_windowsApp(): print ("开始打包exe流程") @@ -194,17 +193,20 @@ def count_files_in_directory(directory): # return md5.hexdigest() def build_the_current_windowsApp(name): + the_last_windowsApp_GITversion = get_the_last_windowsApp_GITversion(name) + the_current_windowsAppZIP="/drone/src/IOTContainer/" + os.getenv('DRONE_REPO_NAME') + '.' + os.getenv('version') + '.zip' - the_last_windowsAppZIP = get_the_last_windowsAppZIP(name) + + # the_last_windowsAppZIP = get_the_last_windowsAppZIP(name) - os.system('mkdir -p /tmp/a/ /tmp/b/ /tmp/IOTContainer/') - os.system('unzip -q ' + the_last_windowsAppZIP + ' -d /tmp/a/') - os.system('unzip -q ' + the_current_windowsAppZIP + ' -d /tmp/b/') - os.system('/bin/sh -c /drone/src/zip_diff.sh') + # os.system('mkdir -p /tmp/a/ /tmp/b/ /tmp/IOTContainer/') + # os.system('unzip -q ' + the_last_windowsAppZIP + ' -d /tmp/a/') + # os.system('unzip -q ' + the_current_windowsAppZIP + ' -d /tmp/b/') + # os.system('/bin/sh -c /drone/src/zip_diff.sh') file_count = count_files_in_directory('/tmp/IOTContainer/') - if the_last_windowsAppZIP == None: + if the_last_windowsApp_GITversion == None: print("初次上传,不比对zip,直接打包上传") platformAppAdd(the_current_windowsAppZIP, '.zip') build_for_windowsApp() @@ -212,6 +214,8 @@ def build_the_current_windowsApp(name): else: print ("比对新老版本zip文件") + the_current_windowsAppZIP_dir = '/drone/src/IOTContainer' + the_last_windowsAppZIP_dir = '/tmp/theLastCode/IOTContainer' if file_count == 1: print ("\033[34m比对结果: 程序版本无更新,流程终止\033[0m") else: diff --git a/zip_diff.sh b/zip_diff.sh index a9b64f6..24efa39 100644 --- a/zip_diff.sh +++ b/zip_diff.sh @@ -1,8 +1,24 @@ -rm -rf /tmp/a/diff.tgz /tmp/b/diff.tgz +mkdir -p /tmp/IOTContainer/ +the_current_windowsAppZIP_dir='/drone/src/IOTContainer' +the_last_windowsAppZIP_dir='/tmp/theLastCode/IOTContainer' cat /drone/src/.tags > /tmp/IOTContainer/version -for i in $(diff -rq /tmp/a/ /tmp/b/ | grep Only | awk '{print $NF}') + +cd /tmp/IOTContainer/ +for i in $(diff -qr /drone/src/IOTContainer/ /tmp/theLastCode/IOTContainer/ | grep /drone/src/IOTContainer/ | grep Only | sed s#/drone/src/IOTContainer/#./# | sed 's#Only in ##') +do + dir=${i%:*} + file=${i##* } + mkdir -p /tmp/IOTContainer/$dir + cp -rp /drone/src/IOTContainer/$dir/$file /tmp/IOTContainer/$dir/$file + echo 差异文件$dir/$file +done + +for i in $(diff -qr /drone/src/IOTContainer/ /tmp/theLastCode/IOTContainer/ | grep /drone/src/IOTContainer/ | grep differ | sed s#/drone/src/IOTContainer/#./# | awk '{print $2}') do - mv /tmp/b/$i /tmp/IOTContainer/ + dir=${i%/*} + file=${i##*/} + mkdir -p /tmp/IOTContainer/$dir + cp -rp /drone/src/IOTContainer/$dir/$file /tmp/IOTContainer/$dir/$file echo 差异文件$i done