@leverege/build-tools 2.93.3-beta.2 → 2.93.3-beta.3
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,11 +1,15 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs'
|
|
2
3
|
|
|
3
4
|
import { shellCmd, log, err, debug } from '../Utils.mjs'
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
parseGenericArtifactFileToRemoteRelativePath,
|
|
7
8
|
parseGenericArtifactSchemaToRemoteRelativePath,
|
|
8
|
-
listGenericArtifactFiles
|
|
9
|
+
listGenericArtifactFiles,
|
|
10
|
+
shouldUseIgnoreConfiguration,
|
|
11
|
+
findIgnoreFilePath,
|
|
12
|
+
copyFilesWithIgnoreConfiguration
|
|
9
13
|
} from './Utils.mjs'
|
|
10
14
|
|
|
11
15
|
class ArtifactPusher {
|
|
@@ -29,6 +33,11 @@ class GenericArtifactPusher extends ArtifactPusher {
|
|
|
29
33
|
return false
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
if ( !this.artifact.local_path && !this.artifact.local_file_path ) {
|
|
37
|
+
err( 'Local path or local file path is required for pushing artifacts' )
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
try {
|
|
33
42
|
|
|
34
43
|
let command = ''
|
|
@@ -40,8 +49,25 @@ class GenericArtifactPusher extends ArtifactPusher {
|
|
|
40
49
|
--package=${this.artifact.package} \
|
|
41
50
|
--version=${this.artifact.version}`
|
|
42
51
|
|
|
52
|
+
let pathToDelete
|
|
53
|
+
|
|
43
54
|
if ( this.artifact.local_path ) {
|
|
44
|
-
const
|
|
55
|
+
const originalLocalPath = path.join( this.path, this.artifact.local_path )
|
|
56
|
+
|
|
57
|
+
let localPath = originalLocalPath
|
|
58
|
+
|
|
59
|
+
const useIgnoreConfiguration = await shouldUseIgnoreConfiguration()
|
|
60
|
+
|
|
61
|
+
if ( useIgnoreConfiguration ) {
|
|
62
|
+
const ignoreFilePath = await findIgnoreFilePath( this.path )
|
|
63
|
+
if ( ignoreFilePath ) {
|
|
64
|
+
const tmpLocalPath = path.join( '/', 'tmp', `${this.artifact.project}_${this.artifact.location}_${this.artifact.repository}_${this.artifact.package}_${this.artifact.version}` )
|
|
65
|
+
localPath = tmpLocalPath
|
|
66
|
+
pathToDelete = tmpLocalPath
|
|
67
|
+
await copyFilesWithIgnoreConfiguration( originalLocalPath, tmpLocalPath, ignoreFilePath )
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
45
71
|
command += ` --source-directory=${localPath}`
|
|
46
72
|
command += ' --skip-existing'
|
|
47
73
|
} else if ( this.artifact.local_file_path ) {
|
|
@@ -66,7 +92,11 @@ class GenericArtifactPusher extends ArtifactPusher {
|
|
|
66
92
|
debug( { command }, '<==Upload Command' )
|
|
67
93
|
|
|
68
94
|
await shellCmd( command )
|
|
69
|
-
|
|
95
|
+
|
|
96
|
+
if ( pathToDelete ) {
|
|
97
|
+
await fs.promises.rm( pathToDelete, { recursive : true } )
|
|
98
|
+
}
|
|
99
|
+
|
|
70
100
|
log( `Successfully pushed artifact: ${this.artifact.name}` )
|
|
71
101
|
|
|
72
102
|
return true
|
package/src/artifacts/Utils.mjs
CHANGED
|
@@ -186,7 +186,7 @@ const listGenericArtifactFiles = async ( artifact ) => {
|
|
|
186
186
|
return files
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
const
|
|
189
|
+
const getMissingRemoteFiles = async ( genericArtifactFiles, genericArtifactSchemaPath, genericArtifactSchema ) => {
|
|
190
190
|
|
|
191
191
|
const expectedRemoteRelativePath = parseGenericArtifactSchemaToRemoteRelativePath( genericArtifactSchema )
|
|
192
192
|
const localRelativePath = parseGenericArtifactSchemaToLocalRelativePath( genericArtifactSchema )
|
|
@@ -221,8 +221,47 @@ const checkGenericArtifactMatch = async ( genericArtifactFiles, genericArtifactS
|
|
|
221
221
|
const actualArray = Array.from( actualFiles )
|
|
222
222
|
const expectedArray = Array.from( expectedFiles )
|
|
223
223
|
|
|
224
|
-
return actualArray.
|
|
225
|
-
|
|
224
|
+
return expectedArray.filter( expected => !actualArray.some( actual => actual.remoteFilePath === expected.remoteFilePath && actual.remoteFileHash === expected.remoteFileHash ) )
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const shouldUseIgnoreConfiguration = async () => {
|
|
228
|
+
let result
|
|
229
|
+
try {
|
|
230
|
+
result = await shellCmd( 'gcloud config get-value gcloudignore/enabled' )
|
|
231
|
+
if ( result.trim() === '' || result.includes( 'has no property' ) ) {
|
|
232
|
+
return false
|
|
233
|
+
}
|
|
234
|
+
return result.trim() === 'true'
|
|
235
|
+
} catch ( error ) {
|
|
236
|
+
if ( error.message && error.message.includes( 'Section [gcloudignore] has no property [enabled]' ) ) {
|
|
237
|
+
return false
|
|
238
|
+
}
|
|
239
|
+
// Re-throw other errors
|
|
240
|
+
throw error
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const findIgnoreFilePath = async ( relativePath ) => {
|
|
245
|
+
if ( relativePath ) {
|
|
246
|
+
const ignoreFilePath = path.join( relativePath, '.gcloudignore' )
|
|
247
|
+
if ( fs.existsSync( ignoreFilePath ) ) {
|
|
248
|
+
return ignoreFilePath
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const ignoreFilePath = path.join( process.cwd(), '.gcloudignore' )
|
|
253
|
+
if ( fs.existsSync( ignoreFilePath ) ) {
|
|
254
|
+
return ignoreFilePath
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return null
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const copyFilesWithIgnoreConfiguration = async ( sourcePath, destinationPath, ignoreFilePath ) => {
|
|
261
|
+
// Ensure sourcePath ends with / so rsync copies contents (not the folder itself) and exclude patterns work correctly
|
|
262
|
+
const normalizedSourcePath = sourcePath.endsWith( '/' ) ? sourcePath : `${sourcePath}/`
|
|
263
|
+
const command = `rsync -av --delete --exclude-from='${ignoreFilePath}' ${normalizedSourcePath} ${destinationPath}`
|
|
264
|
+
await shellCmd( command )
|
|
226
265
|
}
|
|
227
266
|
|
|
228
267
|
export {
|
|
@@ -232,7 +271,12 @@ export {
|
|
|
232
271
|
parseGenericArtifactFileToRemoteRelativePath,
|
|
233
272
|
parseGenericArtifactSchemaToRemoteRelativePath,
|
|
234
273
|
parseGenericArtifactSchemaToLocalRelativePath,
|
|
274
|
+
parseGenericArtifactSchemaToArtifactNameBase,
|
|
275
|
+
parseGenericArtifactSchemaToArtifactNameFile,
|
|
235
276
|
parseGenericArtifactSchemaToArtifactName,
|
|
236
|
-
|
|
237
|
-
listGenericArtifactFiles
|
|
277
|
+
getMissingRemoteFiles,
|
|
278
|
+
listGenericArtifactFiles,
|
|
279
|
+
shouldUseIgnoreConfiguration,
|
|
280
|
+
findIgnoreFilePath,
|
|
281
|
+
copyFilesWithIgnoreConfiguration
|
|
238
282
|
}
|