@leverege/build-tools 2.93.0-beta.8 → 2.93.0-pedro.1

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.93.0-beta.8",
3
+ "version": "2.93.0-pedro.1",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -50,13 +50,12 @@
50
50
  "npm-link": "src/npm-link.sh",
51
51
  "npm-unlink": "src/npm-unlink.sh",
52
52
  "overwhelm": "src/overwhelm.mjs",
53
+ "package-artifact": "src/package-artifact/command.mjs",
53
54
  "pkgck": "src/pkgck.sh",
54
55
  "pkglint": "src/pkglint.sh",
55
56
  "prepack": "src/prepack.mjs",
56
57
  "prune-git": "src/prune-git.sh",
57
- "pull-artifact": "src/artifacts/pull-artifact.mjs",
58
58
  "pull-git": "src/pull-git.sh",
59
- "push-artifact": "src/artifacts/push-artifact.mjs",
60
59
  "push-my-chart": "src/push-my-chart.mjs",
61
60
  "refresh-npm-token": "src/refresh-npm-token.mjs",
62
61
  "refresh-py-idx": "src/refresh-py-idx.sh",
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto'
2
2
  import fs from 'fs'
3
3
 
4
- class ArtifactPusher {
4
+ class ArtifactPackager {
5
5
  constructor( artifact ) {
6
6
  this.artifact = artifact
7
7
  }
@@ -12,7 +12,6 @@ class ArtifactPusher {
12
12
  hash.update( fs.readFileSync( this.artifact.source_path ) )
13
13
  return hash.digest( 'base64url' )
14
14
  } catch ( error ) {
15
- console.error( error )
16
15
  throw new Error( `Failed to calculate hash for artifact ${this.artifact.name}: ${error.message}` )
17
16
  }
18
17
  }
@@ -21,24 +20,27 @@ class ArtifactPusher {
21
20
  throw new Error( 'Not implemented' )
22
21
  }
23
22
 
24
- async push() {
23
+ async build() {
25
24
  throw new Error( 'Not implemented' )
26
25
  }
27
- }
28
26
 
29
- class GenericArtifactPusher extends ArtifactPusher {
27
+ async publish() {
28
+ throw new Error( 'Not implemented' )
29
+ }
30
30
 
31
- async exists() {
32
- const isDirectory = fs.statSync( this.artifact.source_path ).isDirectory()
33
-
34
- // If source path is a directory, check whether the destination path alreadu exists in the registry
35
- if ( isDirectory ) {
36
- // For the time being, return false, and let gcloud skip existing files in upload-time.
37
- // It's pretty slow, might be worth to break down the directory into individual artifacts
38
- // and manage each one with its own pusher.
31
+ async package() {
32
+ if ( await this.exists() ) {
33
+ console.log( 'Artifact already exists in the registry' )
39
34
  return false
40
35
  }
36
+ await this.build()
37
+ return this.publish()
38
+ }
39
+ }
40
+
41
+ class GenericArtifactPackager extends ArtifactPackager {
41
42
 
43
+ async exists() {
42
44
  // Check if artifact already exists in the registry
43
45
  console.log( 'Checking if artifact already exists in the registry...' )
44
46
 
@@ -82,37 +84,22 @@ class GenericArtifactPusher extends ArtifactPusher {
82
84
  throw error
83
85
  }
84
86
  }
87
+
88
+ async build() {
89
+ return true
90
+ }
85
91
 
86
- async push() {
92
+ async publish() {
87
93
  console.log( 'Publishing artifact to registry...' )
88
-
89
- if ( await this.exists() ) {
90
- console.log( 'Artifact already exists in the registry' )
91
- return false
92
- }
93
-
94
- console.log( 'Uploading artifact to registry...' )
95
-
96
- let command = ''
97
-
98
- command = `gcloud artifacts generic upload \
99
- --project=${this.artifact.gcp_project_id} \
100
- --location=${this.artifact.gcp_location} \
101
- --repository=${this.artifact.gcp_artifact_registry_repository_name} \
102
- --package=${this.artifact.gcp_artifact_registry_package_name} \
103
- --version=${this.artifact.gcp_artifact_registry_package_version}`
104
-
105
- const isDirectory = fs.statSync( this.artifact.source_path ).isDirectory()
106
- if ( isDirectory ) {
107
- command += ` --source-directory=${this.artifact.source_path}`
108
- command += ' --skip-existing'
109
- } else {
110
- command += ` --source=${this.artifact.source_path}`
111
- }
112
-
113
- if ( this.artifact.destination_path ) {
114
- command += ` --destination-path=${this.artifact.destination_path}`
115
- }
94
+
95
+ const command = `gcloud artifacts generic upload \
96
+ --project=${this.artifact.gcp_project_id} \
97
+ --location=${this.artifact.gcp_location} \
98
+ --repository=${this.artifact.gcp_artifact_registry_repository_name} \
99
+ --package=${this.artifact.gcp_artifact_registry_package_name} \
100
+ --version=${this.artifact.gcp_artifact_registry_package_version} \
101
+ --source=${this.artifact.source_path} \
102
+ --destination-path=${this.artifact.destination_path}`
116
103
 
117
104
  // console.log( 'Command:', command )
118
105
 
@@ -128,4 +115,4 @@ class GenericArtifactPusher extends ArtifactPusher {
128
115
  }
129
116
  }
130
117
 
131
- export { ArtifactPusher, GenericArtifactPusher }
118
+ export { ArtifactPackager, GenericArtifactPackager }
@@ -1,13 +1,11 @@
1
1
  import { assign, object, string, array, optional, enums, union } from 'superstruct'
2
2
 
3
- const ArtifactTypeEnum = {
4
- GENERIC : 'generic',
5
- }
3
+ const ArtifactTypeEnum = enums( [ 'generic' ] )
6
4
 
7
5
  // Superstruct schema for individual artifact configuration
8
- const PartialArtifactSchema = object( {
6
+ const PartialArtifactEntrySchema = object( {
9
7
  name : string(),
10
- type : optional( enums( Object.values( ArtifactTypeEnum ) ) ),
8
+ type : optional( ArtifactTypeEnum ),
11
9
  gcp_project_id : optional( string() ),
12
10
  gcp_location : optional( string() ),
13
11
  gcp_artifact_registry_repository_name : optional( string() ),
@@ -15,9 +13,9 @@ const PartialArtifactSchema = object( {
15
13
  gcp_artifact_registry_package_version : optional( string() )
16
14
  } )
17
15
 
18
- const ArtifactSchema = assign( PartialArtifactSchema, object( {
16
+ const ArtifactEntrySchema = assign( PartialArtifactEntrySchema, object( {
19
17
  name : string(),
20
- type : enums( Object.values( ArtifactTypeEnum ) ),
18
+ type : ArtifactTypeEnum,
21
19
  gcp_project_id : string(),
22
20
  gcp_location : string(),
23
21
  gcp_artifact_registry_repository_name : string(),
@@ -25,15 +23,15 @@ const ArtifactSchema = assign( PartialArtifactSchema, object( {
25
23
  gcp_artifact_registry_package_version : string()
26
24
  } ) )
27
25
 
28
- const PartialGenericArtifactSchema = assign( PartialArtifactSchema, object( {
29
- type : enums( [ ArtifactTypeEnum.GENERIC ] ),
26
+ const PartialGenericArtifactEntrySchema = assign( PartialArtifactEntrySchema, object( {
27
+ type : enums( [ 'generic' ] ),
30
28
  source_path : string(),
31
29
  destination_path : string()
32
30
  } ) )
33
31
 
34
- const GenericArtifactSchema = assign( ArtifactSchema, object( {
32
+ const GenericArtifactEntrySchema = assign( ArtifactEntrySchema, object( {
35
33
  source_path : string(),
36
- destination_path : optional( string() )
34
+ destination_path : string()
37
35
  } ) )
38
36
 
39
37
  // Superstruct schema for defaults configuration
@@ -46,18 +44,17 @@ const DefaultsSchema = object( {
46
44
  } )
47
45
 
48
46
  // Superstruct schema for the complete artifacts configuration with defaults
49
- const ArtifactsSchema = object( {
50
- defaults : optional( DefaultsSchema ),
51
- artifacts : array( union( [ PartialArtifactSchema, PartialGenericArtifactSchema ] ) )
47
+ const ArtifactEntriesSchema = object( {
48
+ defaults : DefaultsSchema,
49
+ artifacts : array( union( [ PartialArtifactEntrySchema, PartialGenericArtifactEntrySchema ] ) )
52
50
  } )
53
51
 
54
- const FlattenedArtifactsSchema = array( assign( union( [ ArtifactSchema, GenericArtifactSchema ] ) ) )
52
+ const FlattenedArtifactEntriesSchema = array( assign( union( [ ArtifactEntrySchema, GenericArtifactEntrySchema ] ) ) )
55
53
 
56
54
  export {
57
- ArtifactTypeEnum,
58
- ArtifactsSchema,
59
- FlattenedArtifactsSchema,
60
- ArtifactSchema,
55
+ ArtifactEntriesSchema,
56
+ FlattenedArtifactEntriesSchema,
57
+ ArtifactEntrySchema,
61
58
  DefaultsSchema,
62
- GenericArtifactSchema,
59
+ GenericArtifactEntrySchema,
63
60
  }
@@ -2,18 +2,18 @@ import { validate } from 'superstruct'
2
2
 
3
3
  import { parseYamlFile, warning } from '../Utils.mjs'
4
4
 
5
- import { ArtifactTypeEnum, ArtifactsSchema, GenericArtifactSchema } from './Structs.mjs'
5
+ import { ArtifactEntriesSchema, GenericArtifactEntrySchema } from './Structs.mjs'
6
6
 
7
- const getArtifactsSchema = async ( artifactsFilePath = './artifacts.yml' ) => {
8
- const artifactsConfig = await parseYamlFile( artifactsFilePath )
9
- const [ error, result ] = validate( artifactsConfig, ArtifactsSchema )
7
+ const getArtifactEntriesSchema = async ( artifactsConfigPath = './artifacts.yml' ) => {
8
+ const artifactsConfig = await parseYamlFile( artifactsConfigPath )
9
+ const [ error, result ] = validate( artifactsConfig, ArtifactEntriesSchema )
10
10
  if ( error ) {
11
11
  throw new Error( `Invalid artifacts.yml file: ${error.message}` )
12
12
  }
13
13
  return result
14
14
  }
15
15
 
16
- const flattenArtifactsSchema = ( artifactsSchema ) => {
16
+ const flattenArtifactEntriesSchema = ( artifactsSchema ) => {
17
17
  return artifactsSchema.artifacts.reduce( ( flattenedArtifacts, artifact ) => {
18
18
  const mergedArtifact = {
19
19
  ...artifactsSchema.defaults,
@@ -22,8 +22,8 @@ const flattenArtifactsSchema = ( artifactsSchema ) => {
22
22
 
23
23
  let schema
24
24
  switch ( mergedArtifact.type ) {
25
- case ArtifactTypeEnum.GENERIC:
26
- schema = GenericArtifactSchema
25
+ case 'generic':
26
+ schema = GenericArtifactEntrySchema
27
27
  break
28
28
  default:
29
29
  warning( `Unsupported artifact type "${mergedArtifact.type}"` )
@@ -46,4 +46,4 @@ const flattenArtifactsSchema = ( artifactsSchema ) => {
46
46
  }, [] )
47
47
  }
48
48
 
49
- export { getArtifactsSchema, flattenArtifactsSchema }
49
+ export { getArtifactEntriesSchema, flattenArtifactEntriesSchema }
@@ -1,10 +1,7 @@
1
- #!/usr/bin/env node
2
-
3
1
  import { warning } from '../Utils.mjs'
4
2
 
5
- import { getArtifactsSchema, flattenArtifactsSchema } from './Utils.mjs'
6
- import { ArtifactTypeEnum } from './Structs.mjs'
7
- import { GenericArtifactPusher } from './ArtifactPusher.mjs'
3
+ import { getArtifactEntriesSchema, flattenArtifactEntriesSchema } from './Utils.mjs'
4
+ import { GenericArtifactEntryPackager } from './Packager.mjs'
8
5
 
9
6
  async function main() {
10
7
 
@@ -14,8 +11,8 @@ async function main() {
14
11
  const artifactPackageVersion = process.argv[4]
15
12
 
16
13
  if ( artifactsYmlPath ) {
17
- const artifactsSchema = await getArtifactsSchema( artifactsYmlPath )
18
- const flattenedArtifactsSchema = flattenArtifactsSchema( artifactsSchema )
14
+ const artifactsSchema = await getArtifactEntriesSchema( artifactsYmlPath )
15
+ const flattenedArtifactsSchema = flattenArtifactEntriesSchema( artifactsSchema )
19
16
 
20
17
  // Open for unexpected matches if we end up re-using the same package name and version for
21
18
  // multiple artifacts spread across multiple repositories and/or projects.
@@ -24,16 +21,14 @@ async function main() {
24
21
  artifact.gcp_artifact_registry_package_version === artifactPackageVersion )
25
22
 
26
23
  if ( filteredArtifactSchemas.length === 0 ) {
27
- console.error( `No artifacts found for ${artifactPackageName} version ${artifactPackageVersion} in ${artifactsYmlPath}` )
24
+ console.error( `No artifact entries found for ${artifactPackageName} version ${artifactPackageVersion} in ${artifactsYmlPath}` )
28
25
  process.exit( 1 )
29
26
  }
30
-
31
- // TODO: Use concurrency to package artifacts and provide summary of results.
32
27
  for ( const artifactSchema of filteredArtifactSchemas ) {
33
28
  let packager
34
29
  switch ( artifactSchema.type ) {
35
- case ArtifactTypeEnum.GENERIC:
36
- packager = new GenericArtifactPusher( artifactSchema )
30
+ case 'generic':
31
+ packager = new GenericArtifactEntryPackager( artifactSchema )
37
32
  break
38
33
  default:
39
34
  warning( `Unsupported artifact type "${artifactSchema.type}"` )
@@ -1,21 +0,0 @@
1
- import crypto from 'crypto'
2
- import fs from 'fs'
3
-
4
- class ArtifactPusher {
5
- constructor( artifact ) {
6
- this.artifact = artifact
7
- }
8
-
9
- async pull() {
10
- throw new Error( 'Not implemented' )
11
- }
12
- }
13
-
14
- class GenericArtifactPusher extends ArtifactPusher {
15
-
16
- async pull() {
17
- throw new Error( 'Not implemented' )
18
- }
19
- }
20
-
21
- export { ArtifactPusher, GenericArtifactPusher }
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- async function main() {
4
- return null
5
- }
6
-
7
- main()