diff --git a/src/verify.ts b/src/verify.ts index 3f6578d8..0ce9ccc7 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -8,10 +8,8 @@ const SRError = require("@semantic-release/error"); export const verify = async (pluginConfig: Config & UserConfig, _context: Context): Promise => { const errors: Error[] = []; - for (const envVar of ["NUGET_TOKEN"]) { - if (!process.env[envVar]) { - errors.push(new Error(`Environment variable ${envVar} is not set.`)); - } + if (!pluginConfig.skipPublishToNuget && !process.env["NUGET_TOKEN"]) { + errors.push(new Error("Environment variable NUGET_TOKEN is not set.")); } if (pluginConfig.publishToGitLab) { diff --git a/test/verify.test.ts b/test/verify.test.ts index 39c7e9ff..e8f21249 100644 --- a/test/verify.test.ts +++ b/test/verify.test.ts @@ -143,4 +143,18 @@ describe("verify", () => { expect(actualErr).toBeDefined(); expect(actualErr?.details).toBe("Unable to find dotnet executable in dotnet"); }); + + it("should not complain about missing NUGET_TOKEN when skipPublishToNuget is true", async () => { + delete process.env.NUGET_TOKEN; + process.env.CI_SERVER_URL = "gitlab.com"; + process.env.CI_PROJECT_ID = "132"; + process.env.CI_JOB_TOKEN = "a3lhjli"; + + const promise = verify( + { projectPath: "test/fixture/some.csproj", skipPublishToNuget: true, publishToGitLab: true } as UserConfig, + context, + ); + + await expect(promise).resolves.toBeUndefined(); + }); });