feat(jdbc): show plugin update notice
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
export function augmentLatestJsonWithJdbcPlugin({ latestJson, jdbcVersion, protocolVersion, url }) {
|
||||
const data = JSON.parse(latestJson);
|
||||
data.jdbc_plugin = {
|
||||
version: jdbcVersion,
|
||||
protocol_version: Number(protocolVersion),
|
||||
url,
|
||||
};
|
||||
return `${JSON.stringify(data, null, 2)}\n`;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const [latestJsonPath, jdbcVersion, protocolVersion, url] = process.argv.slice(2);
|
||||
if (!latestJsonPath || !jdbcVersion || !protocolVersion || !url) {
|
||||
console.error("Usage: augment-latest-json-jdbc-plugin.mjs <latest.json> <jdbc-version> <protocol-version> <url>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const updated = augmentLatestJsonWithJdbcPlugin({
|
||||
latestJson: readFileSync(latestJsonPath, "utf8"),
|
||||
jdbcVersion,
|
||||
protocolVersion,
|
||||
url,
|
||||
});
|
||||
writeFileSync(latestJsonPath, updated);
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
main();
|
||||
}
|
||||
@@ -240,6 +240,26 @@ jobs:
|
||||
--repo "${GITHUB_REPOSITORY}" \
|
||||
--clobber
|
||||
|
||||
- name: Add JDBC plugin metadata to latest.json
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p "$RUNNER_TEMP/latest-json"
|
||||
gh release download "${GITHUB_REF_NAME}" \
|
||||
--repo "${GITHUB_REPOSITORY}" \
|
||||
--pattern latest.json \
|
||||
--dir "$RUNNER_TEMP/latest-json"
|
||||
node .github/scripts/augment-latest-json-jdbc-plugin.mjs \
|
||||
"$RUNNER_TEMP/latest-json/latest.json" \
|
||||
"${{ steps.jdbc-plugin.outputs.version }}" \
|
||||
"1" \
|
||||
"https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip"
|
||||
gh release upload "${GITHUB_REF_NAME}" \
|
||||
"$RUNNER_TEMP/latest-json/latest.json" \
|
||||
--repo "${GITHUB_REPOSITORY}" \
|
||||
--clobber
|
||||
|
||||
publish:
|
||||
needs: [build, docker-manifest, jdbc-plugin]
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -11,7 +11,7 @@ import DriverInstallProgressCircle from "@/components/config/DriverInstallProgre
|
||||
import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { isTauriRuntime } from "@/lib/tauriRuntime";
|
||||
import { countAvailableAgentDriverUpdates } from "@/lib/agentDriverUpdateBadge";
|
||||
import { countAvailableDriverUpdates } from "@/lib/agentDriverUpdateBadge";
|
||||
import type { JdbcDriverInfo, JdbcPluginStatus } from "@/types/database";
|
||||
import * as api from "@/lib/api";
|
||||
import type { AgentDriverInfo, JavaRuntimeConfig } from "@/lib/api";
|
||||
@@ -84,7 +84,11 @@ const updatableCount = computed(() => drivers.value.filter((d) => d.update_avail
|
||||
|
||||
function updateAgentDrivers(nextDrivers: AgentDriverInfo[]) {
|
||||
drivers.value = nextDrivers;
|
||||
emit("update-count-change", countAvailableAgentDriverUpdates(nextDrivers));
|
||||
emitDriverUpdateCount();
|
||||
}
|
||||
|
||||
function emitDriverUpdateCount() {
|
||||
emit("update-count-change", countAvailableDriverUpdates(drivers.value, jdbcPluginStatus.value));
|
||||
}
|
||||
|
||||
function isDriverProgressActive(dbType: string): boolean {
|
||||
@@ -299,6 +303,7 @@ async function loadJdbcPluginStatus() {
|
||||
if (isWeb) return;
|
||||
try {
|
||||
jdbcPluginStatus.value = await api.jdbcPluginStatus();
|
||||
emitDriverUpdateCount();
|
||||
} catch (e: any) {
|
||||
toast(String(e?.message || e), 5000);
|
||||
}
|
||||
@@ -309,6 +314,7 @@ async function installJdbcPlugin() {
|
||||
isInstallingJdbcPlugin.value = true;
|
||||
try {
|
||||
jdbcPluginStatus.value = await api.installJdbcPlugin();
|
||||
emitDriverUpdateCount();
|
||||
toast(t("settings.jdbcPluginInstallSuccess"));
|
||||
await loadJdbcDrivers();
|
||||
} catch (e: any) {
|
||||
@@ -330,6 +336,7 @@ async function installJdbcPluginLocal() {
|
||||
isInstallingJdbcPlugin.value = true;
|
||||
try {
|
||||
jdbcPluginStatus.value = await api.installJdbcPluginLocal(selected);
|
||||
emitDriverUpdateCount();
|
||||
toast(t("settings.jdbcPluginInstallSuccess"));
|
||||
await loadJdbcDrivers();
|
||||
} catch (e: any) {
|
||||
@@ -344,6 +351,7 @@ async function uninstallJdbcPlugin() {
|
||||
isUninstallingJdbcPlugin.value = true;
|
||||
try {
|
||||
jdbcPluginStatus.value = await api.uninstallJdbcPlugin();
|
||||
emitDriverUpdateCount();
|
||||
toast(t("settings.jdbcPluginUninstallSuccess"));
|
||||
await loadJdbcDrivers();
|
||||
} catch (e: any) {
|
||||
@@ -702,6 +710,20 @@ onUnmounted(() => {
|
||||
: t("settings.jdbcPluginIncompatible")
|
||||
}}
|
||||
</span>
|
||||
<span
|
||||
v-if="jdbcPluginStatus?.installed && jdbcPluginStatus.update_available"
|
||||
class="rounded-full bg-amber-500/15 px-2 py-0.5 text-[11px] text-amber-600"
|
||||
>→ v{{ jdbcPluginStatus.latest_version }}</span
|
||||
>
|
||||
<Button
|
||||
v-if="jdbcPluginStatus?.installed && jdbcPluginStatus.update_available"
|
||||
type="button"
|
||||
variant="outline"
|
||||
:disabled="isInstallingJdbcPlugin"
|
||||
@click="installJdbcPlugin"
|
||||
>
|
||||
{{ isInstallingJdbcPlugin ? t("common.loading") : t("settings.jdbcPluginUpdate") }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="jdbcPluginStatus?.installed"
|
||||
type="button"
|
||||
|
||||
@@ -1154,6 +1154,7 @@ export default {
|
||||
jdbcPlugin: "DBX JDBC plugin",
|
||||
jdbcPluginInstall: "Install JDBC plugin",
|
||||
jdbcPluginInstallSuccess: "JDBC plugin installed",
|
||||
jdbcPluginUpdate: "Update",
|
||||
jdbcPluginUninstall: "Uninstall",
|
||||
jdbcPluginUninstallSuccess: "JDBC plugin uninstalled",
|
||||
jdbcPluginInstalled: "Installed: v{version}",
|
||||
|
||||
@@ -1059,6 +1059,7 @@ export default {
|
||||
jdbcPlugin: "Plugin JDBC de DBX",
|
||||
jdbcPluginInstall: "Instalar plugin JDBC",
|
||||
jdbcPluginInstallSuccess: "Plugin JDBC instalado",
|
||||
jdbcPluginUpdate: "Actualizar",
|
||||
jdbcPluginUninstall: "Desinstalar",
|
||||
jdbcPluginUninstallSuccess: "Plugin JDBC desinstalado",
|
||||
jdbcPluginInstalled: "Instalado: v{version}",
|
||||
|
||||
@@ -1131,6 +1131,7 @@ export default {
|
||||
jdbcPlugin: "DBX JDBC 插件",
|
||||
jdbcPluginInstall: "安装 JDBC 插件",
|
||||
jdbcPluginInstallSuccess: "JDBC 插件已安装",
|
||||
jdbcPluginUpdate: "更新",
|
||||
jdbcPluginUninstall: "卸载",
|
||||
jdbcPluginUninstallSuccess: "JDBC 插件已卸载",
|
||||
jdbcPluginInstalled: "已安装:v{version}",
|
||||
|
||||
@@ -5,3 +5,14 @@ export interface AgentDriverUpdateBadgeState {
|
||||
export function countAvailableAgentDriverUpdates(drivers: readonly AgentDriverUpdateBadgeState[]): number {
|
||||
return drivers.filter((driver) => driver.update_available).length;
|
||||
}
|
||||
|
||||
export interface JdbcPluginUpdateBadgeState {
|
||||
update_available?: boolean | null;
|
||||
}
|
||||
|
||||
export function countAvailableDriverUpdates(
|
||||
drivers: readonly AgentDriverUpdateBadgeState[],
|
||||
jdbcPlugin?: JdbcPluginUpdateBadgeState | null,
|
||||
): number {
|
||||
return countAvailableAgentDriverUpdates(drivers) + (jdbcPlugin?.update_available ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -121,19 +121,28 @@ export async function deleteJdbcDriver(_path: string): Promise<JdbcDriverInfo[]>
|
||||
}
|
||||
|
||||
export async function jdbcPluginStatus(): Promise<JdbcPluginStatus> {
|
||||
return { installed: false, version: null, protocol_version: null, compatible: true, path: "" };
|
||||
return {
|
||||
installed: false,
|
||||
version: null,
|
||||
protocol_version: null,
|
||||
compatible: true,
|
||||
latest_version: null,
|
||||
latest_protocol_version: null,
|
||||
update_available: false,
|
||||
path: "",
|
||||
};
|
||||
}
|
||||
|
||||
export async function installJdbcPlugin(): Promise<JdbcPluginStatus> {
|
||||
return { installed: false, version: null, protocol_version: null, compatible: true, path: "" };
|
||||
return jdbcPluginStatus();
|
||||
}
|
||||
|
||||
export async function installJdbcPluginLocal(_path: string): Promise<JdbcPluginStatus> {
|
||||
return { installed: false, version: null, protocol_version: null, compatible: true, path: "" };
|
||||
return jdbcPluginStatus();
|
||||
}
|
||||
|
||||
export async function uninstallJdbcPlugin(): Promise<JdbcPluginStatus> {
|
||||
return { installed: false, version: null, protocol_version: null, compatible: true, path: "" };
|
||||
return jdbcPluginStatus();
|
||||
}
|
||||
|
||||
export async function listInstalledAgentsLocal(): Promise<AgentDriverInfo[]> {
|
||||
|
||||
@@ -110,6 +110,9 @@ export interface JdbcPluginStatus {
|
||||
version?: string | null;
|
||||
protocol_version?: number | null;
|
||||
compatible: boolean;
|
||||
latest_version?: string | null;
|
||||
latest_protocol_version?: number | null;
|
||||
update_available: boolean;
|
||||
path: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,19 @@ pub struct TauriRelease {
|
||||
pub version: String,
|
||||
#[serde(default)]
|
||||
pub notes: Option<String>,
|
||||
#[serde(default)]
|
||||
pub jdbc_plugin: Option<JdbcPluginLatest>,
|
||||
#[serde(skip)]
|
||||
pub github: Option<GithubReleaseMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct JdbcPluginLatest {
|
||||
pub version: String,
|
||||
pub protocol_version: u32,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct GithubReleaseMetadata {
|
||||
pub name: Option<String>,
|
||||
@@ -148,11 +157,34 @@ mod tests {
|
||||
assert!(!is_newer_version("0.1.9", "0.2.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_jdbc_plugin_metadata_from_latest_json() {
|
||||
let release: TauriRelease = serde_json::from_str(
|
||||
r#"{
|
||||
"version": "0.5.12",
|
||||
"jdbc_plugin": {
|
||||
"version": "0.1.3",
|
||||
"protocol_version": 1,
|
||||
"url": "https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip"
|
||||
},
|
||||
"platforms": {}
|
||||
}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let jdbc = release.jdbc_plugin.unwrap();
|
||||
|
||||
assert_eq!(jdbc.version, "0.1.3");
|
||||
assert_eq!(jdbc.protocol_version, 1);
|
||||
assert_eq!(jdbc.url, "https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_info_prefers_github_release_metadata() {
|
||||
let release = TauriRelease {
|
||||
version: "0.5.3".to_string(),
|
||||
notes: Some("See the assets below to download and install.".to_string()),
|
||||
jdbc_plugin: None,
|
||||
github: Some(GithubReleaseMetadata {
|
||||
name: Some("DBX v0.5.3".to_string()),
|
||||
html_url: Some("https://github.com/t8y2/dbx/releases/tag/v0.5.3".to_string()),
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { countAvailableAgentDriverUpdates } from "../../apps/desktop/src/lib/agentDriverUpdateBadge.ts";
|
||||
import {
|
||||
countAvailableAgentDriverUpdates,
|
||||
countAvailableDriverUpdates,
|
||||
} from "../../apps/desktop/src/lib/agentDriverUpdateBadge.ts";
|
||||
|
||||
test("returns zero when there are no available agent driver updates", () => {
|
||||
assert.equal(countAvailableAgentDriverUpdates([]), 0);
|
||||
@@ -18,3 +21,10 @@ test("counts available agent driver updates", () => {
|
||||
2,
|
||||
);
|
||||
});
|
||||
|
||||
test("counts JDBC plugin update alongside agent driver updates", () => {
|
||||
assert.equal(
|
||||
countAvailableDriverUpdates([{ update_available: true }, { update_available: false }], { update_available: true }),
|
||||
2,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import { strict as assert } from "node:assert";
|
||||
import test from "node:test";
|
||||
import { evaluateJdbcPluginReleaseBump } from "../../.github/scripts/bump-jdbc-plugin-version.mjs";
|
||||
import { evaluateJdbcPluginVersionChange } from "../../.github/scripts/check-jdbc-plugin-version.mjs";
|
||||
import { augmentLatestJsonWithJdbcPlugin } from "../../.github/scripts/augment-latest-json-jdbc-plugin.mjs";
|
||||
|
||||
test("allows JDBC plugin runtime changes without a manual version bump before release", () => {
|
||||
assert.deepEqual(
|
||||
@@ -92,3 +93,30 @@ test("auto bump refuses mismatched JDBC plugin source versions", () => {
|
||||
/JDBC plugin version mismatch/,
|
||||
);
|
||||
});
|
||||
|
||||
test("adds JDBC plugin metadata to latest.json without disturbing updater fields", () => {
|
||||
const result = augmentLatestJsonWithJdbcPlugin({
|
||||
latestJson: JSON.stringify({
|
||||
version: "0.5.12",
|
||||
notes: "Release notes",
|
||||
platforms: {
|
||||
"darwin-aarch64": {
|
||||
signature: "sig",
|
||||
url: "https://example.com/app.dmg",
|
||||
},
|
||||
},
|
||||
}),
|
||||
jdbcVersion: "0.1.3",
|
||||
protocolVersion: 1,
|
||||
url: "https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip",
|
||||
});
|
||||
const parsed = JSON.parse(result);
|
||||
|
||||
assert.equal(parsed.version, "0.5.12");
|
||||
assert.equal(parsed.platforms["darwin-aarch64"].signature, "sig");
|
||||
assert.deepEqual(parsed.jdbc_plugin, {
|
||||
version: "0.1.3",
|
||||
protocol_version: 1,
|
||||
url: "https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::sync::Arc;
|
||||
use tauri::State;
|
||||
|
||||
use dbx_core::plugins::{InstalledPlugin, PluginManifest, SUPPORTED_PLUGIN_PROTOCOL_VERSION};
|
||||
use dbx_core::update::{fetch_latest_release, is_newer_version, JdbcPluginLatest};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::connection::AppState;
|
||||
@@ -28,12 +29,15 @@ pub struct JdbcPluginStatus {
|
||||
pub version: Option<String>,
|
||||
pub protocol_version: Option<u32>,
|
||||
pub compatible: bool,
|
||||
pub latest_version: Option<String>,
|
||||
pub latest_protocol_version: Option<u32>,
|
||||
pub update_available: bool,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn jdbc_plugin_status(state: State<'_, Arc<AppState>>) -> Result<JdbcPluginStatus, String> {
|
||||
jdbc_plugin_status_from_state(&state)
|
||||
jdbc_plugin_status_from_state(&state).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -41,7 +45,7 @@ pub async fn install_jdbc_plugin(state: State<'_, Arc<AppState>>) -> Result<Jdbc
|
||||
let bytes = download_jdbc_plugin_zip().await?;
|
||||
let plugin_dir = state.plugins.root_dir().join("jdbc");
|
||||
install_jdbc_plugin_zip(&bytes, &plugin_dir)?;
|
||||
jdbc_plugin_status_from_state(&state)
|
||||
jdbc_plugin_status_from_state(&state).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -52,7 +56,7 @@ pub async fn install_jdbc_plugin_local(
|
||||
let bytes = std::fs::read(&path).map_err(|e| format!("Failed to read file: {e}"))?;
|
||||
let plugin_dir = state.plugins.root_dir().join("jdbc");
|
||||
install_jdbc_plugin_zip(&bytes, &plugin_dir)?;
|
||||
jdbc_plugin_status_from_state(&state)
|
||||
jdbc_plugin_status_from_state(&state).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -69,7 +73,7 @@ pub async fn uninstall_jdbc_plugin(state: State<'_, Arc<AppState>>) -> Result<Jd
|
||||
std::fs::remove_file(path).map_err(|err| err.to_string())?;
|
||||
}
|
||||
}
|
||||
jdbc_plugin_status_from_state(&state)
|
||||
jdbc_plugin_status_from_state(&state).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -124,7 +128,7 @@ fn jdbc_drivers_dir(state: &AppState) -> std::path::PathBuf {
|
||||
state.plugins.root_dir().join("jdbc").join("drivers")
|
||||
}
|
||||
|
||||
fn jdbc_plugin_status_from_state(state: &AppState) -> Result<JdbcPluginStatus, String> {
|
||||
async fn jdbc_plugin_status_from_state(state: &AppState) -> Result<JdbcPluginStatus, String> {
|
||||
let plugin_dir = state.plugins.root_dir().join("jdbc");
|
||||
let manifest_path = plugin_dir.join("manifest.json");
|
||||
let manifest = match std::fs::read_to_string(&manifest_path) {
|
||||
@@ -139,15 +143,30 @@ fn jdbc_plugin_status_from_state(state: &AppState) -> Result<JdbcPluginStatus, S
|
||||
Some(manifest) => manifest.protocol_version == SUPPORTED_PLUGIN_PROTOCOL_VERSION,
|
||||
None => true,
|
||||
};
|
||||
let latest = latest_jdbc_plugin().await;
|
||||
let latest_version = latest.as_ref().map(|plugin| plugin.version.clone());
|
||||
let latest_protocol_version = latest.as_ref().map(|plugin| plugin.protocol_version);
|
||||
let update_available = match (version.as_deref(), latest.as_ref()) {
|
||||
(Some(current), Some(latest)) if manifest.is_some() => is_newer_version(&latest.version, current),
|
||||
(None, Some(_)) if manifest.is_some() => true,
|
||||
_ => false,
|
||||
};
|
||||
Ok(JdbcPluginStatus {
|
||||
installed: manifest.is_some(),
|
||||
version,
|
||||
protocol_version,
|
||||
compatible,
|
||||
latest_version,
|
||||
latest_protocol_version,
|
||||
update_available,
|
||||
path: plugin_dir.to_string_lossy().to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn latest_jdbc_plugin() -> Option<JdbcPluginLatest> {
|
||||
fetch_latest_release().await.ok().and_then(|release| release.jdbc_plugin)
|
||||
}
|
||||
|
||||
async fn download_jdbc_plugin_zip() -> Result<Vec<u8>, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(60))
|
||||
|
||||
Reference in New Issue
Block a user