mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-20 00:17:44 +00:00
fix(jdbc): stabilize plugin release versioning
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const POM_PATH = "plugins/jdbc/pom.xml";
|
||||
const MANIFEST_PATH = "plugins/jdbc/manifest.json";
|
||||
|
||||
function firstProjectVersion(pomXml) {
|
||||
const match = pomXml.match(/<project[\s\S]*?<version>([^<]+)<\/version>/);
|
||||
return match?.[1]?.trim() ?? "";
|
||||
}
|
||||
|
||||
function manifestVersion(manifestJson) {
|
||||
return JSON.parse(manifestJson).version ?? "";
|
||||
}
|
||||
|
||||
function isRelevantJdbcPluginChange(file) {
|
||||
if (!file.startsWith("plugins/jdbc/")) return false;
|
||||
if (file.startsWith("plugins/jdbc/dist/") || file.startsWith("plugins/jdbc/target/")) return false;
|
||||
if (file === "plugins/jdbc/README.md" || file === "plugins/jdbc/package.sh") return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function evaluateJdbcPluginVersionChange({
|
||||
changedFiles,
|
||||
basePomVersion,
|
||||
baseManifestVersion,
|
||||
headPomVersion,
|
||||
headManifestVersion,
|
||||
}) {
|
||||
const errors = [];
|
||||
if (headPomVersion !== headManifestVersion) {
|
||||
errors.push(`JDBC plugin version mismatch: pom.xml is ${headPomVersion} but manifest.json is ${headManifestVersion}.`);
|
||||
return errors;
|
||||
}
|
||||
|
||||
const baseVersion = basePomVersion || baseManifestVersion;
|
||||
const relevantChanged = changedFiles.some(isRelevantJdbcPluginChange);
|
||||
if (relevantChanged && headPomVersion === baseVersion) {
|
||||
errors.push(
|
||||
`JDBC plugin files changed, but the plugin version is still ${headPomVersion}. Bump plugins/jdbc/pom.xml and plugins/jdbc/manifest.json.`,
|
||||
);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
function git(args) {
|
||||
return execFileSync("git", args, { encoding: "utf8" }).trim();
|
||||
}
|
||||
|
||||
function readFileAt(ref, path) {
|
||||
return git(["show", `${ref}:${path}`]);
|
||||
}
|
||||
|
||||
function main() {
|
||||
const [baseRef = "HEAD~1", headRef = "HEAD"] = process.argv.slice(2);
|
||||
const changedFiles = git(["diff", "--name-only", baseRef, headRef]).split("\n").filter(Boolean);
|
||||
const basePomVersion = firstProjectVersion(readFileAt(baseRef, POM_PATH));
|
||||
const baseManifestVersion = manifestVersion(readFileAt(baseRef, MANIFEST_PATH));
|
||||
const headPomVersion = firstProjectVersion(readFileAt(headRef, POM_PATH));
|
||||
const headManifestVersion = manifestVersion(readFileAt(headRef, MANIFEST_PATH));
|
||||
const errors = evaluateJdbcPluginVersionChange({
|
||||
changedFiles,
|
||||
basePomVersion,
|
||||
baseManifestVersion,
|
||||
headPomVersion,
|
||||
headManifestVersion,
|
||||
});
|
||||
|
||||
if (errors.length) {
|
||||
for (const error of errors) {
|
||||
console.error(`::error::${error}`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`JDBC plugin version check passed (${headPomVersion}).`);
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
main();
|
||||
}
|
||||
@@ -11,6 +11,8 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
@@ -65,5 +67,14 @@ jobs:
|
||||
- name: Cargo check
|
||||
run: cargo check --workspace --locked
|
||||
|
||||
- name: JDBC plugin version guard
|
||||
env:
|
||||
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
|
||||
run: |
|
||||
if [ -z "$BASE_SHA" ] || echo "$BASE_SHA" | grep -Eq '^0+$'; then
|
||||
BASE_SHA="HEAD~1"
|
||||
fi
|
||||
node .github/scripts/check-jdbc-plugin-version.mjs "$BASE_SHA" HEAD
|
||||
|
||||
- name: JDBC plugin package check
|
||||
run: ./plugins/jdbc/package.sh
|
||||
|
||||
@@ -189,6 +189,7 @@ jobs:
|
||||
run: |
|
||||
gh release upload "${GITHUB_REF_NAME}" \
|
||||
"plugins/jdbc/dist/dbx-jdbc-plugin-${{ steps.jdbc-plugin.outputs.version }}.zip" \
|
||||
"plugins/jdbc/dist/dbx-jdbc-plugin-latest.zip" \
|
||||
--repo "${GITHUB_REPOSITORY}" \
|
||||
--clobber
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ Thumbs.db
|
||||
# GitHub (keep workflows)
|
||||
.github/*
|
||||
!.github/workflows/
|
||||
!.github/scripts/
|
||||
!.github/ISSUE_TEMPLATE/
|
||||
|
||||
# Env
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import test from "node:test";
|
||||
import { evaluateJdbcPluginVersionChange } from "../../.github/scripts/check-jdbc-plugin-version.mjs";
|
||||
|
||||
test("requires a JDBC plugin version bump when runtime files change", () => {
|
||||
assert.deepEqual(
|
||||
evaluateJdbcPluginVersionChange({
|
||||
changedFiles: ["plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java"],
|
||||
basePomVersion: "0.1.1",
|
||||
baseManifestVersion: "0.1.1",
|
||||
headPomVersion: "0.1.1",
|
||||
headManifestVersion: "0.1.1",
|
||||
}),
|
||||
["JDBC plugin files changed, but the plugin version is still 0.1.1. Bump plugins/jdbc/pom.xml and plugins/jdbc/manifest.json."],
|
||||
);
|
||||
});
|
||||
|
||||
test("allows JDBC plugin runtime changes when pom and manifest versions are bumped together", () => {
|
||||
assert.deepEqual(
|
||||
evaluateJdbcPluginVersionChange({
|
||||
changedFiles: ["plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java"],
|
||||
basePomVersion: "0.1.1",
|
||||
baseManifestVersion: "0.1.1",
|
||||
headPomVersion: "0.1.2",
|
||||
headManifestVersion: "0.1.2",
|
||||
}),
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test("does not require a JDBC plugin version bump for docs or release packaging changes", () => {
|
||||
assert.deepEqual(
|
||||
evaluateJdbcPluginVersionChange({
|
||||
changedFiles: ["plugins/jdbc/README.md", "plugins/jdbc/package.sh"],
|
||||
basePomVersion: "0.1.1",
|
||||
baseManifestVersion: "0.1.1",
|
||||
headPomVersion: "0.1.1",
|
||||
headManifestVersion: "0.1.1",
|
||||
}),
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test("requires JDBC plugin pom and manifest versions to match", () => {
|
||||
assert.deepEqual(
|
||||
evaluateJdbcPluginVersionChange({
|
||||
changedFiles: ["plugins/jdbc/manifest.json"],
|
||||
basePomVersion: "0.1.1",
|
||||
baseManifestVersion: "0.1.1",
|
||||
headPomVersion: "0.1.2",
|
||||
headManifestVersion: "0.1.1",
|
||||
}),
|
||||
["JDBC plugin version mismatch: pom.xml is 0.1.2 but manifest.json is 0.1.1."],
|
||||
);
|
||||
});
|
||||
@@ -17,6 +17,7 @@ cp target/dbx-jdbc-plugin-*-all.jar lib/dbx-jdbc-plugin.jar
|
||||
```
|
||||
|
||||
The package version follows the JDBC plugin version in `pom.xml` and `manifest.json`.
|
||||
The package script writes both `dbx-jdbc-plugin-<version>.zip` and `dbx-jdbc-plugin-latest.zip`.
|
||||
|
||||
## Install for local DBX
|
||||
|
||||
|
||||
@@ -5,11 +5,12 @@ ROOT="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
VERSION="$(grep -m1 '<version>' "$ROOT/pom.xml" | sed -E 's/.*<version>([^<]+)<.*/\1/')"
|
||||
PACKAGE_DIR="$ROOT/dist/dbx-jdbc-plugin-$VERSION"
|
||||
ZIP_PATH="$ROOT/dist/dbx-jdbc-plugin-$VERSION.zip"
|
||||
LATEST_ZIP_PATH="$ROOT/dist/dbx-jdbc-plugin-latest.zip"
|
||||
|
||||
cd "$ROOT"
|
||||
mvn -q -DskipTests package
|
||||
|
||||
rm -rf "$PACKAGE_DIR" "$ZIP_PATH"
|
||||
rm -rf "$PACKAGE_DIR" "$ZIP_PATH" "$LATEST_ZIP_PATH"
|
||||
mkdir -p "$PACKAGE_DIR/bin" "$PACKAGE_DIR/lib"
|
||||
cp "$ROOT/manifest.json" "$PACKAGE_DIR/manifest.json"
|
||||
cp "$ROOT/bin/dbx-jdbc-plugin" "$PACKAGE_DIR/bin/dbx-jdbc-plugin"
|
||||
@@ -18,4 +19,6 @@ cp "$ROOT/target/dbx-jdbc-plugin-$VERSION-all.jar" "$PACKAGE_DIR/lib/dbx-jdbc-pl
|
||||
chmod +x "$PACKAGE_DIR/bin/dbx-jdbc-plugin"
|
||||
|
||||
(cd "$ROOT/dist" && zip -qr "dbx-jdbc-plugin-$VERSION.zip" "dbx-jdbc-plugin-$VERSION")
|
||||
cp "$ZIP_PATH" "$LATEST_ZIP_PATH"
|
||||
echo "$ZIP_PATH"
|
||||
echo "$LATEST_ZIP_PATH"
|
||||
|
||||
@@ -6,8 +6,9 @@ use serde::Serialize;
|
||||
|
||||
use super::connection::AppState;
|
||||
|
||||
const JDBC_PLUGIN_DOWNLOAD_URL: &str = "https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-0.1.1.zip";
|
||||
const JDBC_PLUGIN_R2_PATH: &str = "releases/latest/dbx-jdbc-plugin-0.1.1.zip";
|
||||
const JDBC_PLUGIN_DOWNLOAD_URL: &str =
|
||||
"https://github.com/t8y2/dbx/releases/latest/download/dbx-jdbc-plugin-latest.zip";
|
||||
const JDBC_PLUGIN_R2_PATH: &str = "releases/latest/dbx-jdbc-plugin-latest.zip";
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_plugins(state: State<'_, Arc<AppState>>) -> Result<Vec<InstalledPlugin>, String> {
|
||||
|
||||
Reference in New Issue
Block a user