Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 29 additions & 10 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ jobs:
- macos-latest
- windows-latest
node-version:
- 16
- 18
- 20
- "16"
- "18"
- "20"
- "22"
- "24"

steps:
- name: Checkout source
Expand Down Expand Up @@ -107,9 +109,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 18
- 20
- "16"
- "18"
- "20"
- "22"
- "24"

services:
verdaccio:
Expand Down Expand Up @@ -173,6 +177,21 @@ jobs:
shell: bash
run: ./e2e/01-setup-package.sh "${{ steps.setup.outputs.package }}" 0.0.3

- id: action-publish-dry-before
name: Publish a dry run before publish
uses: ./
with:
registry: http://localhost:4873
package: ${{ steps.setup.outputs.package }}/package.json
token: ${{ steps.setup.outputs.token }}
dry-run: true

- name: Check release output
if: ${{ steps.action-publish-dry-before.outputs.type != 'patch' }}
run: |
echo "::error::Expected release type to be 'patch', got '${{ steps.action-publish-dry-before.outputs.type }}'"
exit 1

- id: action-publish
name: Publish a new version
uses: ./
Expand All @@ -187,8 +206,8 @@ jobs:
echo "::error::Expected release type to be 'patch', got '${{ steps.action-publish.outputs.type }}'"
exit 1

- id: action-publish-dry
name: Publish a dry run
- id: action-publish-dry-after
name: Publish a dry run after publish
uses: ./
with:
registry: http://localhost:4873
Expand All @@ -197,9 +216,9 @@ jobs:
dry-run: true

- name: Check release output
if: ${{ steps.action-publish-dry.outputs.type }}
if: ${{ steps.action-publish-dry-after.outputs.type }}
run: |
echo "::error::Expected release type to be '', got '${{ steps.action-publish-dry.outputs.type }}'"
echo "::error::Expected release type to be '', got '${{ steps.action-publish-dry-after.outputs.type }}'"
exit 1

deploy:
Expand Down
5 changes: 3 additions & 2 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/main.js.map

Large diffs are not rendered by default.

53 changes: 28 additions & 25 deletions src/compare-and-publish/__tests__/compare-and-publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,32 +224,35 @@ describe("compareAndPublish", () => {
await expect(result).rejects.toThrow(errors.NpmCallError);
});

it("should allow an EPUBLISHCONFLICT from npm publish", async () => {
when(callNpmCli<"publish">)
.calledWith("publish", ["."], {
logger,
environment,
ignoreScripts: false,
})
.thenResolve({
successData: undefined,
errorCode: "EPUBLISHCONFLICT",
error: new errors.NpmCallError("publish", 1, "oh no"),
it.each(["EPUBLISHCONFLICT", "E409"])(
"should allow an %s error from npm publish",
async (errorCode) => {
when(callNpmCli<"publish">)
.calledWith("publish", ["."], {
logger,
environment,
ignoreScripts: false,
})
.thenResolve({
successData: undefined,
errorCode,
error: new errors.NpmCallError("publish", 1, "oh no"),
});

const result = await subject.compareAndPublish(
manifest,
normalizedOptions,
environment
);

expect(result).toEqual({
id: undefined,
files: [],
oldVersion: "0.0.1",
type: undefined,
});

const result = await subject.compareAndPublish(
manifest,
normalizedOptions,
environment
);

expect(result).toEqual({
id: undefined,
files: [],
oldVersion: "0.0.1",
type: undefined,
});
});
}
);

it("should raise a non-EPUBLISHCONFLIG from npm publish", async () => {
when(callNpmCli<"publish">)
Expand Down
1 change: 1 addition & 0 deletions src/compare-and-publish/__tests__/get-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("get command arguments", () => {
"restricted",
"--provenance",
"--dry-run",
"--force",
]);
});

Expand Down
7 changes: 6 additions & 1 deletion src/compare-and-publish/compare-and-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
VIEW,
PUBLISH,
E404,
E409,
EPUBLISHCONFLICT,
callNpmCli,
type NpmCliEnvironment,
Expand Down Expand Up @@ -66,7 +67,11 @@ export async function compareAndPublish(
? await callNpmCli(PUBLISH, publishArguments, cliOptions)
: { successData: undefined, errorCode: undefined, error: undefined };

if (publishCall.error && publishCall.errorCode !== EPUBLISHCONFLICT) {
if (
publishCall.error &&
publishCall.errorCode !== EPUBLISHCONFLICT &&
publishCall.errorCode !== E409
) {
throw publishCall.error;
}

Expand Down
5 changes: 4 additions & 1 deletion src/compare-and-publish/get-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function getPublishArguments(
}

if (!dryRun.isDefault && dryRun.value) {
publishArguments.push("--dry-run");
// NOTE: `--force` does not override `--dry-run`,
// but does bypass package existence check in npm >=11
// because we do our own existence checks separately
publishArguments.push("--dry-run", "--force");
}

return publishArguments;
Expand Down
1 change: 1 addition & 0 deletions src/npm/call-npm-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const VIEW = "view";
export const PUBLISH = "publish";

export const E404 = "E404";
export const E409 = "E409";
export const EPUBLISHCONFLICT = "EPUBLISHCONFLICT";

const IS_WINDOWS = os.platform() === "win32";
Expand Down
Loading