From 8f09eb8554e65cb232e936ca3b44027b45c00d1b Mon Sep 17 00:00:00 2001 From: "marc.sirisak" Date: Tue, 28 Jan 2025 18:29:34 +0100 Subject: [PATCH] feat: build release script and action --- .github/workflows/publish.yml | 0 .github/workflows/test_build.yml | 53 +++++++++++++++++++++++ .gitignore | 1 + .vscode/extensions.json | 3 -- scripts/check-deploys.ts | 0 scripts/fetch-package.ts | 74 ++++++++++++++++++++++++++++++++ tchap_config.json | 5 +++ 7 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test_build.yml delete mode 100644 .vscode/extensions.json create mode 100644 scripts/check-deploys.ts create mode 100644 scripts/fetch-package.ts create mode 100644 tchap_config.json diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml new file mode 100644 index 0000000..427e882 --- /dev/null +++ b/.github/workflows/test_build.yml @@ -0,0 +1,53 @@ +name: "test-on-pr" + +on: [pull_request] + +# This workflow will build your tauri app without uploading it anywhere. + +jobs: + test-tauri: + strategy: + fail-fast: false + matrix: + include: + - platform: "macos-latest" # for Arm based macs (M1 and above). + args: "--target aarch64-apple-darwin" + - platform: "macos-latest" # for Intel based macs. + args: "--target x86_64-apple-darwin" + - platform: "ubuntu-22.04" # for Tauri v1 you could replace this with ubuntu-20.04. + args: "" + - platform: "windows-latest" + args: "" + + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v4 + + - name: setup node + uses: actions/setup-node@v4 + with: + node-version: lts/* + + - name: install Rust stable + uses: dtolnay/rust-toolchain@stable + with: + # Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds. + targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} + + - name: install dependencies (ubuntu only) + if: matrix.platform == 'ubuntu-22.04' # This must match the platform value defined above. + run: | + sudo apt-get update + sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf + # webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2. + # You can remove the one that doesn't apply to your app to speed up the workflow a bit. + + - name: install frontend dependencies + run: yarn install # change this to npm, pnpm or bun depending on which one you use. + + # If tagName and releaseId are omitted tauri-action will only build the app and won't try to upload any assets. + - uses: tauri-apps/tauri-action@v0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: ${{ matrix.args }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a547bf3..74015cf 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ dist dist-ssr *.local +deploys # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 24d7cc6..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] -} diff --git a/scripts/check-deploys.ts b/scripts/check-deploys.ts new file mode 100644 index 0000000..e69de29 diff --git a/scripts/fetch-package.ts b/scripts/fetch-package.ts new file mode 100644 index 0000000..822035b --- /dev/null +++ b/scripts/fetch-package.ts @@ -0,0 +1,74 @@ +#!/usr/bin/env -S npx tsx --resolveJsonModule + +import * as path from "node:path"; +import { createWriteStream, promises as fs } from "node:fs"; +import { promises as stream } from "node:stream"; + +import tchapConfigFile from "../tchap_config.json"; + +const PACKAGE_URL_PREFIX = "https://github.com/element-hq/element-web/releases/download/" + +async function downloadToFile(url: string, filename: string): Promise { + console.log("Downloading " + url + "..."); + + try { + const resp = await fetch(url); + if (!resp.ok) throw new Error(`unexpected response ${resp.statusText}`); + if (!resp.body) throw new Error(`unexpected response has no body ${resp.statusText}`); + await stream.pipeline(resp.body, createWriteStream(filename)); + } catch (e) { + console.error(e); + try { + await fs.unlink(filename); + } catch {} + throw e; + } +} + +function cleanFolder(directory) { + fs.readdir(directory, (err, files) => { + if (err) throw err; + + for (const file of files) { + fs.unlink(path.join(directory, file), (err) => { + if (err) throw err; + }); + } + }); +} + +async function main(): Promise { + let pkgDir = "src"; + let targetVersion: string | undefined = tchapConfigFile!["tchap-web_version"]; + let filename: string | undefined = tchapConfigFile!["tchap-web_archive_name"]; + let url: string | undefined; + + + filename = `tchap-${targetVersion}.tar.gz`; + url = PACKAGE_URL_PREFIX + targetVersion + "/" + filename; + + // clean up src folder firstc + try { + cleanFolder(pkgDir); + console.log(pkgDir + "cleaned"); + } catch {} + + const outPath = path.join(pkgDir, filename); + try { + await downloadToFile(url, outPath); + } catch (e) { + console.log("Failed to download " + url, e); + return 1; + } + + console.log("Done!"); +} + +main() + .then((ret) => { + process.exit(ret); + }) + .catch((e) => { + console.error(e); + process.exit(1); + }); diff --git a/tchap_config.json b/tchap_config.json new file mode 100644 index 0000000..0e6aa21 --- /dev/null +++ b/tchap_config.json @@ -0,0 +1,5 @@ +{ + "release_version": "0.0.0", + "tchap-web_version": "4.12.1", + "tchap-web_archive_name": "tchap-4.12.1-prod-20250113.tar.gz" +} \ No newline at end of file