diff --git a/.github/workflows/pake_build.yaml b/.github/workflows/pake_build.yaml index aac097d..e424cdc 100644 --- a/.github/workflows/pake_build.yaml +++ b/.github/workflows/pake_build.yaml @@ -1,10 +1,9 @@ -name: build +name: Build App on: push: # Sequence of patterns matched against refs/tags tags: - "V*" - workflow_dispatch: jobs: build: @@ -15,16 +14,16 @@ jobs: build: [linux, windows, macos] include: - build: linux - os: ubuntu-latest - rust: nightly + os: ubuntu-20.04 + rust: stable target: x86_64-unknown-linux-musl - build: windows os: windows-latest - rust: nightly-x86_64-msvc + rust: stable-x86_64-msvc target: x86_64-pc-windows-msvc - build: macos os: macos-latest - rust: nightly + rust: stable target: x86_64-apple-darwin fail-fast: false @@ -46,13 +45,25 @@ jobs: target: ${{ matrix.target }} - name: install dependencies (ubuntu only) - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf gnome-video-effects gnome-video-effects-extra + if: matrix.os == 'ubuntu-20.04' + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra + version: 1.1 + + - name: rust cache restore + uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + src-tauri/target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: build for Ubuntu - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-20.04' run: npm run build:all-unix - name: build for MacOS @@ -63,30 +74,14 @@ jobs: - name: build for windows if: matrix.os == 'windows-latest' + shell: pwsh run: | npm run build:all-windows - # - name: Create Release and Upload Release Asset - # uses: softprops/action-gh-release@v1 - # if: startsWith(github.ref, 'refs/tags/') - # with: - # tag_name: ${{ github.ref }} - # name: Release ${{ github.ref }} - # body: TODO New Release. - # draft: false - # prerelease: false - # files: | - # output/*/*.* - - # - uses: ncipollo/release-action@v1 - # if: startsWith(github.ref, 'refs/tags/v') - # with: - # allowUpdates: true - # artifacts: "output/*/*.*" - # token: ${{ secrets.GITHUB_TOKEN }} - name: Upload files - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl -L https://github.com/probonopd/uploadtool/raw/master/upload.sh --output upload.sh - bash upload.sh output/*/*.* + # arg info: https://github.com/ncipollo/release-action#release-action + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + artifacts: "output/*/*.*" + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index 30fc33d..3ed4caf 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "build": "npm run tauri build --release", "build:mac": "npm run tauri build -- --target universal-apple-darwin", "build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh", - "build:all-windows": ".\\script\\build.bat", + "build:all-windows": "pwsh ./script/build.ps1", "tauri": "tauri", "cli": "rollup -c rollup.config.js --watch", "cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js", diff --git a/script/build.ps1 b/script/build.ps1 new file mode 100644 index 0000000..74c5320 --- /dev/null +++ b/script/build.ps1 @@ -0,0 +1,134 @@ +chcp 65001 | Out-Null + +if (-not (Test-Path node_modules)) { + npm i +} + +if (-not (Test-Path output)) { + New-Item -ItemType Directory -Path output +} + +if (-not (Test-Path output\windows)) { + New-Item -ItemType Directory -Path output\windows +} else { + Remove-Item output\windows -Recurse -Force + New-Item -ItemType Directory -Path output\windows +} + +Write-Host "`n=======================" +Write-Host "build for windows" +Write-Host "make ture powershell == 7.2.10" +Write-Host "powershell 7.2.10 download url: https://github.com/PowerShell/PowerShell/releases/tag/v7.2.10" +Write-Host "Powershell info in your localhost " +$PSVersionTable +Write-Host "=======================`n" + + +$identifier_prefix = "com.tw93" + +# total package number +$index = 1 +$total = (Get-Content ./app.csv | Measure-Object -Line).Lines +$pake_conf_path = "src-tauri/pake.json" +$common_conf_path = "src-tauri/tauri.conf.json" +$windows_conf_path = "src-tauri/tauri.windows.conf.json" + +# ignore first header line +$total = $total - 1 + +# for windows, we need replace package name to title +ForEach ($line in (Get-Content -Path .\app.csv | Select-Object -Skip 1)) { + $name, $title, $name_zh, $url = $line.Split(",") + Write-Host "building package ${index}/${total}" + Write-Host "package name is ${name} ${name_zh}" + Write-Host "==========================" + Write-Host "building Args is:" + Write-Host "name = ${name}" + Write-Host "title = ${title}" + Write-Host "name_zh = ${name_zh}" + Write-Host "url = ${url}" + Write-Host "==========================" + # -- replace url -- # + # clear url with regex + (Get-Content -Path $pake_conf_path -Raw) -replace '"url":\s*"[^"]*"', '"url": ""' | Set-Content -Path $pake_conf_path + # replace url with no regex + (Get-Content -Path $pake_conf_path -Raw) | ForEach-Object { $_.Replace('"url": ""', "`"url`": `"${url}`"") } | Set-Content $pake_conf_path + + + # -- replace package name -- # + # clear package_name with regex + (Get-Content -Path $common_conf_path -Raw) -replace '"productName":\s*"[^"]*"', '"productName": ""' | Set-Content -Path $common_conf_path + # replace package_name with no regex + (Get-Content -Path $common_conf_path -Raw) | ForEach-Object { $_.Replace('"productName": ""', "`"productName`": `"${title}`"") } | Set-Content $common_conf_path + + + # -- replace systemTray iconPath -- # + # clear systemTray iconPath with regex + (Get-Content -Path $common_conf_path -Raw) -replace '"iconPath":\s*"[^"]*"', '"iconPath": ""' | Set-Content -Path $common_conf_path + # replace systemTray iconPath with no regex + (Get-Content -Path $common_conf_path -Raw) | ForEach-Object { $_.Replace('"iconPath": ""', "`"iconPath`": `"png/${name}_32.ico`"") } | Set-Content $common_conf_path + + # -- replace icon -- + # clear icon path with regex + (Get-Content -Path $windows_conf_path -Raw) -replace '(?s)"icon":\s*\[[^\]]*\]', '"icon": []' | Set-Content -Path $windows_conf_path + # replace icon path with no regex + (Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"icon": []', "`"icon`": [`"png/${name}_256.ico`", `"png/${name}_32.ico`"]") } | Set-Content $windows_conf_path + + # -- replace identifier -- + # clear identifier with regex + (Get-Content -Path $windows_conf_path -Raw) -replace '"identifier":\s*"[^"]*"', '"identifier": ""' | Set-Content -Path $windows_conf_path + # -- replace identifier with no regex -- + (Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"identifier": ""', "`"identifier`": `"${identifier_prefix}.${name}`"") } | Set-Content $windows_conf_path + + # -- replace icon resources -- + # clear resources with regex + (Get-Content -Path $windows_conf_path -Raw) -replace '(?s)"resources":\s*\[[^\]]*\]', '"resources": []' | Set-Content -Path $windows_conf_path + # replace resources with no regex + (Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"resources": []', "`"resources`": [`"png/${name}_32.ico`"]") } | Set-Content $windows_conf_path + + if (-not (Test-Path "src-tauri\png\${name}_32.ico")) { + Copy-Item "src-tauri\png\icon_32.ico" "src-tauri\png\${name}_32.ico" + } + + if (-not (Test-Path "src-tauri\png\${name}_256.ico")) { + Copy-Item "src-tauri\png\icon_256.ico" "src-tauri\png\${name}_256.ico" + } + + # build package + Write-Host "npm run build:windows" + npm run tauri build -- --target x86_64-pc-windows-msvc + Move-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\bundle\msi\*.msi" -Destination "output\windows\${title}_x64.msi" + #rm cache + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\*.exe" -Recurse -Force + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\resources\*.ico" -Recurse -Force + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\png\*.ico" -Recurse -Force + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\wix\*.*" -Recurse -Force + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\app.*" -Force + Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\resources" -Recurse -Force + Write-Host "package build success!" + Write-Host "" + $index++ + # strip blank line for common_conf_path + $lines = Get-Content ${common_conf_path} + $lastNonEmptyLineIndex = ($lines.Count - 1) + while ($lastNonEmptyLineIndex -ge 0 -and -not $lines[$lastNonEmptyLineIndex].Trim()) { + $lastNonEmptyLineIndex-- + } + if ($lastNonEmptyLineIndex -lt ($lines.Count - 1)) { + $lines = $lines[0..$lastNonEmptyLineIndex] + } + Set-Content -Path ${common_conf_path} -Value $lines + + # strip blank line for windows conf_path + $lines = Get-Content ${windows_conf_path} + $lastNonEmptyLineIndex = ($lines.Count - 1) + while ($lastNonEmptyLineIndex -ge 0 -and -not $lines[$lastNonEmptyLineIndex].Trim()) { + $lastNonEmptyLineIndex-- + } + if ($lastNonEmptyLineIndex -lt ($lines.Count - 1)) { + $lines = $lines[0..$lastNonEmptyLineIndex] + } + Set-Content -Path ${windows_conf_path} -Value $lines +} + +Write-Host "output dir is output\windows" diff --git a/script/build.sh b/script/build.sh index b5e91b6..87a47d3 100755 --- a/script/build.sh +++ b/script/build.sh @@ -23,16 +23,17 @@ if [[ "$OSTYPE" =~ ^darwin ]]; then fi SHELL_FOLDER=$(cd "$(dirname "$0")" || exit 1; pwd) +PROJECT_FOLDER=`dirname ${SHELL_FOLDER}` +echo "shell folder is ${SHELL_FOLDER}" +echo "project folder is ${PROJECT_FOLDER}" + # total app number, ignore first line total=$(sed -n '$=' app.csv) export total=$((total-1)) export index=1 -export old_name="weread" -export old_title="WeRead" -export old_zh_name="微信阅读" -export old_url="https://weread.qq.com/" export package_prefix="com-tw93" +export identifier_prefix="com.tw93" @@ -40,13 +41,9 @@ if [[ "$OSTYPE" =~ ^linux ]]; then echo "===============" echo "Build for Linux" echo "===============" - export sd=${SHELL_FOLDER}/sd-linux-x64 + export sd=${SHELL_FOLDER}/sd-linux-`arch` chmod +x "$sd" - # for linux, package name may be com.xxx.xxx - echo "rename package name" - export desktop_file="src-tauri/assets/${package_prefix}.weread.desktop" - # sed -i "s/\"productName\": \"weread\"/\"productName\": \"${package_prefix}-weread\"/g" src-tauri/tauri.conf.json - $sd "\"productName\": \"WeRead\"" "\"productName\": \"${package_prefix}-weread\"" src-tauri/tauri.conf.json + export desktop_file="src-tauri/assets/*.desktop" fi if [[ "$OSTYPE" =~ ^darwin ]]; then @@ -56,8 +53,6 @@ if [[ "$OSTYPE" =~ ^darwin ]]; then export sd=${SHELL_FOLDER}/sd-apple-x64 chmod +x "$sd" - echo "rename package name" - $sd "\"productName\": \"weread\"" "\"productName\": \"WeRead\"" src-tauri/tauri.conf.json fi tail -n +2 app.csv | while IFS=, read -r -a arr; @@ -66,51 +61,120 @@ do package_title=${arr[1]} package_zh_name=${arr[2]} url=${arr[3]} + # replace package info - $sd -s "${old_url}" "${url}" src-tauri/pake.json - $sd "${old_name}" "${package_name}" src-tauri/tauri.conf.json - # echo "update ico with 32x32 pictue" - # $sd "${old_name}" "${package_name}" src-tauri/src/main.rs + # clear url with regex + $sd "\"url\": \"(.*?)\"," "\"url\": \"\"," src-tauri/pake.json + # replace url with no regex + $sd -s "\"url\": \"\"," "\"url\": \"${url}\"," src-tauri/pake.json # for apple, need replace title if [[ "$OSTYPE" =~ ^darwin ]]; then - $sd "${old_name}" "${package_name}" src-tauri/tauri.macos.conf.json - $sd "${old_title}" "${package_title}" src-tauri/tauri.conf.json + # update icon + # if icon exists, change icon path + if [ ! -f "src-tauri/icons/${package_name}.icns" ]; then + # else, replace icon to default + echo "warning" + echo "icon for MacOS not exist, will use default icon to replace it" + echo "warning" + cp "src-tauri/icons/icon.icns" "src-tauri/icons/${package_name}.icns" + fi + # clear package_name with regex + $sd "\"productName\": \"(.*?)\"," "\"productName\": \"\"," src-tauri/tauri.conf.json + # replace package_name with no regex + $sd -s "\"productName\": \"\"," "\"productName\": \"${package_title}\"," src-tauri/tauri.conf.json + # clear icon path with regex + $sd "\"icon\": \[\"(.*?)\"\]," "\"icon\": [\"\"]," src-tauri/tauri.macos.conf.json + # replace icon path with no regex + $sd -s "\"icon\": [\"\"]," "\"icon\": [\"icons/${package_name}.icns\"]," src-tauri/tauri.macos.conf.json + # clear identifier with regex + $sd "\"identifier\": \"(.*?)\"," "\"identifier\": \"\"," src-tauri/tauri.macos.conf.json + # replace identifier with not regex + $sd -s "\"identifier\": \"\"," "\"identifier\": \"${identifier_prefix}.${package_name}\"," src-tauri/tauri.macos.conf.json fi - # echo "update ico with 32x32 pictue" + # echo "update ico with 32x32 picture" # cp "src-tauri/png/${package_name}_32.ico" "src-tauri/icons/icon.ico" if [[ "$OSTYPE" =~ ^linux ]]; then - $sd "${old_name}" "${package_name}" src-tauri/tauri.linux.conf.json - echo "update desktop" - old_desktop="src-tauri/assets/${package_prefix}-${old_name}.desktop" - new_desktop="src-tauri/assets/${package_prefix}-${package_name}.desktop" - mv "${old_desktop}" "${new_desktop}" - $sd "${old_zh_name}" "${package_zh_name}" "${new_desktop}" - $sd "${old_name}" "${package_name}" "${new_desktop}" - fi + # update icon + # if icon exists, change icon path + if [ ! -f "src-tauri/png/${package_name}_512.png" ]; then + # else, replace icon to default + echo "warning" + echo "icon for linux not exist, will use default icon to replace it" + echo "warning" + cp "src-tauri/png/icon_512.png" "src-tauri/png/${package_name}_512.png" + fi + # -- replace package name -- # + # clear package_name with regex + $sd "\"productName\": \"(.*?)\"," "\"productName\": \"\"," src-tauri/tauri.conf.json + # replace package_name with no regex + $sd -s "\"productName\": \"\"," "\"productName\": \"${package_prefix}-${package_name}\"," src-tauri/tauri.conf.json - # update package info - old_name=${package_name} - old_title=${package_title} - old_zh_name=${package_zh_name} - old_url=${url} + # -- replace systemTray iconPath -- # + # clear systemTray iconPath with regex + $sd "\"iconPath\": \"(.*?)\"," "\"iconPath\": \"\"," src-tauri/tauri.conf.json + # replace systemTray iconPath with no regex + $sd -s "\"iconPath\": \"\"," "\"iconPath\": \"png/${package_name}_512.png\"," src-tauri/tauri.conf.json + + # -- replace icon -- # + # clear icon path with regex + $sd "\"icon\": \[\"(.*?)\"\]," "\"icon\": [\"\"]," src-tauri/tauri.linux.conf.json + # replace icon path with no regex + $sd -s "\"icon\": [\"\"]," "\"icon\": [\"png/${package_name}_512.png\"]," src-tauri/tauri.linux.conf.json + + # -- replace identifier -- # + # clear identifier with regex + $sd "\"identifier\": \"(.*?)\"," "\"identifier\": \"\"," src-tauri/tauri.linux.conf.json + # replace identifier with not regex + $sd -s "\"identifier\": \"\"," "\"identifier\": \"${identifier_prefix}.${package_name}\"," src-tauri/tauri.linux.conf.json + echo "update desktop" + + new_desktop="${PROJECT_FOLDER}/src-tauri/assets/${package_prefix}-${package_name}.desktop" + new_desktop_map_path="/usr/share/applications/${package_prefix}-${package_name}.desktop" + for file in `ls ${PROJECT_FOLDER}/src-tauri/assets/` + do + mv "${PROJECT_FOLDER}/src-tauri/assets/${file}" "${new_desktop}" + echo mv "${PROJECT_FOLDER}/src-tauri/assets/${file}" "${new_desktop}" + done + # clear desktop file with regex + $sd "\"files\": \{\"(.*)\"\}" "\"files\": \{\"\"\}" src-tauri/tauri.linux.conf.json + # replace desktop file with no regex + $sd -s "\"files\": \{\"\"\}" "\"files\": {\"${new_desktop_map_path}\": \"${new_desktop}\"}" src-tauri/tauri.linux.conf.json + # clear desktop content with regex + $sd "Exec=.*" "Exec=" "${new_desktop}" + $sd "Icon=.*" "Icon=" "${new_desktop}" + $sd "Name=.*" "Name=" "${new_desktop}" + $sd "Name\[zh_CN\]=.*" "Name[zh_CN]=" "${new_desktop}" + # repleace dekstop content with no reg + $sd -s "Exec=" "Exec=${package_prefix}-${package_name}" "${new_desktop}" + $sd -s "Icon=" "Icon=${package_prefix}-${package_name}" "${new_desktop}" + $sd -s "Name=" "Name=${package_title}" "${new_desktop}" + $sd -s "Name[zh_CN]=" "Name[zh_CN]=${package_zh_name}" "${new_desktop}" + fi echo "building package ${index}/${total}" echo "package name is ${package_name} (${package_zh_name})" if [[ "$OSTYPE" =~ ^linux ]]; then npm run tauri build - mv src-tauri/target/release/bundle/deb/${package_prefix}-${package_name}*.deb output/linux/${package_title}_amd64.deb - mv src-tauri/target/release/bundle/appimage/${package_prefix}-${package_name}*.AppImage output/linux/${package_title}_amd64.AppImage + mv src-tauri/target/release/bundle/deb/${package_prefix}-"${package_name}"*.deb output/linux/"${package_title}"_`arch`.deb + mv src-tauri/target/release/bundle/appimage/${package_prefix}-"${package_name}"*.AppImage output/linux/"${package_title}"_`arch`.AppImage + echo clear cache + rm src-tauri/target/release + rm -rf src-tauri/target/release/bundle + fi if [[ "$OSTYPE" =~ ^darwin ]]; then npm run tauri build -- --target universal-apple-darwin - # mv src-tauri/target/release/bundle/dmg/*.dmg output/macos/${package_title}_x64.dmg - mv src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg output/macos/${package_title}.dmg + mv src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg output/macos/"${package_title}".dmg + echo clear cache + rm -rf src-tauri/target/universal-apple-darwin + rm src-tauri/target/aarch64-apple-darwin/release + rm src-tauri/target/x86_64-apple-darwin/release fi echo "package build success!" @@ -119,4 +183,4 @@ done echo "build all package success!" echo "you run 'rm src-tauri/assets/*.desktop && git checkout src-tauri' to recovery code" -# rm src-tauri/assets/*.desktop && git checkout src-tauri + diff --git a/script/sd.exe b/script/sd.exe deleted file mode 100644 index 285ed10..0000000 Binary files a/script/sd.exe and /dev/null differ diff --git a/src-tauri/tauri.linux.conf.json b/src-tauri/tauri.linux.conf.json index c4c78b0..7ab88e0 100644 --- a/src-tauri/tauri.linux.conf.json +++ b/src-tauri/tauri.linux.conf.json @@ -1,26 +1,15 @@ { "tauri": { "bundle": { - "icon": [ - "png/weread_256.ico", - "png/weread_512.png" - ], + "icon": ["png/weread_512.png"], "identifier": "com.tw93.weread", "active": true, "category": "DeveloperTool", "copyright": "", "deb": { "depends": [ - "libwebkit2gtk-4.0-dev", - "build-essential", "curl", - "wget", - "libssl-dev", - "libgtk-3-dev", - "libayatana-appindicator3-dev", - "librsvg2-dev", - "gnome-video-effects", - "gnome-video-effects-extra" + "wget" ], "files": { "/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop" diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 0c2eb5b..b46b429 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -1,10 +1,7 @@ { "tauri": { "bundle": { - "icon": [ - "png/weread_256.ico", - "png/weread_32.ico" - ], + "icon": ["png/weread_256.ico", "png/weread_32.ico"], "identifier": "com.tw93.weread", "active": true, "category": "DeveloperTool",