From 86f4799cd2399bd1fa8bc0809cc85c17513501a9 Mon Sep 17 00:00:00 2001 From: Alan Ly <36793262+aly76@users.noreply.github.com> Date: Thu, 6 May 2021 11:16:06 +1000 Subject: [PATCH] Publish artifacts with source branch as the NPM tag (#513) * Publish artifacts with source branch as the NPM tag Remove validation of artifact version in release definition * Remove tests for artifact version validation --- .../schemas/releasedefinition.schema.json | 3 +- .../sfpowerscripts/orchestrator/publish.ts | 16 +++-- .../impl/release/ReleaseDefinition.test.ts | 65 ------------------- 3 files changed, 13 insertions(+), 71 deletions(-) diff --git a/packages/sfpowerscripts-cli/resources/schemas/releasedefinition.schema.json b/packages/sfpowerscripts-cli/resources/schemas/releasedefinition.schema.json index c2e7a15a6..de71c46bf 100644 --- a/packages/sfpowerscripts-cli/resources/schemas/releasedefinition.schema.json +++ b/packages/sfpowerscripts-cli/resources/schemas/releasedefinition.schema.json @@ -26,8 +26,7 @@ "type": "object", "patternProperties": { ".+": { - "type": "string", - "pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$)|^LATEST_TAG$|^[a-zA-Z0-9]+$" + "type": "string" } } }, diff --git a/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts b/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts index 9fe548bc3..bedfbb54b 100644 --- a/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts +++ b/packages/sfpowerscripts-cli/src/commands/sfpowerscripts/orchestrator/publish.ts @@ -142,8 +142,6 @@ export default class Promote extends SfpowerscriptsCommand { } try { - console.log(`Publishing ${packageName} Version ${packageVersionNumber}...`); - if (this.flags.npm) { this.publishUsingNpm( sourceDirectory, @@ -283,9 +281,18 @@ export default class Promote extends SfpowerscriptsCommand { let cmd = `npm publish`; - if (this.flags.npmtag) - cmd += ` --tag ${this.flags.npmtag}`; + let tag: string; + if (this.flags.npmtag) { + tag = this.flags.npmtag; + } else if (packageMetadata.branch) { + tag = packageMetadata.branch + } else { + throw new Error(`Artifact ${packageName} ${packageVersionNumber} does not contain branch info. Please provide --npmtag flag explicitly, or re-build the artifact with the --branch flag.`); + } + + cmd += ` --tag ${tag}`; + console.log(`Publishing ${packageName} Version ${packageVersionNumber} with tag ${tag}...`); child_process.execSync( cmd, @@ -308,6 +315,7 @@ export default class Promote extends SfpowerscriptsCommand { cmd = `cmd.exe /c ${this.flags.scriptpath} ${packageName} ${packageVersionNumber} ${artifact} ${this.flags.publishpromotedonly}`; } + console.log(`Publishing ${packageName} Version ${packageVersionNumber}...`); child_process.execSync( cmd, diff --git a/packages/sfpowerscripts-cli/tests/impl/release/ReleaseDefinition.test.ts b/packages/sfpowerscripts-cli/tests/impl/release/ReleaseDefinition.test.ts index e31f73bb7..53c70fee0 100644 --- a/packages/sfpowerscripts-cli/tests/impl/release/ReleaseDefinition.test.ts +++ b/packages/sfpowerscripts-cli/tests/impl/release/ReleaseDefinition.test.ts @@ -12,71 +12,6 @@ describe("Given a release definition, validateReleaseDefinition", () => { }); }); - it("should not throw an error for a valid release definition", () => { - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "3.0.5-13" - packageB: "LATEST_TAG" - packageC: "3.0.0" - packageD: "alpha" - PackageE: "ALPHA" - PackageF: "Alpha2" - `; - - expect(() => { new ReleaseDefinition(null); }).not.toThrow(); - }); - - it("should throw an error for incorrect semantic version", () => { - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "3.0.5.10" - `; - - expect(() => { new ReleaseDefinition(null); }).toThrow(); - - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "3.0" - `; - - expect(() => { new ReleaseDefinition(null); }).toThrow(); - - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "3,0.5-10" - `; - - expect(() => { new ReleaseDefinition(null); }).toThrow(); - }); - - it("should throw for incorrectly formatted LATEST_TAG", () => { - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "latest_tag" - `; - - expect(() => { new ReleaseDefinition(null); }).toThrow(); - - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "latest-tag" - `; - expect(() => { new ReleaseDefinition(null); }).toThrow(); - - releaseDefinitionYaml = ` - release: "test-release" - artifacts: - packageA: "LATEST-TAG" - `; - expect(() => { new ReleaseDefinition(null); }).toThrow(); - }); - it("should throw if artifacts field is missing", () => { releaseDefinitionYaml = ` release: "test-release"