diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c5d3e60..84fe4fa 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -46,15 +46,18 @@ jobs: - uses: actions/checkout@v1 with: fetch-depth: 1 + # 编译 - name: Build MacOS run: | export ENV_QT_CLANG=$(pwd)/${{env.Qt5_Dir}} ci/mac/build_for_mac.sh release + # 发布 - name: Publish if: startsWith(github.event.ref, 'refs/tags/') run: | export ENV_QT_CLANG=$(pwd)/${{env.Qt5_Dir}} ci/mac/publish_for_mac.sh ../build + ci/mac/package_for_mac.sh # tag 打包 - name: Package if: startsWith(github.event.ref, 'refs/tags/') @@ -65,7 +68,7 @@ jobs: [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) [string]$name = 'QtScrcpy-mac-x64-' + ${tag} # 打包zip - Compress-Archive -Path ci\build\QtScrcpy.app ci\build\${name}.zip + Compress-Archive -Path ci\build\QtScrcpy.dmg ci\build\${name}.zip # 查询Release - name: Query Release if: startsWith(github.event.ref, 'refs/tags/') @@ -73,12 +76,20 @@ jobs: env: githubFullName: ${{ github.event.repository.full_name }} ref: ${{ github.event.ref }} + github_token: ${{ secrets.GITHUB_TOKEN }} run: | [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag} + + $token = ${env:github_token} + $authInfo = ("{0}" -f $token) + $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo) + $authInfo = [System.Convert]::ToBase64String($authInfo) + $headers = @{Authorization=("barry-ran {0}" -f $authInfo)} + $response={} try { - $response = Invoke-RestMethod -Uri $url -Method Get + $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get } catch { Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription @@ -102,12 +113,14 @@ jobs: run: | [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag} + # github token防止api rate limite,否则一个小时只能60个api请求 $token = ${env:github_token} $authInfo = ("{0}" -f $token) $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo) $authInfo = [System.Convert]::ToBase64String($authInfo) $headers = @{Authorization=("barry-ran {0}" -f $authInfo)} + $response = Invoke-RestMethod -Uri $url -ContentType 'text/json' -Headers $headers -Method Get [string]$latestUpUrl = $response.upload_url Write-Host 'latestUpUrl:'$latestUpUrl diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2b40ad2..6b58178 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -103,12 +103,20 @@ jobs: env: githubFullName: ${{ github.event.repository.full_name }} ref: ${{ github.event.ref }} + github_token: ${{ secrets.GITHUB_TOKEN }} run: | [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag} + + $token = ${env:github_token} + $authInfo = ("{0}" -f $token) + $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo) + $authInfo = [System.Convert]::ToBase64String($authInfo) + $headers = @{Authorization=("barry-ran {0}" -f $authInfo)} + $response={} try { - $response = Invoke-RestMethod -Uri $url -Method Get + $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get } catch { Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription diff --git a/ci/mac/package/dmg-background.jpg b/ci/mac/package/dmg-background.jpg new file mode 100644 index 0000000..84c5074 Binary files /dev/null and b/ci/mac/package/dmg-background.jpg differ diff --git a/ci/mac/package/package.py b/ci/mac/package/package.py new file mode 100644 index 0000000..a3bca07 --- /dev/null +++ b/ci/mac/package/package.py @@ -0,0 +1,55 @@ +import dmgbuild +import os +import json +import sys + +current_file_path = os.path.dirname(os.path.realpath(__file__)) +dmg_settings_path = '%s/dmg-settings.json' % current_file_path +dmg_background_img = '%s/dmg-background.jpg' % current_file_path +app_path = '%s/../../build/QtScrcpy.app' % current_file_path +dmg_path = '%s/../../build/QtScrcpy.dmg' % current_file_path +app_name = 'QtScrcpy' + +def console_print(msg): + print(msg) + sys.stdout.flush() + +def generate_dmg_info(): + with open(dmg_settings_path, 'w') as file: + info = { + 'title': app_name, + 'icon-size': 120, + 'background': dmg_background_img, + 'format': 'UDZO', + 'compression-level': 9, + 'window': { + 'position': {'x': 400, 'y': 200}, + 'size': {'width': 780, 'height': 480} + }, + 'contents': [ + { + 'x': 223, + 'y': 227, + 'type': 'file', + 'path': app_path + }, + { + 'x': 550, + 'y': 227, + 'type': 'link', + 'path': '/Applications' + } + ] + } + json.dump(info, file) + +if __name__ == '__main__': + console_print('generate dmg info') + generate_dmg_info() + console_print('build dmg: %s' % dmg_path) + dmgbuild.build_dmg(dmg_path, app_name, dmg_settings_path) + if not os.path.exists(dmg_path): + console_print('fail to create %s' % dmg_path) + sys.exit(1) + + sys.exit(0) \ No newline at end of file diff --git a/ci/mac/package/requirements.txt b/ci/mac/package/requirements.txt new file mode 100644 index 0000000..aa42ddf --- /dev/null +++ b/ci/mac/package/requirements.txt @@ -0,0 +1 @@ +dmgbuild==1.3.3 \ No newline at end of file diff --git a/ci/mac/package_for_mac.sh b/ci/mac/package_for_mac.sh new file mode 100755 index 0000000..60f01fa --- /dev/null +++ b/ci/mac/package_for_mac.sh @@ -0,0 +1,37 @@ +# 获取绝对路径,保证其他目录执行此脚本依然正确 +{ +cd $(dirname "$0") +script_path=$(pwd) +cd - +} &> /dev/null # disable output +# 设置当前目录,cd的目录影响接下来执行程序的工作目录 +old_cd=$(pwd) +cd $(dirname "$0") + +echo +echo +echo --------------------------------------------------------------- +echo pip install requirements +echo --------------------------------------------------------------- + +pip install -r $script_path/package/requirements.txt +if [ $? -ne 0 ] ;then + echo "pip install requirements failed" + exit 1 +fi + +echo +echo +echo --------------------------------------------------------------- +echo create package +echo --------------------------------------------------------------- + +python $script_path/package/package.py +if [ $? -ne 0 ] ;then + echo "create package failed" + exit 1 +fi + +# 恢复当前目录 +cd $old_cd +exit 0