Skip to content

Commit

Permalink
ci: add release type to release utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 24, 2023
1 parent e4092ac commit b6f1ac4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scripts/release/LatestRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LatestRelease extends Release {
// Determine version using conventional commits specs.
return "--conventional-commits";
});
this.setCreateGithubRelease(true);
// By setting `latest`, this release will be marked as `latest` on Github
this.setCreateGithubRelease("latest");
}

setTag(tag) {
Expand Down
9 changes: 7 additions & 2 deletions scripts/release/Release.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Release {
this.version = version;
}

/**
* @param {boolean|string} flag Boolean or "latest" to mark release as "latest" on Github
*/
setCreateGithubRelease(flag) {
this.createGithubRelease = flag;
}
Expand Down Expand Up @@ -109,7 +112,7 @@ class Release {
await execa("yarn", lernaPublishArgs, { stdio: "inherit" });
this.logger.info(`Packages were published to NPM under %s dist-tag`, this.tag);

if (this.createGithubRelease) {
if (this.createGithubRelease !== false) {
// Generate changelog, tag commit, and create Github release.
const lernaJSON = await loadJSON("lerna.json");
const versionTag = `v${lernaJSON.version}`;
Expand Down Expand Up @@ -191,7 +194,9 @@ class Release {
tag_name: tag,
name: tag,
body: changelog,
prerelease: false
prerelease: false,
// `make_latest` is of type `string`
make_latest: this.createGithubRelease === "latest" ? "true" : "false"
});
}
}
Expand Down
15 changes: 14 additions & 1 deletion scripts/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ const yargs = require("yargs");
const { ConsoleLogger } = require("../ConsoleLogger");
const { getReleaseType } = require("./releaseTypes");

// Disable default handling of `--version` parameter.
yargs.version(false);

async function runRelease() {
const { type, tag, gitReset } = yargs.argv;
const { type, tag, gitReset, version, createGithubRelease } = yargs.argv;

console.log({ type, tag, gitReset, version });
if (!type) {
throw Error(`Missing required "--type" option.`);
}
Expand All @@ -17,10 +22,18 @@ async function runRelease() {
release.setTag(tag);
}

if (version) {
release.setVersion(version);
}

if (gitReset) {
release.setResetAllChanges(gitReset);
}

if (createGithubRelease) {
release.setCreateGithubRelease(createGithubRelease);
}

await release.execute();
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/release/releaseTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ const { LatestRelease } = require("./LatestRelease");
const { BetaRelease } = require("./BetaRelease");
const { UnstableRelease } = require("./UnstableRelease");
const { VerdaccioRelease } = require("./VerdaccioRelease");
const { Release } = require("./Release");

const releaseTypes = {
latest: LatestRelease,
beta: BetaRelease,
unstable: UnstableRelease,
verdaccio: VerdaccioRelease
verdaccio: VerdaccioRelease,
release: Release
};

const checkReleaseType = type => {
Expand Down

0 comments on commit b6f1ac4

Please sign in to comment.