Skip to content

Commit 2a236d6

Browse files
authored
Merge pull request #2774 from UltimateHackingKeyboard/feat-agent-fw-versions-metadata
feat: add Agent and firmware metadata to user configuration
2 parents 3543f85 + d1b7f21 commit 2a236d6

32 files changed

+217
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "8.0.1",
77
"firmwareVersion": "15.3.0",
88
"deviceProtocolVersion": "4.15.0",
9-
"userConfigVersion": "12.1.0",
9+
"userConfigVersion": "13.0.0",
1010
"hardwareConfigVersion": "1.0.0",
1111
"description": "Agent is the configuration application of the Ultimate Hacking Keyboard.",
1212
"repository": {

packages/uhk-common/scripts/generate-versions.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { exec } from 'node:child_process';
12
import fs from 'node:fs/promises';
23
import path from 'node:path';
4+
import process from 'node:process';
35

6+
import getGithubTag from '../../../scripts/get-github-tag.mjs';
47
const rootPackageJsonPath = path.join(import.meta.dirname, '../../../package.json');
58
const packageJsonContent = await fs.readFile(rootPackageJsonPath, { encoding: 'utf8' });
69
const packageJson = JSON.parse(packageJsonContent)
@@ -9,6 +12,8 @@ const versionsFileContent = `\
912
import { VersionInformation } from '../models/version-information.js';
1013
1114
export const VERSIONS: VersionInformation = {
15+
agentRepo: ${writeValue(getGitRepo())},
16+
agentTag: ${writeValue(await getGitTag())},
1217
version: ${writeValue(packageJson.version)},
1318
firmwareVersion: ${writeValue(packageJson.firmwareVersion)},
1419
deviceProtocolVersion: ${writeValue(packageJson.deviceProtocolVersion)},
@@ -17,6 +22,11 @@ export const VERSIONS: VersionInformation = {
1722
}
1823
`
1924

25+
if (process.env.CI) {
26+
console.log('versions.ts file content:')
27+
console.log(versionsFileContent);
28+
}
29+
2030
const versionsFilePath = path.join(import.meta.dirname, '../src/util/versions.ts')
2131
await fs.writeFile(versionsFilePath, versionsFileContent, { encoding: 'utf8' });
2232

@@ -31,3 +41,50 @@ function writeValue(value) {
3141

3242
return `'${value}'`;
3343
}
44+
45+
function getGitRepo() {
46+
if (process.env.CI) {
47+
return process.env.GITHUB_REPOSITORY;
48+
}
49+
50+
return 'UltimateHackingKeyboard/agent'
51+
}
52+
53+
async function getGitTag() {
54+
if (process.env.CI) {
55+
const tag = getGithubTag();
56+
if (tag) {
57+
return tag;
58+
}
59+
}
60+
61+
try {
62+
const tagResponse = await execAsync('git describe --exact-match --tags')
63+
64+
if (tagResponse.stdout) {
65+
return tagResponse.stdout.trim()
66+
}
67+
} catch (error) {
68+
console.log('No Agent git tag fallback to sha')
69+
}
70+
71+
// fallback to git sha
72+
const shaResponse = await execAsync('git rev-parse --verify --short HEAD')
73+
74+
return shaResponse.stdout.trim()
75+
}
76+
77+
async function execAsync(command) {
78+
return new Promise((resolve, reject) => {
79+
exec(command, (error, stdout, stderr) => {
80+
if (error) {
81+
return reject(error);
82+
}
83+
84+
resolve({
85+
stdout,
86+
stderr,
87+
});
88+
})
89+
})
90+
}

packages/uhk-common/src/config-serializer/config-items/host-connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class HostConnection {
7474
case 9:
7575
case 11:
7676
case 12:
77+
case 13:
7778
return this.fromJsonObjectV9(jsonObject, serialisationInfo);
7879

7980
default:
@@ -89,6 +90,7 @@ export class HostConnection {
8990
case 9:
9091
case 11:
9192
case 12:
93+
case 13:
9294
return this.fromJsonBinaryV9(buffer, serialisationInfo);
9395

9496
default:

packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class Helper {
4040
case 9:
4141
case 11:
4242
case 12:
43+
case 13:
4344
return this.fromUhkBufferV1(buffer, macros, serialisationInfo);
4445

4546
default:
@@ -128,6 +129,7 @@ export class Helper {
128129
case 9:
129130
case 11:
130131
case 12:
132+
case 13:
131133
return this.fromJSONObjectV1(keyAction, macros, serialisationInfo);
132134

133135
default:

packages/uhk-common/src/config-serializer/config-items/key-action/keystroke-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class KeystrokeAction extends KeyAction {
8585
case 9:
8686
case 11:
8787
case 12:
88+
case 13:
8889
this.fromJsonObjectV6(jsonObject, serialisationInfo);
8990
break;
9091

@@ -111,6 +112,7 @@ export class KeystrokeAction extends KeyAction {
111112
case 9:
112113
case 11:
113114
case 12:
115+
case 13:
114116
this.fromBinaryV6(buffer, serialisationInfo);
115117
break;
116118

packages/uhk-common/src/config-serializer/config-items/key-action/mouse-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class MouseAction extends KeyAction {
6464
case 9:
6565
case 11:
6666
case 12:
67+
case 13:
6768
this.fromJsonObjectV6(jsonObject, serialisationInfo);
6869
break;
6970

@@ -90,6 +91,7 @@ export class MouseAction extends KeyAction {
9091
case 9:
9192
case 11:
9293
case 12:
94+
case 13:
9395
this.fromBinaryV6(buffer, serialisationInfo);
9496
break;
9597

packages/uhk-common/src/config-serializer/config-items/key-action/play-macro-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class PlayMacroAction extends KeyAction {
9595
case 9:
9696
case 11:
9797
case 12:
98+
case 13:
9899
this.fromJsonObjectV6(jsonObject, macros, serialisationInfo);
99100
break;
100101

@@ -121,6 +122,7 @@ export class PlayMacroAction extends KeyAction {
121122
case 9:
122123
case 11:
123124
case 12:
125+
case 13:
124126
this.fromBinaryV6(buffer, macros, serialisationInfo);
125127
break;
126128

packages/uhk-common/src/config-serializer/config-items/key-action/switch-keymap-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class SwitchKeymapAction extends KeyAction {
4343
case 9:
4444
case 11:
4545
case 12:
46+
case 13:
4647
this.fromJsonObjectV6(jsonObject, serialisationInfo);
4748
break;
4849

@@ -119,6 +120,7 @@ export class UnresolvedSwitchKeymapAction extends KeyAction {
119120
case 9:
120121
case 11:
121122
case 12:
123+
case 13:
122124
this.fromBinaryV6(buffer, serialisationInfo);
123125
break;
124126

packages/uhk-common/src/config-serializer/config-items/key-action/switch-layer-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class SwitchLayerAction extends KeyAction {
7373
case 9:
7474
case 11:
7575
case 12:
76+
case 13:
7677
this.fromJsonObjectV6(jsonObject, serialisationInfo);
7778
break;
7879

@@ -99,6 +100,7 @@ export class SwitchLayerAction extends KeyAction {
99100
case 9:
100101
case 11:
101102
case 12:
103+
case 13:
102104
this.fromBinaryV6(buffer, serialisationInfo);
103105
break;
104106

packages/uhk-common/src/config-serializer/config-items/keymap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class Keymap {
4242
case 9:
4343
case 11:
4444
case 12:
45+
case 13:
4546
this.fromJsonObjectV1(jsonObject, macros, serialisationInfo);
4647
break;
4748

@@ -67,6 +68,7 @@ export class Keymap {
6768
case 9:
6869
case 11:
6970
case 12:
71+
case 13:
7072
this.fromBinaryV1(buffer, macros, serialisationInfo);
7173
break;
7274

0 commit comments

Comments
 (0)