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
Prev Previous commit
Next Next commit
Changing flag to be clearer
  • Loading branch information
Tohaker committed Sep 14, 2021
commit 18930aa589ee6b5fc2c7959c9eed5009e04b901d
2 changes: 1 addition & 1 deletion src/action/index.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ async function main(): Promise<void> {
tag: getInput("tag"),
access: getInput("access") as Access,
dryRun: getInput("dry-run").toLowerCase() === "true",
greaterVersion: getInput("greater-version").toLowerCase() === "true",
greaterVersionOnly: getInput("greater-version-only").toLowerCase() === "true",
debug: debugHandler,
};

8 changes: 4 additions & 4 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export interface NormalizedOptions {
access?: Access;
dryRun: boolean;
checkVersion: boolean;
greaterVersion: boolean;
greaterVersionOnly: boolean;
quiet: boolean;
debug: Debug;
}
@@ -37,10 +37,10 @@ export function normalizeOptions(options: Options): NormalizedOptions {
dryRun: options.dryRun || false,
checkVersion:
options.checkVersion === undefined ? true : Boolean(options.checkVersion),
greaterVersion:
options.greaterVersion === undefined
greaterVersionOnly:
options.greaterVersionOnly === undefined
? false
: Boolean(options.greaterVersion),
: Boolean(options.greaterVersionOnly),
quiet: options.quiet || false,
debug: options.debug || (() => undefined),
};
10 changes: 4 additions & 6 deletions src/npm-publish.ts
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ export async function npmPublish(opts: Options = {}): Promise<Results> {
let shouldPublish =
!options.checkVersion ||
// compare returns 1 if manifest is higher than published
(options.greaterVersion && cmp === 1) ||
(options.greaterVersionOnly && cmp === 1) ||
// compare returns 0 if the manifest is the same as published
cmp !== 0;

@@ -33,13 +33,11 @@ export async function npmPublish(opts: Options = {}): Promise<Results> {
await npm.publish(manifest, options);
}

// The version should be marked as lower if we disallow decrementing the version
let type =
(options.greaterVersion && cmp === -1 && "lower") || diff || "none";

let results: Results = {
package: manifest.name,
type,
// The version should be marked as lower if we disallow decrementing the version
type:
(options.greaterVersionOnly && cmp === -1 && "lower") || diff || "none",
version: manifest.version.raw,
oldVersion: publishedVersion.raw,
tag: options.tag,
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ export interface Options {
*
* Defaults to `false`
*/
greaterVersion?: boolean;
greaterVersionOnly?: boolean;

/**
* A function to call to log debug messages.
2 changes: 1 addition & 1 deletion test/specs/action/success.spec.js
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ describe("GitHub Action - success tests", () => {
let cli = exec.action({
env: {
INPUT_TOKEN: "my-secret-token",
"INPUT_GREATER-VERSION": "true",
"INPUT_GREATER-VERSION-ONLY": "true",
},
});