From ad9f6942dc0da52e6e0a7fc50a17a967b8a64792 Mon Sep 17 00:00:00 2001 From: Jason <37859597+zachowj@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:05:25 -0800 Subject: [PATCH] fix: Add a version file for diagnostics --- .github/workflows/ci.yml | 2 ++ src/helpers/diagnostics.ts | 20 ++------------------ src/version.ts | 1 + 3 files changed, 5 insertions(+), 18 deletions(-) create mode 100644 src/version.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e07af1966e..c63919da6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,8 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} release-type: node bump-minor-pre-major: true + extra-files: ["src/version.ts"] + outputs: release_created: ${{ steps.release.outputs.release_created }} publish: diff --git a/src/helpers/diagnostics.ts b/src/helpers/diagnostics.ts index f3bc026117..f757f17771 100644 --- a/src/helpers/diagnostics.ts +++ b/src/helpers/diagnostics.ts @@ -4,10 +4,10 @@ import os from 'os'; import { RED } from '../globals'; import { homeAssistantConnections } from '../homeAssistant'; +import packageVersion from '../version'; let addonVersionCached: string | undefined; let isDockerCached: boolean | undefined; -let packageVersionCached: string | undefined; async function hasDockerEnv() { try { @@ -34,22 +34,6 @@ async function isRunningInDocker() { return isDockerCached; } -async function packageVersion() { - if (packageVersionCached) return packageVersionCached; - - try { - const pkg = await fs.readFile( - `${RED.settings.nodesDir}/node-red-contrib-home-assistant-websocket/package.json`, - 'utf8' - ); - packageVersionCached = JSON.parse(pkg).version; - } catch { - packageVersionCached = 'unknown'; - } - - return packageVersionCached; -} - interface HomeAssistantDiagnostic { serverId: string; version: string; @@ -126,7 +110,7 @@ async function getAddonVersion(): Promise { export async function getEnvironmentData() { const content = - `Version: ${await packageVersion()}\n` + + `Version: ${packageVersion}\n` + `\n` + `${getHomeAssistantVersionText()}` + `\n` + diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000000..8f31edaf51 --- /dev/null +++ b/src/version.ts @@ -0,0 +1 @@ +export default '0.0.0'; // x-release-please-version