Skip to content

Commit 8b28186

Browse files
varlAndarist
andauthored
Use logging provided by @actions/core (#289)
* chore: migrate to logging from @actions/core * Update src/index.ts * Update .changeset/blue-hornets-marry.md --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent ab485bf commit 8b28186

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

.changeset/blue-hornets-marry.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
Use logging provided by `@actions/core`

src/index.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
1616

1717
const inputCwd = core.getInput("cwd");
1818
if (inputCwd) {
19-
console.log("changing directory to the one given as the input");
19+
core.info("changing directory to the one given as the input");
2020
process.chdir(inputCwd);
2121
}
2222

2323
let setupGitUser = core.getBooleanInput("setupGitUser");
2424

2525
if (setupGitUser) {
26-
console.log("setting git user");
26+
core.info("setting git user");
2727
await gitUtils.setupUser();
2828
}
2929

30-
console.log("setting GitHub credentials");
30+
core.info("setting GitHub credentials");
3131
await fs.writeFile(
3232
`${process.env.HOME}/.netrc`,
3333
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
@@ -48,27 +48,27 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
4848

4949
switch (true) {
5050
case !hasChangesets && !hasPublishScript:
51-
console.log("No changesets found");
51+
core.info("No changesets found");
5252
return;
5353
case !hasChangesets && hasPublishScript: {
54-
console.log(
54+
core.info(
5555
"No changesets found, attempting to publish any unpublished packages to npm"
5656
);
5757

5858
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
5959
if (fs.existsSync(userNpmrcPath)) {
60-
console.log("Found existing user .npmrc file");
60+
core.info("Found existing user .npmrc file");
6161
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
6262
const authLine = userNpmrcContent.split("\n").find((line) => {
6363
// check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
6464
return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line);
6565
});
6666
if (authLine) {
67-
console.log(
67+
core.info(
6868
"Found existing auth token for the npm registry in the user .npmrc file"
6969
);
7070
} else {
71-
console.log(
71+
core.info(
7272
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
7373
);
7474
fs.appendFileSync(
@@ -77,7 +77,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
7777
);
7878
}
7979
} else {
80-
console.log("No user .npmrc file found, creating one");
80+
core.info("No user .npmrc file found, creating one");
8181
fs.writeFileSync(
8282
userNpmrcPath,
8383
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
@@ -100,7 +100,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
100100
return;
101101
}
102102
case hasChangesets && !hasNonEmptyChangesets:
103-
console.log("All changesets are empty; not creating PR");
103+
core.info("All changesets are empty; not creating PR");
104104
return;
105105
case hasChangesets:
106106
const { pullRequestNumber } = await runVersion({
@@ -116,6 +116,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
116116
return;
117117
}
118118
})().catch((err) => {
119-
console.error(err);
119+
core.error(err);
120120
core.setFailed(err.message);
121121
});

src/run.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exec, getExecOutput } from "@actions/exec";
22
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
33
import * as github from "@actions/github";
4+
import * as core from "@actions/core";
45
import fs from "fs-extra";
56
import { getPackages, Package } from "@manypkg/get-packages";
67
import path from "path";
@@ -86,12 +87,12 @@ export async function runPublish({
8687
getOctokitOptions(githubToken, {
8788
throttle: {
8889
onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
89-
console.log(
90+
core.warning(
9091
`Request quota exhausted for request ${options.method} ${options.url}`
9192
);
9293

9394
if (retryCount <= 2) {
94-
console.log(`Retrying after ${retryAfter} seconds!`);
95+
core.info(`Retrying after ${retryAfter} seconds!`);
9596
return true;
9697
}
9798
},
@@ -101,12 +102,12 @@ export async function runPublish({
101102
octokit,
102103
retryCount
103104
) => {
104-
console.log(
105+
core.warning(
105106
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
106107
);
107108

108109
if (retryCount <= 2) {
109-
console.log(`Retrying after ${retryAfter} seconds!`);
110+
core.info(`Retrying after ${retryAfter} seconds!`);
110111
return true;
111112
}
112113
},
@@ -360,7 +361,7 @@ export async function runVersion({
360361
await gitUtils.push(versionBranch, { force: true });
361362

362363
let searchResult = await searchResultPromise;
363-
console.log(JSON.stringify(searchResult.data, null, 2));
364+
core.info(JSON.stringify(searchResult.data, null, 2));
364365

365366
const changedPackagesInfo = (await changedPackagesInfoPromises)
366367
.filter((x) => x)
@@ -375,7 +376,7 @@ export async function runVersion({
375376
});
376377

377378
if (searchResult.data.items.length === 0) {
378-
console.log("creating pull request");
379+
core.info("creating pull request");
379380
const { data: newPullRequest } = await octokit.rest.pulls.create({
380381
base: branch,
381382
head: versionBranch,
@@ -390,7 +391,7 @@ export async function runVersion({
390391
} else {
391392
const [pullRequest] = searchResult.data.items;
392393

393-
console.log(`updating found pull request #${pullRequest.number}`);
394+
core.info(`updating found pull request #${pullRequest.number}`);
394395
await octokit.rest.pulls.update({
395396
pull_number: pullRequest.number,
396397
title: finalPrTitle,

0 commit comments

Comments
 (0)