Skip to content

Commit 0c340a3

Browse files
add createGcomPluginJson.ts (#328)
* add createGcomPluginJson.ts * review fixes * remove relase folder * better debugging message * better debugging messages v2
1 parent 029122a commit 0c340a3

File tree

5 files changed

+228
-3
lines changed

5 files changed

+228
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ dist/**/*
3636
# Ignore output from coverage report
3737
coverage
3838

39-
scripts/sharp-downloader
39+
scripts/tmp

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"watch": "tsc-watch --onSuccess \"node build/app.js server --config=dev.json\"",
1717
"watch:debug": "tsc-watch --onSuccess \"cross-env DEBUG=puppeteer-cluster:* node build/app.js server --config=dev.json\"",
1818
"build": "tsc",
19-
"start": "node build/app.js --config=dev.json"
19+
"start": "node build/app.js --config=dev.json",
20+
"create-gcom-plugin-json": "ts-node scripts/createGcomPluginJson.ts ./scripts/tmp"
2021
},
2122
"dependencies": {
2223
"@grpc/grpc-js": "^1.0",
@@ -48,6 +49,8 @@
4849
"eslint": "^7.32.0",
4950
"eslint-config-prettier": "^8.3.0",
5051
"eslint-plugin-jsdoc": "^36.1.0",
52+
"axios": "0.26.0",
53+
"ts-node": "10.5.0",
5154
"eslint-plugin-prettier": "^4.0.0",
5255
"eslint-plugin-react": "^7.26.1",
5356
"eslint-plugin-react-hooks": "^4.2.0",

scripts/createGcomPluginJson.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import path = require("path");
2+
const fs = require('fs');
3+
4+
const outputFolder = process.argv[2]
5+
const commit = process.argv[3];
6+
7+
if (!outputFolder) {
8+
throw new Error('expected output folder as the first arg')
9+
}
10+
11+
if (!commit) {
12+
throw new Error(`usage: 'yarn run create-gcom-plugin-json <COMMIT_HASH>'`);
13+
}
14+
15+
const outputPath = path.join(outputFolder, 'plugin.json')
16+
const rootPluginJsonPath = path.resolve('./plugin.json');
17+
18+
19+
enum PluginVersion {
20+
'darwin-amd64' = 'darwin-amd64',
21+
'linux-amd64' = 'linux-amd64',
22+
'windows-amd64' = 'windows-amd64',
23+
}
24+
25+
type PluginJson = {
26+
url: string;
27+
commit: string;
28+
download: Record<PluginVersion, { url: string; md5: string }>;
29+
};
30+
31+
const pluginVersionToFileName: Record<PluginVersion, string> = {
32+
[PluginVersion['darwin-amd64']]: 'plugin-darwin-x64-unknown.zip',
33+
[PluginVersion['linux-amd64']]: 'plugin-linux-x64-glibc.zip',
34+
[PluginVersion['windows-amd64']]: 'plugin-win32-x64-unknown.zip',
35+
};
36+
37+
const baseUrl = `https://github.com/grafana/grafana-image-renderer`;
38+
const fileUrl = (release, fileName) => `${baseUrl}/releases/download/${release}/${fileName}`;
39+
40+
const axios = require('axios');
41+
42+
const getFileNamesToChecksumMap = async (releaseVersion: string): Promise<Record<string, string>> => {
43+
const res = await axios.get(fileUrl(releaseVersion, 'md5sums.txt'));
44+
45+
if (typeof res.data !== 'string') {
46+
throw new Error('expected checksum data to be string');
47+
}
48+
49+
const text = res.data as string;
50+
51+
return text
52+
.split('\n')
53+
.map((l) => l.replaceAll(/\s+/g, ' ').split(' '))
54+
.filter((arr) => arr.length === 2)
55+
.reduce((acc, [checksum, artifact]) => {
56+
const artifactPrefix = 'artifacts/';
57+
if (artifact.startsWith(artifactPrefix)) {
58+
return { ...acc, [artifact.substring(artifactPrefix.length)]: checksum };
59+
} else {
60+
throw new Error(`expected artifact name to start with "artifact/". actual: ${artifact}`);
61+
}
62+
}, {});
63+
};
64+
65+
const verifyChecksums = (map: Record<string, string>) => {
66+
const expectedFileNames = Object.values(pluginVersionToFileName);
67+
const fileNamesInChecksumMap = Object.keys(map);
68+
for (const expectedFileName of expectedFileNames) {
69+
if (!fileNamesInChecksumMap.includes(expectedFileName)) {
70+
throw new Error(`expected to find ${expectedFileName} in the checksum map. actual: [${fileNamesInChecksumMap.join(', ')}]`);
71+
}
72+
}
73+
};
74+
75+
const getReleaseVersion = (): string => {
76+
const rootPluginJson = JSON.parse(fs.readFileSync(rootPluginJsonPath));
77+
const version = rootPluginJson?.info?.version;
78+
79+
if (!version || typeof version !== 'string' || !version.length) {
80+
throw new Error(`expected to find value for "info.version" in root plugin.json (${rootPluginJsonPath})`);
81+
}
82+
return `v${version}`;
83+
};
84+
85+
const createGcomPluginJson = (map: Record<string, string>, releaseVersion: string): PluginJson => ({
86+
url: baseUrl,
87+
commit: commit,
88+
download: Object.values(PluginVersion)
89+
.map((ver) => {
90+
const fileName = pluginVersionToFileName[ver];
91+
const md5 = map[fileName];
92+
if (!md5 || !md5.length) {
93+
throw new Error(`expected non-empty md5 checksum for plugin version ${ver} with filename ${fileName}`);
94+
}
95+
96+
return { [ver]: { md5, url: fileUrl(releaseVersion, fileName) } };
97+
})
98+
.reduce((acc, next) => ({ ...acc, ...next }), {}) as PluginJson['download'],
99+
});
100+
101+
const run = async () => {
102+
const releaseVersion = getReleaseVersion();
103+
console.log(`Creating gcom plugin json with version ${releaseVersion} and commit ${commit}`);
104+
105+
const artifactsToChecksumMap = await getFileNamesToChecksumMap(releaseVersion);
106+
verifyChecksums(artifactsToChecksumMap);
107+
108+
console.log(`Fetched artifact checksums ${JSON.stringify(artifactsToChecksumMap, null, 2)}`);
109+
110+
const pluginJson = createGcomPluginJson(artifactsToChecksumMap, releaseVersion);
111+
if (!fs.existsSync(outputFolder)) {
112+
fs.mkdirSync(outputFolder)
113+
}
114+
fs.writeFileSync(outputPath, JSON.stringify(pluginJson, null, 2));
115+
116+
console.log(`Done! Path: ${path.resolve(outputPath)}`)
117+
};
118+
119+
run();

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"moduleResolution": "node",
4-
"target": "es6",
4+
"target": "es2021",
55
"module": "commonjs",
66
"outDir": "build",
77
"sourceMap": true,

yarn.lock

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
"@babel/helper-validator-identifier" "^7.15.7"
5151
to-fast-properties "^2.0.0"
5252

53+
"@cspotcode/[email protected]":
54+
version "0.8.0"
55+
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
56+
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==
57+
58+
"@cspotcode/[email protected]":
59+
version "0.7.0"
60+
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5"
61+
integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==
62+
dependencies:
63+
"@cspotcode/source-map-consumer" "0.8.0"
64+
5365
"@dabh/diagnostics@^2.0.2":
5466
version "2.0.2"
5567
resolved "https://registry.yarnpkg.com/@dabh/diagnostics/-/diagnostics-2.0.2.tgz#290d08f7b381b8f94607dc8f471a12c675f9db31"
@@ -525,6 +537,26 @@
525537
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
526538
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
527539

540+
"@tsconfig/node10@^1.0.7":
541+
version "1.0.8"
542+
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
543+
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==
544+
545+
"@tsconfig/node12@^1.0.7":
546+
version "1.0.9"
547+
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
548+
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==
549+
550+
"@tsconfig/node14@^1.0.0":
551+
version "1.0.1"
552+
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
553+
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==
554+
555+
"@tsconfig/node16@^1.0.2":
556+
version "1.0.2"
557+
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
558+
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
559+
528560
"@types/body-parser@*":
529561
version "1.19.2"
530562
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0"
@@ -777,11 +809,21 @@ acorn-jsx@^5.3.1:
777809
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
778810
integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==
779811

812+
acorn-walk@^8.1.1:
813+
version "8.2.0"
814+
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
815+
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
816+
780817
acorn@^7.4.0:
781818
version "7.4.1"
782819
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
783820
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==
784821

822+
acorn@^8.4.1:
823+
version "8.7.0"
824+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf"
825+
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==
826+
785827
agent-base@6:
786828
version "6.0.2"
787829
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
@@ -879,6 +921,11 @@ are-we-there-yet@~1.1.2:
879921
delegates "^1.0.0"
880922
readable-stream "^2.0.6"
881923

924+
arg@^4.1.0:
925+
version "4.1.3"
926+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
927+
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
928+
882929
argparse@^1.0.7:
883930
version "1.0.10"
884931
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -931,6 +978,13 @@ at-least-node@^1.0.0:
931978
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
932979
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
933980

981+
982+
version "0.26.0"
983+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928"
984+
integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==
985+
dependencies:
986+
follow-redirects "^1.14.8"
987+
934988
balanced-match@^1.0.0:
935989
version "1.0.2"
936990
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
@@ -1246,6 +1300,11 @@ cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
12461300
path-type "^4.0.0"
12471301
yaml "^1.10.0"
12481302

1303+
create-require@^1.1.0:
1304+
version "1.1.1"
1305+
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
1306+
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
1307+
12491308
12501309
version "7.0.3"
12511310
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
@@ -1337,6 +1396,11 @@ [email protected]:
13371396
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.960912.tgz#411c1fa355eddb72f06c4a8743f2808766db6245"
13381397
integrity sha512-I3hWmV9rWHbdnUdmMKHF2NuYutIM2kXz2mdXW8ha7TbRlGTVs+PF+PsB5QWvpCek4Fy9B+msiispCfwlhG5Sqg==
13391398

1399+
diff@^4.0.1:
1400+
version "4.0.2"
1401+
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
1402+
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
1403+
13401404
dir-glob@^3.0.1:
13411405
version "3.0.1"
13421406
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
@@ -1934,6 +1998,11 @@ [email protected]:
19341998
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc"
19351999
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==
19362000

2001+
follow-redirects@^1.14.8:
2002+
version "1.14.9"
2003+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
2004+
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
2005+
19372006
19382007
version "0.2.0"
19392008
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
@@ -2663,6 +2732,11 @@ lru-cache@^6.0.0:
26632732
dependencies:
26642733
yallist "^4.0.0"
26652734

2735+
make-error@^1.1.1:
2736+
version "1.3.6"
2737+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
2738+
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
2739+
26662740
map-stream@~0.1.0:
26672741
version "0.1.0"
26682742
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194"
@@ -3972,6 +4046,25 @@ triple-beam@^1.2.0, triple-beam@^1.3.0:
39724046
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
39734047
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==
39744048

4049+
4050+
version "10.5.0"
4051+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.5.0.tgz#618bef5854c1fbbedf5e31465cbb224a1d524ef9"
4052+
integrity sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==
4053+
dependencies:
4054+
"@cspotcode/source-map-support" "0.7.0"
4055+
"@tsconfig/node10" "^1.0.7"
4056+
"@tsconfig/node12" "^1.0.7"
4057+
"@tsconfig/node14" "^1.0.0"
4058+
"@tsconfig/node16" "^1.0.2"
4059+
acorn "^8.4.1"
4060+
acorn-walk "^8.1.1"
4061+
arg "^4.1.0"
4062+
create-require "^1.1.0"
4063+
diff "^4.0.1"
4064+
make-error "^1.1.1"
4065+
v8-compile-cache-lib "^3.0.0"
4066+
yn "3.1.1"
4067+
39754068
tsc-watch@^4.2.3:
39764069
version "4.6.0"
39774070
resolved "https://registry.yarnpkg.com/tsc-watch/-/tsc-watch-4.6.0.tgz#a0eba1300cbe3048ab6d3a3e06de47141b613beb"
@@ -4120,6 +4213,11 @@ [email protected]:
41204213
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
41214214
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
41224215

4216+
v8-compile-cache-lib@^3.0.0:
4217+
version "3.0.0"
4218+
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8"
4219+
integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==
4220+
41234221
v8-compile-cache@^2.0.3:
41244222
version "2.3.0"
41254223
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
@@ -4305,6 +4403,11 @@ yauzl@^2.10.0:
43054403
buffer-crc32 "~0.2.3"
43064404
fd-slicer "~1.1.0"
43074405

4406+
4407+
version "3.1.1"
4408+
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
4409+
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
4410+
43084411
yocto-queue@^0.1.0:
43094412
version "0.1.0"
43104413
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"

0 commit comments

Comments
 (0)