Skip to content

Commit

Permalink
dynamically set protocol CLI version
Browse files Browse the repository at this point in the history
  • Loading branch information
dworthen committed Apr 8, 2024
1 parent 6c4a72e commit 4f37427
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gold-insects-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gov4git-desktop-app': patch
---

Dynamically set protocol CLI version
4 changes: 4 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extraResources:
to: 'migrations'
filter:
- '**/*'
- from: '.'
to: '.'
filter:
- 'package.json'
win:
executableName: Gov4Git
nsis:
Expand Down
14 changes: 14 additions & 0 deletions src/electron/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

import { toResolvedPath } from './lib/paths.js'
Expand All @@ -13,3 +14,16 @@ export const COMMUNITY_REPO_NAME =
process.env['GOV4GIT_COMMUNITY_REPO_NAME'] ?? 'gov4git-identity'

export const GITHUB_OAUTH_CLIENT_ID = '912c0ab18e0f0b4a1abe'

export let CLI_VERSION = ''

export function setCliVersion(isPackaged: boolean) {
const packageJsonPath = resolve(
isPackaged ? process.resourcesPath : process.cwd(),
'package.json',
)

const pkgJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))

CLI_VERSION = pkgJson['dependencies']['@gov4git/js-client']
}
9 changes: 9 additions & 0 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
import type { InvokeServiceProps } from '~/shared'

import {
CLI_VERSION,
COMMUNITY_REPO_NAME,
CONFIG_PATH,
DB_PATH,
GITHUB_OAUTH_CLIENT_ID,
setCliVersion,
} from './configs.js'
import { DB, loadDb } from './db/db.js'
import { migrateDb } from './db/migrate.js'
Expand All @@ -41,6 +43,13 @@ services.register('log', logService)
logService.info(`Gov4Git Version ${logService.getAppVersion()}`)

async function setup(): Promise<void> {
try {
logService.info(`Setting CLI Version for protocol`)
setCliVersion(app.isPackaged)
logService.info(`CLI_VERSION of protocol: ${CLI_VERSION}`)
} catch (ex) {
logService.error(`Failed to set CLI_VERSION`)
}
try {
logService.info(`Initializing DB: ${DB_PATH}`)
const db = loadDb(DB_PATH)
Expand Down
3 changes: 2 additions & 1 deletion src/electron/services/CommunityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'path'

import { AbstractCommunityService, Expand, ServiceResponse } from '~/shared'

import { CLI_VERSION } from '../configs.js'
import { DB } from '../db/db.js'
import {
communities,
Expand Down Expand Up @@ -428,7 +429,7 @@ ${user.memberPublicBranch}`
'--project',
`${org}/${repo}`,
'--release',
'v2.2.5',
`v${CLI_VERSION}`,
]
await this.govService.mustRun(command, undefined, true)

Expand Down

0 comments on commit 4f37427

Please sign in to comment.