(feat): add auto update for dev builds on dev builds
This commit is contained in:
parent
e146ae2710
commit
2440fedaad
4 changed files with 71 additions and 8 deletions
|
|
@ -104,6 +104,20 @@ jobs:
|
||||||
- name: Build packages
|
- name: Build packages
|
||||||
run: bun run 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
|
- name: Build Electron desktop
|
||||||
run: bun run build:desktop
|
run: bun run build:desktop
|
||||||
|
|
||||||
|
|
@ -143,9 +157,6 @@ jobs:
|
||||||
name: electron-desktop-linux
|
name: electron-desktop-linux
|
||||||
path: apps/electron/release/
|
path: apps/electron/release/
|
||||||
|
|
||||||
- name: Copy releases
|
|
||||||
run: bun --bun run copy-releases
|
|
||||||
|
|
||||||
- name: Read version and hash
|
- name: Read version and hash
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -156,6 +167,15 @@ jobs:
|
||||||
echo "tag=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT"
|
echo "tag=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT"
|
||||||
echo "title=${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
|
- name: Create pre-release and upload files
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ forgejo.token }}
|
TOKEN: ${{ forgejo.token }}
|
||||||
|
|
@ -239,6 +259,7 @@ jobs:
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = "releases/electron-release-metadata.json";
|
const path = "releases/electron-release-metadata.json";
|
||||||
const metadata = JSON.parse(fs.readFileSync(path, "utf8"));
|
const metadata = JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
|
metadata.version = process.env.TAG;
|
||||||
metadata.tag = process.env.TAG;
|
metadata.tag = process.env.TAG;
|
||||||
for (const artifact of metadata.artifacts || []) {
|
for (const artifact of metadata.artifacts || []) {
|
||||||
artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`;
|
artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`;
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,18 @@ jobs:
|
||||||
- name: Build packages
|
- name: Build packages
|
||||||
run: bun run 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
|
- name: Build Electron desktop
|
||||||
run: bun run build:desktop
|
run: bun run build:desktop
|
||||||
|
|
||||||
|
|
@ -141,9 +153,6 @@ jobs:
|
||||||
name: electron-desktop-linux
|
name: electron-desktop-linux
|
||||||
path: apps/electron/release/
|
path: apps/electron/release/
|
||||||
|
|
||||||
- name: Copy releases
|
|
||||||
run: bun --bun run copy-releases
|
|
||||||
|
|
||||||
- name: Read version
|
- name: Read version
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -151,6 +160,15 @@ jobs:
|
||||||
echo "version=$VERSION" >> "$FORGEJO_OUTPUT"
|
echo "version=$VERSION" >> "$FORGEJO_OUTPUT"
|
||||||
echo "tag=$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
|
- name: Create release and upload files
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ forgejo.token }}
|
TOKEN: ${{ forgejo.token }}
|
||||||
|
|
@ -198,6 +216,7 @@ jobs:
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = "releases/electron-release-metadata.json";
|
const path = "releases/electron-release-metadata.json";
|
||||||
const metadata = JSON.parse(fs.readFileSync(path, "utf8"));
|
const metadata = JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
|
metadata.version = process.env.TAG;
|
||||||
metadata.tag = process.env.TAG;
|
metadata.tag = process.env.TAG;
|
||||||
for (const artifact of metadata.artifacts || []) {
|
for (const artifact of metadata.artifacts || []) {
|
||||||
artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`;
|
artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ function compareSemver(left: string, right: string) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDevVersion(version: string) {
|
||||||
|
return /-dev[.-]/.test(version);
|
||||||
|
}
|
||||||
|
|
||||||
function platformName() {
|
function platformName() {
|
||||||
if (process.platform === "win32") return "windows";
|
if (process.platform === "win32") return "windows";
|
||||||
if (process.platform === "darwin") return "macos";
|
if (process.platform === "darwin") return "macos";
|
||||||
|
|
@ -101,6 +105,23 @@ export async function checkForUpdates(): Promise<UpdateCheckResult> {
|
||||||
const metadata = JSON.parse(await requestText(metadataUrl)) as ReleaseMetadata;
|
const metadata = JSON.parse(await requestText(metadataUrl)) as ReleaseMetadata;
|
||||||
const artifact = selectArtifact(metadata);
|
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) {
|
if (!artifact || compareSemver(metadata.version, currentVersion) <= 0) {
|
||||||
return { available: false, currentVersion, latestVersion: metadata.version };
|
return { available: false, currentVersion, latestVersion: metadata.version };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import { join } from "node:path";
|
||||||
import packageJson from "../package.json" with { type: "json" };
|
import packageJson from "../package.json" with { type: "json" };
|
||||||
|
|
||||||
const { version } = packageJson;
|
const { version } = packageJson;
|
||||||
|
const releaseVersion = process.env.TENSAMIN_RELEASE_VERSION || version;
|
||||||
|
const releaseTag = process.env.TENSAMIN_RELEASE_TAG || releaseVersion;
|
||||||
const releasesDir = join("releases");
|
const releasesDir = join("releases");
|
||||||
const releaseAssetBaseUrl = process.env.FORGEJO_RELEASE_ASSET_BASE_URL;
|
const releaseAssetBaseUrl = process.env.FORGEJO_RELEASE_ASSET_BASE_URL;
|
||||||
|
|
||||||
|
|
@ -64,7 +66,7 @@ const copyElectronArtifacts = () => {
|
||||||
|
|
||||||
for (const file of readdirSync(electronReleaseDir)) {
|
for (const file of readdirSync(electronReleaseDir)) {
|
||||||
if (file.endsWith(".blockmap") || file.endsWith(".yml")) continue;
|
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);
|
const source = join(electronReleaseDir, file);
|
||||||
if (!statSync(source).isFile()) continue;
|
if (!statSync(source).isFile()) continue;
|
||||||
|
|
@ -98,7 +100,7 @@ const artifacts = await Promise.all(
|
||||||
|
|
||||||
await Bun.write(
|
await Bun.write(
|
||||||
join(releasesDir, "electron-release-metadata.json"),
|
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(
|
await Bun.write(
|
||||||
join(releasesDir, "SHA256SUMS"),
|
join(releasesDir, "SHA256SUMS"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue