Skip to content

Commit

Permalink
fix: Add a version file for diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Dec 13, 2023
1 parent 9f50a91 commit ad9f694
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 2 additions & 18 deletions src/helpers/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -126,7 +110,7 @@ async function getAddonVersion(): Promise<string> {

export async function getEnvironmentData() {
const content =
`Version: ${await packageVersion()}\n` +
`Version: ${packageVersion}\n` +
`\n` +
`${getHomeAssistantVersionText()}` +
`\n` +
Expand Down
1 change: 1 addition & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default '0.0.0'; // x-release-please-version

0 comments on commit ad9f694

Please sign in to comment.