Skip to content

Commit

Permalink
fix: use PAT due to branch protection (#17)
Browse files Browse the repository at this point in the history
Also some more logging
  • Loading branch information
hongaar authored Dec 8, 2022
1 parent 4136a90 commit 0576ddc
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
- run: yarn build
- run: yarn release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_PAT }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## [0.2.1](https://github.com/hongaar/semantic-release-yarn/compare/v0.2.0...v0.2.1) (2022-12-07)


### Bug Fixes

* don't run husky install on postinstall ([6d541a4](https://github.com/hongaar/semantic-release-yarn/commit/6d541a479afdf63062c51d05ba414d2477421f2b))
- don't run husky install on postinstall
([6d541a4](https://github.com/hongaar/semantic-release-yarn/commit/6d541a479afdf63062c51d05ba414d2477421f2b))

# [0.2.0](https://github.com/hongaar/semantic-release-yarn/compare/v0.1.1...v0.2.0) (2022-12-07)

Expand Down
66 changes: 56 additions & 10 deletions src/get-registry.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
import type { PackageJson } from "read-pkg";
import { DEFAULT_NPM_REGISTRY } from "./definitions/constants.js";
import {
DEFAULT_NPM_REGISTRY,
YARNRC_FILENAME,
} from "./definitions/constants.js";
import type { CommonContext } from "./definitions/context.js";
import type { Yarnrc } from "./definitions/yarnrc.js";

export function getRegistry(
{ publishConfig }: PackageJson,
{ npmRegistryServer, npmPublishRegistry }: Yarnrc,
{ env }: { env?: CommonContext["env"] }
{
env,
logger,
}: { env: CommonContext["env"]; logger: CommonContext["logger"] }
) {
const publishConfigRegistry = publishConfig?.["registry"] as
| string
| undefined;

return (
publishConfigRegistry ||
env?.["YARN_NPM_PUBLISH_REGISTRY"] ||
npmPublishRegistry ||
env?.["YARN_NPM_REGISTRY_SERVER"] ||
npmRegistryServer ||
DEFAULT_NPM_REGISTRY
);
if (publishConfigRegistry) {
logger.log(
`Using registry "%s" from "package.json: publishConfig.registry"`,
publishConfigRegistry
);

return publishConfigRegistry;
}

if (env["YARN_NPM_PUBLISH_REGISTRY"]) {
logger.log(
`Using registry "%s" from environment variable YARN_NPM_PUBLISH_REGISTRY`,
env["YARN_NPM_PUBLISH_REGISTRY"]
);

return env["YARN_NPM_PUBLISH_REGISTRY"];
}

if (npmPublishRegistry) {
logger.log(
`Using registry "%s" from "${YARNRC_FILENAME}: npmPublishRegistry"`,
npmPublishRegistry
);

return npmPublishRegistry;
}

if (env["YARN_NPM_REGISTRY_SERVER"]) {
logger.log(
`Using registry "%s" from environment variable YARN_NPM_REGISTRY_SERVER`,
env["YARN_NPM_REGISTRY_SERVER"]
);

return env["YARN_NPM_REGISTRY_SERVER"];
}

if (npmRegistryServer) {
logger.log(
`Using registry "%s" from "${YARNRC_FILENAME}: npmRegistryServer"`,
npmRegistryServer
);

return npmRegistryServer;
}

logger.log(`Using default registry "%s"`, DEFAULT_NPM_REGISTRY);

return DEFAULT_NPM_REGISTRY;
}
2 changes: 1 addition & 1 deletion src/get-yarn-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getYarnConfig({
return {};
}

logger.log("Reading yarn config from %s", result.files.join(", "));
logger.log('Reading yarn config from "%s"', result.files.join(", "));

return result.config;
}
Expand Down
38 changes: 27 additions & 11 deletions test/get-registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
import test from "ava";
import { getRegistry } from "../src/get-registry.js";
import { createContext } from "./helpers/create-context.js";

test("Get default registry", async (t) => {
t.is(getRegistry({}, {}, {}), "https://registry.npmjs.org");
const context = createContext();

t.is(getRegistry({}, {}, context), "https://registry.npmjs.org");
t.is(
getRegistry({ publishConfig: {} }, {}, {}),
getRegistry({ publishConfig: {} }, {}, context),
"https://registry.npmjs.org"
);
t.is(
getRegistry({}, { npmPublishRegistry: "" }, {}),
getRegistry({}, { npmPublishRegistry: "" }, context),
"https://registry.npmjs.org"
);
t.is(
getRegistry({}, { npmRegistryServer: "" }, {}),
getRegistry({}, { npmRegistryServer: "" }, context),
"https://registry.npmjs.org"
);
t.is(getRegistry({}, {}, { env: {} }), "https://registry.npmjs.org");
t.is(getRegistry({}, {}, context), "https://registry.npmjs.org");
t.is(
getRegistry({}, {}, { env: { YARN_NPM_PUBLISH_REGISTRY: "" } }),
getRegistry({}, {}, { ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "" } }),
"https://registry.npmjs.org"
);
t.is(
getRegistry({}, {}, { env: { YARN_NPM_REGISTRY_SERVER: "" } }),
getRegistry({}, {}, { ...context, env: { YARN_NPM_REGISTRY_SERVER: "" } }),
"https://registry.npmjs.org"
);
});

test("Get registry from yarnrc", async (t) => {
const context = createContext();

t.is(
getRegistry(
{},
{
npmPublishRegistry: "https://custom1.registry.com",
},
{}
context
),
"https://custom1.registry.com"
);
Expand All @@ -43,7 +48,7 @@ test("Get registry from yarnrc", async (t) => {
{
npmRegistryServer: "https://custom1.registry.com",
},
{}
context
),
"https://custom1.registry.com"
);
Expand All @@ -54,18 +59,21 @@ test("Get registry from yarnrc", async (t) => {
npmPublishRegistry: "https://custom1.registry.com",
npmRegistryServer: "https://custom2.registry.com",
},
{}
context
),
"https://custom1.registry.com"
);
});

test("Get registry from environment variables", async (t) => {
const context = createContext();

t.is(
getRegistry(
{},
{},
{
...context,
env: { YARN_NPM_PUBLISH_REGISTRY: "https://custom1.registry.com" },
}
),
Expand All @@ -76,6 +84,7 @@ test("Get registry from environment variables", async (t) => {
{},
{},
{
...context,
env: { YARN_NPM_REGISTRY_SERVER: "https://custom1.registry.com" },
}
),
Expand All @@ -86,6 +95,7 @@ test("Get registry from environment variables", async (t) => {
{},
{},
{
...context,
env: {
YARN_NPM_PUBLISH_REGISTRY: "https://custom1.registry.com",
YARN_NPM_REGISTRY_SERVER: "https://custom2.registry.com",
Expand All @@ -97,24 +107,29 @@ test("Get registry from environment variables", async (t) => {
});

test("Get registry from publishConfig", async (t) => {
const context = createContext();

t.is(
getRegistry(
{ publishConfig: { registry: "https://custom1.registry.com" } },
{},
{}
context
),
"https://custom1.registry.com"
);
});

test("Precedence: publishConfig > environment variables > yarnrc", async (t) => {
const context = createContext();

t.is(
getRegistry(
{ publishConfig: { registry: "https://custom1.registry.com" } },
{
npmPublishRegistry: "https://custom2.registry.com",
},
{
...context,
env: {
YARN_NPM_PUBLISH_REGISTRY: "https://custom3.registry.com",
},
Expand All @@ -129,6 +144,7 @@ test("Precedence: publishConfig > environment variables > yarnrc", async (t) =>
npmPublishRegistry: "https://custom1.registry.com",
},
{
...context,
env: {
YARN_NPM_PUBLISH_REGISTRY: "https://custom2.registry.com",
},
Expand Down

0 comments on commit 0576ddc

Please sign in to comment.