From 76ee3a185e8d365abb2f0751df8bfd1274d46ed3 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Mon, 28 Aug 2023 18:59:32 +0800 Subject: [PATCH] :art: Refactoring action packaging logic --- .github/workflows/pake-cli.yaml | 2 +- .github/workflows/pake_build_single_app.yaml | 8 +++--- ...pp_config.mjs => build_with_app_config.js} | 28 ++++++++----------- ...th_pake_cli.mjs => build_with_pake_cli.js} | 0 4 files changed, 17 insertions(+), 21 deletions(-) rename script/{build_with_app_config.mjs => build_with_app_config.js} (87%) rename script/{build_with_pake_cli.mjs => build_with_pake_cli.js} (100%) diff --git a/.github/workflows/pake-cli.yaml b/.github/workflows/pake-cli.yaml index d8ecb6e..4113021 100644 --- a/.github/workflows/pake-cli.yaml +++ b/.github/workflows/pake-cli.yaml @@ -117,7 +117,7 @@ jobs: - name: Build with pake-cli run: | - node ./script/build_with_pake_cli.mjs + node ./script/build_with_pake_cli.js env: URL: ${{ inputs.url }} NAME: ${{ inputs.name }} diff --git a/.github/workflows/pake_build_single_app.yaml b/.github/workflows/pake_build_single_app.yaml index 43b3443..2414c1f 100644 --- a/.github/workflows/pake_build_single_app.yaml +++ b/.github/workflows/pake_build_single_app.yaml @@ -71,14 +71,14 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} - - name: install dependencies (ubuntu only) + - name: Install dependencies (ubuntu only) if: matrix.os == 'ubuntu-latest' 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 + - name: Rust cache restore id: cache_store uses: actions/cache/restore@v3 with: @@ -98,7 +98,7 @@ jobs: URL: ${{ inputs.url }} run: | npm install - node ./script/build_with_pake_cli.mjs + node ./script/build_with_pake_cli.js - name: Build for Ubuntu if: matrix.os == 'ubuntu-latest' @@ -129,7 +129,7 @@ jobs: run: | git checkout -- src-tauri/Cargo.lock - - name: rust cache store + - name: Rust cache store uses: actions/cache/save@v3 with: path: | diff --git a/script/build_with_app_config.mjs b/script/build_with_app_config.js similarity index 87% rename from script/build_with_app_config.mjs rename to script/build_with_app_config.js index 765497a..6d8ba9e 100755 --- a/script/build_with_app_config.mjs +++ b/script/build_with_app_config.js @@ -1,12 +1,12 @@ -import pakeJson from '../src-tauri/pake.json' assert { type: 'json' }; -import tauriJson from '../src-tauri/tauri.conf.json' assert { type: 'json' }; -import windowsJson from '../src-tauri/tauri.windows.conf.json' assert { type: 'json' }; -import macosJson from '../src-tauri/tauri.macos.conf.json' assert { type: 'json' }; -import linuxJson from '../src-tauri/tauri.linux.conf.json' assert { type: 'json' }; - -import { writeFileSync, existsSync, copyFileSync } from 'fs'; +import { writeFileSync, existsSync, copyFileSync, readFileSync } from 'fs'; import os from 'os'; +const pakeJson = JSON.parse(readFileSync('../src-tauri/pake.json', 'utf-8')); +const tauriJson = JSON.parse(readFileSync('../src-tauri/tauri.conf.json', 'utf-8')); +const windowsJson = JSON.parse(readFileSync('../src-tauri/tauri.windows.conf.json', 'utf-8')); +const macosJson = JSON.parse(readFileSync('../src-tauri/tauri.macos.conf.json', 'utf-8')); +const linuxJson = JSON.parse(readFileSync('../src-tauri/tauri.linux.conf.json', 'utf-8')); + const desktopEntry = `[Desktop Entry] Encoding=UTF-8 Categories=Office @@ -55,8 +55,7 @@ const variables = { hdIconPath: `src-tauri/png/${process.env.NAME}_256.ico`, hdDefaultPath: 'src-tauri/png/icon_256.ico', icon: [`png/${process.env.NAME}_256.ico`, `png/${process.env.NAME}_32.ico`], - resources: [`png/${process.env.NAME}_32.ico`] - + resources: [`png/${process.env.NAME}_32.ico`], }, }; @@ -82,12 +81,11 @@ switch (os.platform()) { case 'win32': platformConfig = windowsJson; platformVariables = variables.windows; - updateResources() + updateResources(); updateIconFile(platformVariables.hdIconPath, platformVariables.hdDefaultPath); break; } - updateIconFile(platformVariables.iconPath, platformVariables.defaultIconPath); updatePlatformConfig(platformConfig, platformVariables); @@ -149,7 +147,6 @@ function updatePlatformConfig(platformConfig, platformVariables) { } function save() { - writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2)); writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2)); @@ -159,16 +156,15 @@ function save() { writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2)); writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2)); - } function updateDesktopEntry() { linuxJson.tauri.bundle.deb.files = {}; linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] = - variables.linux.desktopEntryConfig.configValue; + variables.linux.desktopEntryConfig.configValue; writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry); } -function updateResources(){ +function updateResources() { windowsJson.tauri.bundle.resources = variables.windows.resources; -} \ No newline at end of file +} diff --git a/script/build_with_pake_cli.mjs b/script/build_with_pake_cli.js similarity index 100% rename from script/build_with_pake_cli.mjs rename to script/build_with_pake_cli.js