@leverege/build-tools 2.93.0-beta.11 → 2.93.0-beta.12
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,5 +1,8 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
1
2
|
import fs from 'fs'
|
|
2
3
|
|
|
4
|
+
import { shellCmd, log, debug, err } from '../Utils.mjs'
|
|
5
|
+
|
|
3
6
|
import { toExplicitPath } from './Utils.mjs'
|
|
4
7
|
|
|
5
8
|
class ArtifactPuller {
|
|
@@ -15,6 +18,8 @@ class ArtifactPuller {
|
|
|
15
18
|
class GenericArtifactPuller extends ArtifactPuller {
|
|
16
19
|
|
|
17
20
|
async downloadFile( remoteFilePath, localFilePath ) {
|
|
21
|
+
debug( { remoteFilePath, localFilePath }, '<==Download File' )
|
|
22
|
+
|
|
18
23
|
const command = `gcloud artifacts generic download \
|
|
19
24
|
--project=${this.artifact.gcp_project_id} \
|
|
20
25
|
--location=${this.artifact.gcp_location} \
|
|
@@ -40,25 +45,23 @@ class GenericArtifactPuller extends ArtifactPuller {
|
|
|
40
45
|
// Ensure the directory exists
|
|
41
46
|
fs.mkdirSync( localFilePath.split( '/' ).slice( 0, -1 ).join( '/' ), { recursive : true } )
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
debug( { command }, '<==Download File Command' )
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
const result = execSync( command, { encoding : 'utf8', stdio : 'pipe' } )
|
|
47
|
-
console.log( 'Result:', result )
|
|
50
|
+
await shellCmd( command )
|
|
48
51
|
|
|
49
52
|
// Check if file exists in the old path
|
|
50
53
|
if ( !fs.existsSync( oldPath ) ) {
|
|
51
|
-
|
|
54
|
+
debug( { oldPath }, '<==File does not exist in the old path' )
|
|
52
55
|
return false
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
debug( { oldPath, newPath }, '<==Copying file' )
|
|
56
59
|
|
|
57
60
|
await fs.copyFileSync( oldPath, newPath )
|
|
58
61
|
|
|
59
62
|
// Check if file exists in the new path
|
|
60
63
|
if ( !fs.existsSync( newPath ) ) {
|
|
61
|
-
|
|
64
|
+
debug( { newPath }, '<==File does not exist in the new path' )
|
|
62
65
|
return false
|
|
63
66
|
}
|
|
64
67
|
|
|
@@ -74,15 +77,14 @@ class GenericArtifactPuller extends ArtifactPuller {
|
|
|
74
77
|
--version=${this.artifact.gcp_artifact_registry_package_version} \
|
|
75
78
|
--destination=${localPath}`
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
debug( { command }, '<==Download Directory Command' )
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
execSync( command, { encoding : 'utf8', stdio : 'pipe' } )
|
|
81
|
-
|
|
82
|
-
return true
|
|
82
|
+
await shellCmd( command )
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
async downloadNestedDirectory( remotePath, localPath ) {
|
|
86
|
+
debug( { remotePath, localPath }, '<==Download Nested Directory' )
|
|
87
|
+
|
|
86
88
|
const files = await this.listFiles( remotePath )
|
|
87
89
|
await Promise.all(
|
|
88
90
|
files
|
|
@@ -93,7 +95,6 @@ class GenericArtifactPuller extends ArtifactPuller {
|
|
|
93
95
|
await this.downloadFile( remoteFilePath, localFilePath )
|
|
94
96
|
} )
|
|
95
97
|
)
|
|
96
|
-
return true
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
async listFiles( ) {
|
|
@@ -105,42 +106,48 @@ class GenericArtifactPuller extends ArtifactPuller {
|
|
|
105
106
|
--version ${this.artifact.gcp_artifact_registry_package_version} \
|
|
106
107
|
--format="json"`
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
debug( { command }, '<==List Files Command' )
|
|
109
110
|
|
|
110
|
-
const
|
|
111
|
-
const result = execSync( command, { encoding : 'utf8', stdio : 'pipe' } )
|
|
111
|
+
const result = await shellCmd( command )
|
|
112
112
|
|
|
113
113
|
// Parse the JSON response
|
|
114
114
|
const files = JSON.parse( result )
|
|
115
|
-
|
|
116
115
|
return files
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
async pull() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
119
|
+
log( `Pulling artifact: ${this.artifact.name}` )
|
|
120
|
+
|
|
121
|
+
debug( { artifact : this.artifact }, '<==Pulling artifact' )
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
if ( this.artifact.remote_file_path && this.artifact.local_file_path ) {
|
|
125
|
+
await this.downloadFile( this.artifact.remote_file_path, toExplicitPath( this.artifact.local_file_path ) )
|
|
126
|
+
} else if ( this.artifact.remote_file_path && this.artifact.local_path ) {
|
|
127
|
+
await this.downloadFile( this.artifact.remote_file_path, toExplicitPath( `${this.artifact.local_path}/${this.artifact.remote_file_path.split( '/' ).pop()}` ) )
|
|
128
|
+
} else if ( this.artifact.remote_path && this.artifact.local_path ) {
|
|
129
|
+
await this.downloadNestedDirectory( this.artifact.remote_path, toExplicitPath( this.artifact.local_path ) )
|
|
130
|
+
} else if ( this.artifact.remote_path && !this.artifact.local_path && !this.artifact.local_file_path ) {
|
|
131
|
+
await this.downloadDirectory( this.artifact.remote_path, '.' )
|
|
132
|
+
} else if ( !this.artifact.remote_path && !this.artifact.remote_file_path && this.artifact.local_path ) {
|
|
133
|
+
await this.downloadDirectory( toExplicitPath( this.artifact.local_path ) )
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error( 'No valid paths provided' )
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
log( `Successfully pulled artifact: ${this.artifact.name}` )
|
|
139
|
+
|
|
140
|
+
return true
|
|
141
|
+
|
|
142
|
+
// if ( !this.artifact.remote_path && !this.artifact.remote_file_path && this.local_file_path ) {
|
|
143
|
+
// throw new Error( '' )
|
|
144
|
+
// }
|
|
145
|
+
// if ( this.artifact.remote_path && this.artifact.local_file_path ) {
|
|
146
|
+
// throw new Error( '' )
|
|
147
|
+
// }
|
|
148
|
+
} catch ( error ) {
|
|
149
|
+
err( `Error pulling artifact: ${this.artifact.name} ${error.message}` )
|
|
136
150
|
}
|
|
137
|
-
// if ( !this.artifact.remote_path && !this.artifact.remote_file_path && this.local_file_path ) {
|
|
138
|
-
// throw new Error( '' )
|
|
139
|
-
// }
|
|
140
|
-
// if ( this.artifact.remote_path && this.artifact.local_file_path ) {
|
|
141
|
-
// throw new Error( '' )
|
|
142
|
-
// }
|
|
143
|
-
|
|
144
151
|
return false
|
|
145
152
|
}
|
|
146
153
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
|
+
import { shellCmd, log, err, debug } from '../Utils.mjs'
|
|
3
|
+
|
|
1
4
|
class ArtifactPusher {
|
|
2
5
|
constructor( artifact ) {
|
|
3
6
|
this.artifact = artifact
|
|
@@ -19,10 +22,9 @@ class GenericArtifactPusher extends ArtifactPusher {
|
|
|
19
22
|
--version ${this.artifact.gcp_artifact_registry_package_version} \
|
|
20
23
|
--format="json"`
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
debug( { command }, '<==List Files Command' )
|
|
23
26
|
|
|
24
|
-
const
|
|
25
|
-
const result = execSync( command, { encoding : 'utf8', stdio : 'pipe' } )
|
|
27
|
+
const result = await shellCmd( command )
|
|
26
28
|
|
|
27
29
|
// Parse the JSON response
|
|
28
30
|
const files = JSON.parse( result )
|
|
@@ -31,45 +33,49 @@ class GenericArtifactPusher extends ArtifactPusher {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
async push() {
|
|
34
|
-
|
|
36
|
+
log( `Pushing artifact: ${this.artifact.name}` )
|
|
35
37
|
|
|
36
38
|
if ( this.artifact.remote_file_path ) {
|
|
39
|
+
err( 'Remote file path is not supported for pushing artifacts' )
|
|
37
40
|
return false
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
try {
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
let command = ''
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
command = `gcloud artifacts generic upload \
|
|
45
48
|
--project=${this.artifact.gcp_project_id} \
|
|
46
49
|
--location=${this.artifact.gcp_location} \
|
|
47
50
|
--repository=${this.artifact.gcp_artifact_registry_repository_name} \
|
|
48
51
|
--package=${this.artifact.gcp_artifact_registry_package_name} \
|
|
49
52
|
--version=${this.artifact.gcp_artifact_registry_package_version}`
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
if ( this.artifact.local_path ) {
|
|
55
|
+
command += ` --source-directory=${this.artifact.local_path}`
|
|
56
|
+
command += ' --skip-existing'
|
|
57
|
+
} else if ( this.artifact.local_file_path ) {
|
|
58
|
+
const files = await this.listFiles( this.artifact.remote_path )
|
|
59
|
+
if ( files.some( file => file.name.split( ':' ).pop().replaceAll( '%2F', '/' ) === `${this.artifact.remote_path}/${this.artifact.remote_file_path.split( '/' ).pop()}` ) ) {
|
|
60
|
+
err( `File already exists in the artifact registry: ${this.artifact.local_file_path}` )
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
command += ` --source=${this.artifact.local_file_path}`
|
|
58
64
|
}
|
|
59
|
-
command += ` --source=${this.artifact.local_file_path}`
|
|
60
|
-
}
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
if ( this.artifact.remote_path ) {
|
|
67
|
+
command += ` --destination-path=${this.artifact.remote_path}`
|
|
68
|
+
}
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
debug( { command }, '<==Upload Command' )
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
await shellCmd( command )
|
|
73
|
+
|
|
74
|
+
log( `Successfully pushed artifact: ${this.artifact.name}` )
|
|
75
|
+
|
|
70
76
|
return true
|
|
71
77
|
} catch ( error ) {
|
|
72
|
-
|
|
78
|
+
err( `Error pushing artifact: ${this.artifact.name} ${error.message}` )
|
|
73
79
|
return false
|
|
74
80
|
}
|
|
75
81
|
}
|
package/src/artifacts/Utils.mjs
CHANGED
|
@@ -70,35 +70,6 @@ const toExplicitPath = ( path ) => {
|
|
|
70
70
|
return explicitPath
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const buildGenericArtifactName = ( artifact ) => {
|
|
74
|
-
const baseElements = [
|
|
75
|
-
'projects',
|
|
76
|
-
artifact.gcp_project_id,
|
|
77
|
-
'locations',
|
|
78
|
-
artifact.gcp_location,
|
|
79
|
-
'repositories',
|
|
80
|
-
artifact.gcp_artifact_registry_repository_name,
|
|
81
|
-
'files',
|
|
82
|
-
artifact.gcp_artifact_registry_package_name,
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
const versionElement = artifact.gcp_artifact_registry_package_version
|
|
86
|
-
|
|
87
|
-
const remotePathElements = []
|
|
88
|
-
|
|
89
|
-
if ( artifact.remote_path || artifact.remote_file_path ) {
|
|
90
|
-
const explicitRemotePath = toExplicitPath( artifact.remote_path || artifact.remote_file_path )
|
|
91
|
-
const implicitRemotePath = toImplicitPath( explicitRemotePath )
|
|
92
|
-
if ( implicitRemotePath !== '.' ) {
|
|
93
|
-
remotePathElements.push( implicitRemotePath )
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const name = [ baseElements.join( '/' ), versionElement, encodeURIComponent( remotePathElements.join( '/' ) ) ].join( ':' )
|
|
98
|
-
|
|
99
|
-
return name
|
|
100
|
-
}
|
|
101
|
-
|
|
102
73
|
const calculateHash = ( path ) => {
|
|
103
74
|
try {
|
|
104
75
|
const hash = crypto.createHash( 'sha256' )
|
|
@@ -110,4 +81,4 @@ const calculateHash = ( path ) => {
|
|
|
110
81
|
}
|
|
111
82
|
}
|
|
112
83
|
|
|
113
|
-
export { calculateHash, getArtifactsSchema, flattenArtifactsSchema, toImplicitPath, toExplicitPath
|
|
84
|
+
export { calculateHash, getArtifactsSchema, flattenArtifactsSchema, toImplicitPath, toExplicitPath }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { warning } from '../Utils.mjs'
|
|
3
|
+
import { warning, err, log } from '../Utils.mjs'
|
|
4
4
|
|
|
5
5
|
import { getArtifactsSchema, flattenArtifactsSchema } from './Utils.mjs'
|
|
6
6
|
import { ArtifactTypeEnum } from './Structs.mjs'
|
|
@@ -8,61 +8,64 @@ import { GenericArtifactPuller } from './ArtifactPuller.mjs'
|
|
|
8
8
|
|
|
9
9
|
async function main() {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if ( process.argv.length < 3 ) {
|
|
12
|
+
err( 'Usage:' )
|
|
13
|
+
err( ' pull-artifact.mjs <artifacts.yml>' )
|
|
14
|
+
err( ' pull-artifact.mjs <artifacts.yml> <artifact package name>' )
|
|
15
|
+
err( ' pull-artifact.mjs <artifacts.yml> <artifact package name> <artifact package version>' )
|
|
16
|
+
process.exit( 1 )
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const artifactsYmlPath = process.argv[2]
|
|
20
|
+
const artifactPackageName = process.argv.length > 3 ? process.argv[3] : null
|
|
21
|
+
const artifactPackageVersion = process.argv.length > 4 ? process.argv[4] : null
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
artifactsYmlPath = process.argv[2]
|
|
24
|
-
filteredArtifactSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
25
|
-
const flattenedArtifactsSchema = flattenArtifactsSchema( filteredArtifactSchema )
|
|
26
|
-
filteredArtifactSchema = flattenedArtifactsSchema.find(
|
|
27
|
-
artifact => artifact.name === artifactName )
|
|
28
|
-
} else if ( process.argv.length === 5 ) {
|
|
29
|
-
artifactsYmlPath = process.argv[2]
|
|
30
|
-
artifactName = process.argv[3]
|
|
31
|
-
artifactPackageName = process.argv[4]
|
|
32
|
-
artifactPackageVersion = process.argv[5]
|
|
33
|
-
filteredArtifactSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
34
|
-
const flattenedArtifactsSchema = flattenArtifactsSchema( filteredArtifactSchema )
|
|
35
|
-
filteredArtifactSchema = flattenedArtifactsSchema.filter(
|
|
23
|
+
const artifactsSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
24
|
+
const flattenedArtifactsSchema = flattenArtifactsSchema( artifactsSchema )
|
|
25
|
+
|
|
26
|
+
let filteredArtifactsSchema
|
|
27
|
+
if ( artifactPackageName && artifactPackageVersion ) {
|
|
28
|
+
filteredArtifactsSchema = flattenedArtifactsSchema.filter(
|
|
36
29
|
artifact => artifact.gcp_artifact_registry_package_name === artifactPackageName &&
|
|
37
30
|
artifact.gcp_artifact_registry_package_version === artifactPackageVersion )
|
|
31
|
+
} else if ( artifactPackageName ) {
|
|
32
|
+
filteredArtifactsSchema = flattenedArtifactsSchema.filter(
|
|
33
|
+
artifact => artifact.gcp_artifact_registry_package_name === artifactPackageName )
|
|
38
34
|
} else {
|
|
39
|
-
|
|
40
|
-
console.error( ' pull-artifact.mjs <artifacts.yml>' )
|
|
41
|
-
console.error( ' pull-artifact.mjs <artifacts.yml> <artifact name>' )
|
|
42
|
-
console.error( ' pull-artifact.mjs <artifacts.yml> <artifact package name> <artifact package version>' )
|
|
43
|
-
process.exit( 1 )
|
|
35
|
+
filteredArtifactsSchema = flattenedArtifactsSchema
|
|
44
36
|
}
|
|
37
|
+
|
|
38
|
+
let counter = 0
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const pullResults = await Promise.all(
|
|
41
|
+
filteredArtifactsSchema.map( async ( artifactSchema ) => {
|
|
42
|
+
let puller
|
|
43
|
+
switch ( artifactSchema.type ) {
|
|
44
|
+
case ArtifactTypeEnum.GENERIC:
|
|
45
|
+
puller = new GenericArtifactPuller( artifactSchema )
|
|
46
|
+
break
|
|
47
|
+
default:
|
|
48
|
+
warning( `Unsupported artifact type "${artifactSchema.type}"` )
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( !puller ) {
|
|
54
53
|
warning( `Unsupported artifact type "${artifactSchema.type}"` )
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
return await puller.pull()
|
|
59
|
+
} catch ( error ) {
|
|
60
|
+
warning( `Error pulling artifact "${artifactSchema.name}": ${error.message}` )
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
} )
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
counter = pullResults.filter( Boolean ).length
|
|
67
|
+
|
|
68
|
+
log( `Successfully pushed ${counter}/${filteredArtifactsSchema.length} artifacts` )
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { warning } from '../Utils.mjs'
|
|
3
|
+
import { warning, err, log } from '../Utils.mjs'
|
|
4
4
|
|
|
5
5
|
import { getArtifactsSchema, flattenArtifactsSchema } from './Utils.mjs'
|
|
6
6
|
import { ArtifactTypeEnum } from './Structs.mjs'
|
|
@@ -8,61 +8,64 @@ import { GenericArtifactPusher } from './ArtifactPusher.mjs'
|
|
|
8
8
|
|
|
9
9
|
async function main() {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if ( process.argv.length < 3 ) {
|
|
12
|
+
err( 'Usage:' )
|
|
13
|
+
err( ' push-artifact.mjs <artifacts.yml>' )
|
|
14
|
+
err( ' push-artifact.mjs <artifacts.yml> <artifact package name>' )
|
|
15
|
+
err( ' push-artifact.mjs <artifacts.yml> <artifact package name> <artifact package version>' )
|
|
16
|
+
process.exit( 1 )
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const artifactsYmlPath = process.argv[2]
|
|
20
|
+
const artifactPackageName = process.argv.length > 3 ? process.argv[3] : null
|
|
21
|
+
const artifactPackageVersion = process.argv.length > 4 ? process.argv[4] : null
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
artifactsYmlPath = process.argv[2]
|
|
24
|
-
filteredArtifactSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
25
|
-
const flattenedArtifactsSchema = flattenArtifactsSchema( filteredArtifactSchema )
|
|
26
|
-
filteredArtifactSchema = flattenedArtifactsSchema.find(
|
|
27
|
-
artifact => artifact.name === artifactName )
|
|
28
|
-
} else if ( process.argv.length === 5 ) {
|
|
29
|
-
artifactsYmlPath = process.argv[2]
|
|
30
|
-
artifactName = process.argv[3]
|
|
31
|
-
artifactPackageName = process.argv[4]
|
|
32
|
-
artifactPackageVersion = process.argv[5]
|
|
33
|
-
filteredArtifactSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
34
|
-
const flattenedArtifactsSchema = flattenArtifactsSchema( filteredArtifactSchema )
|
|
35
|
-
filteredArtifactSchema = flattenedArtifactsSchema.filter(
|
|
23
|
+
const artifactsSchema = await getArtifactsSchema( artifactsYmlPath )
|
|
24
|
+
const flattenedArtifactsSchema = flattenArtifactsSchema( artifactsSchema )
|
|
25
|
+
|
|
26
|
+
let filteredArtifactsSchema
|
|
27
|
+
if ( artifactPackageName && artifactPackageVersion ) {
|
|
28
|
+
filteredArtifactsSchema = flattenedArtifactsSchema.filter(
|
|
36
29
|
artifact => artifact.gcp_artifact_registry_package_name === artifactPackageName &&
|
|
37
30
|
artifact.gcp_artifact_registry_package_version === artifactPackageVersion )
|
|
31
|
+
} else if ( artifactPackageName ) {
|
|
32
|
+
filteredArtifactsSchema = flattenedArtifactsSchema.filter(
|
|
33
|
+
artifact => artifact.gcp_artifact_registry_package_name === artifactPackageName )
|
|
38
34
|
} else {
|
|
39
|
-
|
|
40
|
-
console.error( ' push-artifact.mjs <artifacts.yml>' )
|
|
41
|
-
console.error( ' push-artifact.mjs <artifacts.yml> <artifact name>' )
|
|
42
|
-
console.error( ' push-artifact.mjs <artifacts.yml> <artifact package name> <artifact package version>' )
|
|
43
|
-
process.exit( 1 )
|
|
35
|
+
filteredArtifactsSchema = flattenedArtifactsSchema
|
|
44
36
|
}
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
let counter = 0
|
|
39
|
+
|
|
40
|
+
const pushResults = await Promise.all(
|
|
41
|
+
filteredArtifactsSchema.map( async ( artifactSchema ) => {
|
|
42
|
+
let pusher
|
|
43
|
+
switch ( artifactSchema.type ) {
|
|
44
|
+
case ArtifactTypeEnum.GENERIC:
|
|
45
|
+
pusher = new GenericArtifactPusher( artifactSchema )
|
|
46
|
+
break
|
|
47
|
+
default:
|
|
48
|
+
warning( `Unsupported artifact type "${artifactSchema.type}"` )
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( !pusher ) {
|
|
54
53
|
warning( `Unsupported artifact type "${artifactSchema.type}"` )
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
return await pusher.push()
|
|
59
|
+
} catch ( error ) {
|
|
60
|
+
warning( `Error pushing artifact "${artifactSchema.name}": ${error.message}` )
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
} )
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
counter = pushResults.filter( Boolean ).length
|
|
67
|
+
|
|
68
|
+
log( `Successfully pushed ${counter}/${filteredArtifactsSchema.length} artifacts` )
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
main()
|