From 9d205c4a36eeb8ff484e6d635c3e070029d6a8e5 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Sat, 8 Apr 2023 14:28:43 +0800 Subject: [PATCH] add pake-cli for dev branch --- .github/workflows/pake-cli.yaml | 161 ++++++++++++++++++++++++++++++++ script/build_with_pake_cli.ps1 | 84 +++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 .github/workflows/pake-cli.yaml create mode 100644 script/build_with_pake_cli.ps1 diff --git a/.github/workflows/pake-cli.yaml b/.github/workflows/pake-cli.yaml new file mode 100644 index 0000000..57a74b1 --- /dev/null +++ b/.github/workflows/pake-cli.yaml @@ -0,0 +1,161 @@ +name: Build App with Pake-Cli +on: + workflow_dispatch: + inputs: + platform: + description: "platform" + required: true + default: "macos-latest" + type: choice + options: + - "windows-latest" + - "macos-latest" + - "ubuntu-20.04" + url: + description: "[URL]" + required: true + name: + description: "[Name]" + required: true + icon: + description: "[Icon, Optional]" + required: false + height: + description: "[Height, Optional]" + required: false + default: "780" + width: + description: "[Width, Optional]" + required: false + default: "1200" + transparent: + description: "[Transparent, Optional]" + required: false + type: boolean + default: false + # fullscreen: + # description: "[FullScreen, Optional]" + # required: false + # type: boolean + # default: false + resize: + description: "[Resize, Optional]" + required: false + type: boolean + default: true + multi_arch: + description: "[MultiArch, Optional, MacOS only]" + required: false + type: boolean + default: false + targets: + description: "[Targets, Optional, Linux only]" + required: false + default: "deb" + type: choice + options: + - "deb" + - "appimage" + - "all" + + +jobs: + build: + name: ${{ inputs.platform }} + runs-on: ${{ inputs.platform }} + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: install node + uses: actions/setup-node@v1 + with: + node-version: 18 + + - name: Install Rust for ubuntu-20.04 + if: inputs.platform == 'ubuntu-20.04' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: x86_64-unknown-linux-musl + + - name: Install Rust for windows-latest + if: inputs.platform == 'windows-latest' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable-x86_64-msvc + profile: minimal + override: true + target: x86_64-pc-windows-msvc + + - name: Install Rust for macos-latest + if: inputs.platform == 'macos-latest' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: x86_64-apple-darwin + + - name: install dependencies (ubuntu only) + if: inputs.platform == '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: install pake-cli local + shell: bash + run: | + echo "install pake on local" + npm install pake-cli + + - name: rust cache restore + uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + node_modules/pake-cli/src-tauri/target/ + key: ${{ inputs.platform }}-cargo-${{ hashFiles('node_modules/pake-cli/src-tauri/Cargo.lock') }} + + - name: build with pake-cli + shell: pwsh + run: | + pwsh ./script/build_with_pake_cli.ps1 + env: + URL: ${{ inputs.url }} + NAME: ${{ inputs.name }} + ICON: ${{ inputs.icon }} + HEIGHT: ${{ inputs.height }} + WIDTH: ${{ inputs.width }} + TRANSPARENT: ${{ inputs.transparent }} + FULLSCREEN: ${{ inputs.fullscreen }} + RESIZE: ${{ inputs.resize }} + MULTI_ARCH: ${{ inputs.multi_arch }} + TARGETS: ${{ inputs.targets }} + + - name: Upload archive + uses: actions/upload-artifact@v3 + with: + name: output-${{ inputs.platform }}.zip + path: node_modules/pake-cli/output/* + retention-days: 3 + + - name: rust cache store + uses: actions/cache/save@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + node_modules/pake-cli/src-tauri/target/ + key: ${{ inputs.platform }}-cargo-${{ hashFiles('node_modules/pake-cli/src-tauri/Cargo.lock') }} \ No newline at end of file diff --git a/script/build_with_pake_cli.ps1 b/script/build_with_pake_cli.ps1 new file mode 100644 index 0000000..773d5f4 --- /dev/null +++ b/script/build_with_pake_cli.ps1 @@ -0,0 +1,84 @@ +Write-Host "Welcome to use Powershell" +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=======================`n" + +Write-Host "`n=======================" +Write-Host "pake parameters is: " +Write-Host "url: " $env:URL +Write-Host "name: " $env:NAME +Write-Host "icon: " $env:ICON +Write-Host "height: " $env:HEIGHT +Write-Host "width: " $env:WIDTH +Write-Host "transparent: " $env:TRANSPARENT +# Write-Host "fullscreen: " $env:FULLSCREEN +Write-Host "resize: " $env:RESIZE +Write-Host "is multi arch? only for Mac: " $env:MULTI_ARCH +Write-Host "targets type? only for Linux: " $env:TARGETS +Write-Host "===========================`n" + + +Set-Location node_modules/pake-cli +# init params +${Params}="node cli.js $env:URL --name $env:NAME" + +# download icon +if ((($null -ne $env:ICON) -and ($env:ICON -ne ""))){ + if ($IsLinux) { + curl -L "$env:ICON" -o icon.png + ${Params}="${Params} --icon icon.png" + } elseif ($IsMacOS) { + curl -L "$env:ICON" -o icon.icns + ${Params}="${Params} --icon icon.icns" + } elseif ($IsWindows) { + curl -L "$env:ICON" -o icon.ico + ${Params}="${Params} --icon icon.ico" + } else { + Write-Host "it won't download icon, becase it can't detect you OS system!" + } +} + +# height && weight +${Params}="${Params} --height $env:HEIGHT --width $env:WIDTH" + +# transparent +if ("$env:TRANSPARENT" -eq "true") { + ${Params}="${Params} --transparent" +} + +# fullscreen +# if ("$env:FULLSCREEN" -eq "true") { +# ${Params}="${Params} --fullscreen" +# } + +# resize +if ("$env:FULLSCREEN" -eq "true" ) { + ${Params}="${Params} --resize" +} + +# multi-arch only for mac +if (($env:MULTI_ARCH -eq "true") -and ($IsMacOS)) { + rustup target add aarch64-apple-darwin + ${Params}="${Params} --multi-arch" +} + +# targets type, only for linux +if (($null -ne $env:TARGETS) -and ($env:TARGETS -ne "") -and ($IsLinux)) { + ${Params}="${Params} --targets $env:TARGETS" +} + +Write-Host "Pake parameters is: ${Params}" +Write-Host "compile...." +Invoke-Expression $Params + +# output +if (-not(Test-Path output)) { + New-Item -ItemType Directory -Path "output" +} +Move-Item -Path "$env:NAME.*" -Destination "output/" +Write-Host "Build Success" +Set-Location ../..