@leverege/build-tools 2.58.0-pedro.3 → 2.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.58.0-pedro.3",
3
+ "version": "2.58.0",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -48,7 +48,6 @@
48
48
  "pkglint": "src/pkglint.sh",
49
49
  "prune-git": "src/prune-git.sh",
50
50
  "pull-git": "src/pull-git.sh",
51
- "push-model-registry": "src/push-model-registry.mjs",
52
51
  "push-my-chart": "src/push-my-chart.mjs",
53
52
  "refresh-npm-token": "src/refresh-npm-token.mjs",
54
53
  "refresh-py-idx": "src/refresh-py-idx.sh",
@@ -60,7 +59,6 @@
60
59
  "license": "SEE LICENSE IN LICENSE.md",
61
60
  "dependencies": {
62
61
  "@google-cloud/artifact-registry": "^3.5.0",
63
- "@google-cloud/storage": "^7.14.0",
64
62
  "ansi-colors": "^4.1.3",
65
63
  "chalk": "^5.3.0",
66
64
  "command-line-args": "^6.0.1",
@@ -68,7 +66,6 @@
68
66
  "deepmerge": "^4.3.1",
69
67
  "enquirer": "^2.4.1",
70
68
  "execa": "^9.5.1",
71
- "fast-crc32c": "^2.0.0",
72
69
  "glob": "^11.0.0",
73
70
  "handlebars": "^4.7.8",
74
71
  "inquirer": "^12.1.0",
@@ -87,4 +84,4 @@
87
84
  "@leverege/eslint-config-leverege": "^5.0.1",
88
85
  "npm": "^10.9.1"
89
86
  }
90
- }
87
+ }
@@ -1,145 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import chalk from 'chalk';
6
- import inquirer from 'inquirer';
7
- import {Storage} from '@google-cloud/storage';
8
- import crc32c from 'fast-crc32c';
9
-
10
- const storage = new Storage();
11
-
12
- function getAllFiles(dirPath, arrayOfFiles = []) {
13
- const files = fs.readdirSync(dirPath);
14
-
15
- files.forEach(file => {
16
- const filePath = path.join(dirPath, file);
17
- if (fs.lstatSync(filePath).isDirectory()) {
18
- arrayOfFiles = getAllFiles(filePath, arrayOfFiles);
19
- } else {
20
- arrayOfFiles.push(filePath);
21
- }
22
- });
23
-
24
- return arrayOfFiles;
25
- }
26
-
27
- async function main() {
28
- // Get git branch name
29
- const branchName = fs.readFileSync('.git/HEAD', 'utf8').split('/').pop().trim();
30
-
31
- const bucketName = `${branchName}-triton-model-registry`;
32
-
33
- // Get all blobs in the bucket
34
- let files = [];
35
- try {
36
- [files] = await storage.bucket(bucketName).getFiles();
37
- } catch (error) {
38
- if (error.code === 404) {
39
- console.error(`Bucket ${bucketName} does not exist.`);
40
- return;
41
- } else {
42
- throw error;
43
- }
44
- }
45
-
46
- // Get all not hidden blobs in the current path in the filesystem
47
- const localFiles = getAllFiles('./models').filter(file => !path.basename(file).startsWith('.'));
48
-
49
- const filesToDelete = files.filter(file => !localFiles.find(localFile => localFile === file.name));
50
-
51
- console.log(`${chalk.underline(filesToDelete.length + " file(s)")} in ${chalk.underline(bucketName)} without a ${chalk.underline("local")} counterpart`);
52
- filesToDelete.forEach(file => console.log(chalk.red(file.name)));
53
-
54
- if (filesToDelete.length > 0) console.log("");
55
-
56
- const filesToAdd = [];
57
- const filesToReplace = [];
58
-
59
- const metadataPromises = localFiles.map(async file => {
60
- const localFileChecksum = Buffer.from(crc32c.calculate(fs.readFileSync(file)).toString(16), 'hex').toString('base64');
61
- const remoteFile = files.find(blob => blob.name === file);
62
- if (remoteFile) {
63
- const [metadata] = await remoteFile.getMetadata();
64
- return { file, localFileChecksum, remoteFileChecksum: metadata.crc32c };
65
- } else {
66
- return { file, localFileChecksum, remoteFileChecksum: null };
67
- }
68
- });
69
-
70
- const metadataResults = await Promise.all(metadataPromises);
71
-
72
- metadataResults.forEach(({ file, localFileChecksum, remoteFileChecksum }) => {
73
- if (remoteFileChecksum) {
74
- if (localFileChecksum !== remoteFileChecksum) {
75
- filesToReplace.push(file);
76
- }
77
- } else {
78
- filesToAdd.push(file);
79
- }
80
- });
81
-
82
- console.log(`${chalk.underline(filesToAdd.length + " file(s)")} to be added to ${chalk.underline(bucketName)}`);
83
- filesToAdd.forEach(file => console.log(chalk.green(file)));
84
-
85
- if (filesToAdd.length > 0) console.log("");
86
-
87
- console.log(`${chalk.underline(filesToReplace.length + " file(s)")} to be replaced in ${chalk.underline(bucketName)}`);
88
- filesToReplace.forEach(file => console.log(chalk.yellow(file)));
89
-
90
- if (filesToReplace.length > 0) console.log("");
91
-
92
- if (filesToDelete.length > 0) {
93
- const {confirm} = await inquirer.prompt({
94
- type: 'confirm',
95
- name: 'confirm',
96
- message: `Do you want to delete ${filesToDelete.length} file(s) from ${bucketName}?`,
97
- });
98
-
99
- if (!confirm) {
100
- return;
101
- }
102
-
103
- // Remove all blobs that are not in the local filesystem
104
- const deletePromises = filesToDelete.map(async file => {
105
- console.log(`Deleting ${file.name} from ${bucketName}`);
106
- return storage.bucket(bucketName).file(file.name).delete();
107
- });
108
-
109
- await Promise.all(deletePromises);
110
- console.log("")
111
- }
112
-
113
- if (filesToAdd.length > 0 || filesToReplace.length > 0) {
114
- const {confirm} = await inquirer.prompt({
115
- type: 'confirm',
116
- name: 'confirm',
117
- message: `Do you want to upload ${filesToAdd.length + filesToReplace.length} file(s) to ${bucketName}?`,
118
- });
119
-
120
- if (!confirm) {
121
- return;
122
- }
123
-
124
- // Upload all new files
125
- const uploadPromises = filesToAdd.map(async file => {
126
- console.log(`Uploading ${file} to ${bucketName}`);
127
- return storage.bucket(bucketName).upload(file, {
128
- destination: file,
129
- });
130
- });
131
-
132
- // Replace all files with different checksums
133
- const replacePromises = filesToReplace.map(async file => {
134
- console.log(`Replacing ${file} in ${bucketName}`);
135
- return storage.bucket(bucketName).upload(file, {
136
- destination: file,
137
- });
138
- });
139
-
140
- await Promise.all([...uploadPromises, ...replacePromises]);
141
- console.log("")
142
- }
143
- }
144
-
145
- main().catch(console.error);