From 8a7dbf5944984c246fcef5f2e1b0a30d5123af0f Mon Sep 17 00:00:00 2001 From: huangrunheng <2234044577@qq.com> Date: Sun, 17 Dec 2023 01:35:40 +0800 Subject: [PATCH] tag: v0.1.7 --- .github/workflows/release-windows.yml | 17 ++++---- script/release_windows_package.py | 60 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 script/release_windows_package.py diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 89b9336..d8ac7df 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -73,13 +73,14 @@ jobs: id: build run: flutter build windows # 打包 - - run: Move-Item -Path ".\build\windows\runner\Release" -Destination ".\oasx_${{ steps.get_release.outputs.tag_name }}_windows" - - name: Compress file - uses: a7ul/tar-action@v1.1.0 + - name: Package oasx + id: package + uses: actions/setup-python@v4 with: - command: c - files: ./oasx_${{ steps.get_release.outputs.tag_name }}_windows - outPath: ./oasx_${{ steps.get_release.outputs.tag_name }}_windows.tar.gz + python-version: '3.10' + - run: | + python ./script/release_windows_package.py --version ${{ steps.get_release.outputs.version }} + # 发布到 Release - name: Upload Release Windows uses: actions/upload-release-asset@v1 @@ -87,6 +88,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} with: upload_url: ${{ steps.get_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./oasx_${{ steps.get_release.outputs.tag_name }}_windows.tar.gz - asset_name: oasx_${{ steps.get_release.outputs.tag_name }}_windows.tar.gz + asset_path: ./oasx_${{ steps.get_release.outputs.tag_name }}_windows.zip + asset_name: oasx_${{ steps.get_release.outputs.tag_name }}_windows.zip asset_content_type: application/gzip \ No newline at end of file diff --git a/script/release_windows_package.py b/script/release_windows_package.py new file mode 100644 index 0000000..c54aa00 --- /dev/null +++ b/script/release_windows_package.py @@ -0,0 +1,60 @@ +import argparse +import re +import os +import zipfile +import time + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--path", + type=str, + help="xxx", + ) + parser.add_argument( + "--version", + type=str, + help="xxx", + ) + args, _ = parser.parse_known_args() + if args.path: + release_path = args.path + else: + if os.path.exists("./build/windows/x64/runner/Release/oasx.exe"): + release_path = "./build/windows/x64/runner/Release" + elif os.path.exists("./build/windows/runner/Release/oasx.exe"): + release_path = "./build/windows/runner/Release" + else: + raise FileNotFoundError("No release path found.") + match = re.search(r'build.*Release', release_path) + if match: + release_path = match.group(0) + release_path = release_path.replace('\\', '/') + print(f"Matched string: {release_path}") + else: + print("No match found.") + + if args.version: + release_version = args.tag + else: + with open('./CHANGELOG.md', 'r', encoding='utf-8') as file: + log = file.read() + log = re.search(r'v\d+\.\d+\.\d+', log).group(0) + log = log.replace('\n', '').replace('\r', '').replace(' ', '') + release_version = log + + + # 压缩 + zip_filename = f'oasx_{release_version}_windows.zip' + with zipfile.ZipFile(zip_filename, 'w') as zip_file: + # 遍历文件夹中的文件 + for foldername, subfolders, filenames in os.walk(release_path): + for filename in filenames: + # 构建文件的完整路径 + file_path = os.path.join(foldername, filename) + + # 将文件添加到 Zip 文件中 + zip_file.write(file_path, os.path.relpath(file_path, release_path)) + + time.sleep(10)