From 2440fedaadcaa20a2cc75f36738f1fe04aab2253 Mon Sep 17 00:00:00 2001 From: Alois Date: Mon, 25 May 2026 14:05:20 +0200 Subject: [PATCH] (feat): add auto update for dev builds on dev builds --- .forgejo/workflows/deploy-dev.yml | 27 ++++++++++++++++++++++++--- .forgejo/workflows/deploy-prod.yml | 25 ++++++++++++++++++++++--- apps/electron/src/main/updates.ts | 21 +++++++++++++++++++++ scripts/copy-releases.ts | 6 ++++-- 4 files changed, 71 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/deploy-dev.yml b/.forgejo/workflows/deploy-dev.yml index 41d03e1..36c5efe 100644 --- a/.forgejo/workflows/deploy-dev.yml +++ b/.forgejo/workflows/deploy-dev.yml @@ -104,6 +104,20 @@ jobs: - name: Build packages run: bun run build:packages + - name: Set Electron dev version + run: | + VERSION="$(node -p "require('./package.json').version")" + SHORT_SHA="$(git rev-parse --short HEAD)" + DEV_VERSION="$VERSION-dev-$SHORT_SHA" + export DEV_VERSION + node -e ' + const fs = require("fs"); + const path = "apps/electron/package.json"; + const pkg = JSON.parse(fs.readFileSync(path, "utf8")); + pkg.version = process.env.DEV_VERSION; + fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n"); + ' + - name: Build Electron desktop run: bun run build:desktop @@ -143,9 +157,6 @@ jobs: name: electron-desktop-linux path: apps/electron/release/ - - name: Copy releases - run: bun --bun run copy-releases - - name: Read version and hash id: version run: | @@ -156,6 +167,15 @@ jobs: echo "tag=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT" echo "title=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT" + - name: Copy releases + env: + TENSAMIN_RELEASE_VERSION: ${{ steps.version.outputs.tag }} + TENSAMIN_RELEASE_TAG: ${{ steps.version.outputs.tag }} + run: | + ASSET_BASE_URL="${{ forgejo.api_url }}" + ASSET_BASE_URL="${ASSET_BASE_URL%/api/v1}/${{ forgejo.repository }}/releases/download/${{ steps.version.outputs.tag }}" + FORGEJO_RELEASE_ASSET_BASE_URL="$ASSET_BASE_URL" bun --bun run copy-releases + - name: Create pre-release and upload files env: TOKEN: ${{ forgejo.token }} @@ -239,6 +259,7 @@ jobs: const fs = require("fs"); const path = "releases/electron-release-metadata.json"; const metadata = JSON.parse(fs.readFileSync(path, "utf8")); + metadata.version = process.env.TAG; metadata.tag = process.env.TAG; for (const artifact of metadata.artifacts || []) { artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`; diff --git a/.forgejo/workflows/deploy-prod.yml b/.forgejo/workflows/deploy-prod.yml index 95641f1..bc086d6 100644 --- a/.forgejo/workflows/deploy-prod.yml +++ b/.forgejo/workflows/deploy-prod.yml @@ -104,6 +104,18 @@ jobs: - name: Build packages run: bun run build:packages + - name: Set Electron prod version + run: | + VERSION="$(node -p "require('./package.json').version")" + export VERSION + node -e ' + const fs = require("fs"); + const path = "apps/electron/package.json"; + const pkg = JSON.parse(fs.readFileSync(path, "utf8")); + pkg.version = process.env.VERSION; + fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n"); + ' + - name: Build Electron desktop run: bun run build:desktop @@ -141,9 +153,6 @@ jobs: name: electron-desktop-linux path: apps/electron/release/ - - name: Copy releases - run: bun --bun run copy-releases - - name: Read version id: version run: | @@ -151,6 +160,15 @@ jobs: echo "version=$VERSION" >> "$FORGEJO_OUTPUT" echo "tag=$VERSION" >> "$FORGEJO_OUTPUT" + - name: Copy releases + env: + TENSAMIN_RELEASE_VERSION: ${{ steps.version.outputs.tag }} + TENSAMIN_RELEASE_TAG: ${{ steps.version.outputs.tag }} + run: | + ASSET_BASE_URL="${{ forgejo.api_url }}" + ASSET_BASE_URL="${ASSET_BASE_URL%/api/v1}/${{ forgejo.repository }}/releases/download/${{ steps.version.outputs.tag }}" + FORGEJO_RELEASE_ASSET_BASE_URL="$ASSET_BASE_URL" bun --bun run copy-releases + - name: Create release and upload files env: TOKEN: ${{ forgejo.token }} @@ -198,6 +216,7 @@ jobs: const fs = require("fs"); const path = "releases/electron-release-metadata.json"; const metadata = JSON.parse(fs.readFileSync(path, "utf8")); + metadata.version = process.env.TAG; metadata.tag = process.env.TAG; for (const artifact of metadata.artifacts || []) { artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`; diff --git a/apps/electron/src/main/updates.ts b/apps/electron/src/main/updates.ts index 982d191..7386118 100644 --- a/apps/electron/src/main/updates.ts +++ b/apps/electron/src/main/updates.ts @@ -20,6 +20,10 @@ function compareSemver(left: string, right: string) { return 0; } +function isDevVersion(version: string) { + return /-dev[.-]/.test(version); +} + function platformName() { if (process.platform === "win32") return "windows"; if (process.platform === "darwin") return "macos"; @@ -101,6 +105,23 @@ export async function checkForUpdates(): Promise { const metadata = JSON.parse(await requestText(metadataUrl)) as ReleaseMetadata; const artifact = selectArtifact(metadata); + if (isDevVersion(metadata.version) !== isDevVersion(currentVersion)) { + return { available: false, currentVersion, latestVersion: metadata.version }; + } + + if (isDevVersion(currentVersion)) { + if (!artifact || metadata.version === currentVersion) { + return { available: false, currentVersion, latestVersion: metadata.version }; + } + + return { + available: true, + currentVersion, + latestVersion: metadata.version, + artifact, + }; + } + if (!artifact || compareSemver(metadata.version, currentVersion) <= 0) { return { available: false, currentVersion, latestVersion: metadata.version }; } diff --git a/scripts/copy-releases.ts b/scripts/copy-releases.ts index 3df2718..3b0eeec 100644 --- a/scripts/copy-releases.ts +++ b/scripts/copy-releases.ts @@ -13,6 +13,8 @@ import { join } from "node:path"; import packageJson from "../package.json" with { type: "json" }; const { version } = packageJson; +const releaseVersion = process.env.TENSAMIN_RELEASE_VERSION || version; +const releaseTag = process.env.TENSAMIN_RELEASE_TAG || releaseVersion; const releasesDir = join("releases"); const releaseAssetBaseUrl = process.env.FORGEJO_RELEASE_ASSET_BASE_URL; @@ -64,7 +66,7 @@ const copyElectronArtifacts = () => { for (const file of readdirSync(electronReleaseDir)) { if (file.endsWith(".blockmap") || file.endsWith(".yml")) continue; - if (!file.includes(version)) continue; + if (!file.includes(version) && !file.includes(releaseVersion)) continue; const source = join(electronReleaseDir, file); if (!statSync(source).isFile()) continue; @@ -98,7 +100,7 @@ const artifacts = await Promise.all( await Bun.write( join(releasesDir, "electron-release-metadata.json"), - `${JSON.stringify({ version, tag: version, publishedAt: new Date().toISOString(), artifacts: artifacts.filter((artifact) => artifact.platform !== "android") }, null, 2)}\n`, + `${JSON.stringify({ version: releaseVersion, tag: releaseTag, publishedAt: new Date().toISOString(), artifacts: artifacts.filter((artifact) => artifact.platform !== "android") }, null, 2)}\n`, ); await Bun.write( join(releasesDir, "SHA256SUMS"),