Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Publish artifacts with source branch as the NPM tag (#513)
Browse files Browse the repository at this point in the history
* Publish artifacts with source branch as the NPM tag

Remove validation of artifact version in release definition

* Remove tests for artifact version validation
  • Loading branch information
aly76 authored May 6, 2021
1 parent 09bb61f commit 86f4799
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"type": "object",
"patternProperties": {
".+": {
"type": "string",
"pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$)|^LATEST_TAG$|^[a-zA-Z0-9]+$"
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ export default class Promote extends SfpowerscriptsCommand {
}

try {
console.log(`Publishing ${packageName} Version ${packageVersionNumber}...`);

if (this.flags.npm) {
this.publishUsingNpm(
sourceDirectory,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 86f4799

Please sign in to comment.