Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to restrict publishing to greater package version only #44

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding new option and parsing
  • Loading branch information
Tohaker committed Sep 13, 2021
commit b7c6f3069d6353801666e0981f10f4e3d4bd636a
25 changes: 15 additions & 10 deletions src/action/index.ts
Original file line number Diff line number Diff line change
@@ -17,24 +17,30 @@ async function main(): Promise<void> {
token: getInput("token", { required: true }),
registry: getInput("registry", { required: true }),
package: getInput("package", { required: true }),
checkVersion: getInput("check-version", { required: true }).toLowerCase() === "true",
checkVersion:
getInput("check-version", { required: true }).toLowerCase() === "true",
tag: getInput("tag"),
access: getInput("access") as Access,
dryRun: getInput("dry-run").toLowerCase() === "true",
greaterVersion: getInput("greater-version").toLowerCase() === "true",
debug: debugHandler,
};

// Publish to NPM
let results = await npmPublish(options);

if (results.type === "none") {
console.log(`\n📦 ${results.package} v${results.version} is already published to NPM`);
}
else if (results.dryRun) {
console.log(`\n📦 ${results.package} v${results.version} was NOT actually published to NPM (dry run)`);
}
else {
console.log(`\n📦 Successfully published ${results.package} v${results.version} to NPM`);
console.log(
`\n📦 ${results.package} v${results.version} is already published to NPM`
);
} else if (results.dryRun) {
console.log(
`\n📦 ${results.package} v${results.version} was NOT actually published to NPM (dry run)`
);
} else {
console.log(
`\n📦 Successfully published ${results.package} v${results.version} to NPM`
);
}

// Set the GitHub Actions output variables
@@ -44,8 +50,7 @@ async function main(): Promise<void> {
setOutput("tag", results.tag);
setOutput("access", results.access);
setOutput("dry-run", results.dryRun);
}
catch (error) {
} catch (error) {
errorHandler(error as Error);
}
}
13 changes: 11 additions & 2 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ export interface NormalizedOptions {
access?: Access;
dryRun: boolean;
checkVersion: boolean;
greaterVersion: boolean;
quiet: boolean;
debug: Debug;
}
@@ -22,7 +23,10 @@ export interface NormalizedOptions {
* @internal
*/
export function normalizeOptions(options: Options): NormalizedOptions {
let registryURL = typeof options.registry === "string" ? new URL(options.registry) : options.registry;
let registryURL =
typeof options.registry === "string"
? new URL(options.registry)
: options.registry;

return {
token: options.token || "",
@@ -31,7 +35,12 @@ export function normalizeOptions(options: Options): NormalizedOptions {
tag: options.tag || "latest",
access: options.access,
dryRun: options.dryRun || false,
checkVersion: options.checkVersion === undefined ? true : Boolean(options.checkVersion),
checkVersion:
options.checkVersion === undefined ? true : Boolean(options.checkVersion),
greaterVersion:
options.greaterVersion === undefined
? false
: Boolean(options.greaterVersion),
quiet: options.quiet || false,
debug: options.debug || (() => undefined),
};
8 changes: 8 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -64,6 +64,14 @@ export interface Options {
*/
quiet?: boolean;

/**
* Only publish the package if the version number in package.json
* is greater than the latest on NPM.
*
* Defaults to `false`
*/
greaterVersion?: boolean;

/**
* A function to call to log debug messages.
*