From 8b2818674de86a7fc69aebb9ed6b486ee32eb96e Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Mon, 8 May 2023 23:42:00 +0200 Subject: [PATCH] Use logging provided by `@actions/core` (#289) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: migrate to logging from @actions/core * Update src/index.ts * Update .changeset/blue-hornets-marry.md --------- Co-authored-by: Mateusz BurzyƄski --- .changeset/blue-hornets-marry.md | 5 +++++ src/index.ts | 22 +++++++++++----------- src/run.ts | 15 ++++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 .changeset/blue-hornets-marry.md diff --git a/.changeset/blue-hornets-marry.md b/.changeset/blue-hornets-marry.md new file mode 100644 index 00000000..db5bbde3 --- /dev/null +++ b/.changeset/blue-hornets-marry.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Use logging provided by `@actions/core` diff --git a/src/index.ts b/src/index.ts index 11214453..51ca39e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,18 +16,18 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; const inputCwd = core.getInput("cwd"); if (inputCwd) { - console.log("changing directory to the one given as the input"); + core.info("changing directory to the one given as the input"); process.chdir(inputCwd); } let setupGitUser = core.getBooleanInput("setupGitUser"); if (setupGitUser) { - console.log("setting git user"); + core.info("setting git user"); await gitUtils.setupUser(); } - console.log("setting GitHub credentials"); + core.info("setting GitHub credentials"); await fs.writeFile( `${process.env.HOME}/.netrc`, `machine github.com\nlogin github-actions[bot]\npassword ${githubToken}` @@ -48,27 +48,27 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; switch (true) { case !hasChangesets && !hasPublishScript: - console.log("No changesets found"); + core.info("No changesets found"); return; case !hasChangesets && hasPublishScript: { - console.log( + core.info( "No changesets found, attempting to publish any unpublished packages to npm" ); let userNpmrcPath = `${process.env.HOME}/.npmrc`; if (fs.existsSync(userNpmrcPath)) { - console.log("Found existing user .npmrc file"); + core.info("Found existing user .npmrc file"); const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8"); const authLine = userNpmrcContent.split("\n").find((line) => { // check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105 return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line); }); if (authLine) { - console.log( + core.info( "Found existing auth token for the npm registry in the user .npmrc file" ); } else { - console.log( + core.info( "Didn't find existing auth token for the npm registry in the user .npmrc file, creating one" ); fs.appendFileSync( @@ -77,7 +77,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; ); } } else { - console.log("No user .npmrc file found, creating one"); + core.info("No user .npmrc file found, creating one"); fs.writeFileSync( userNpmrcPath, `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n` @@ -100,7 +100,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; return; } case hasChangesets && !hasNonEmptyChangesets: - console.log("All changesets are empty; not creating PR"); + core.info("All changesets are empty; not creating PR"); return; case hasChangesets: const { pullRequestNumber } = await runVersion({ @@ -116,6 +116,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; return; } })().catch((err) => { - console.error(err); + core.error(err); core.setFailed(err.message); }); diff --git a/src/run.ts b/src/run.ts index 28ced817..e1789a3c 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,6 +1,7 @@ import { exec, getExecOutput } from "@actions/exec"; import { GitHub, getOctokitOptions } from "@actions/github/lib/utils"; import * as github from "@actions/github"; +import * as core from "@actions/core"; import fs from "fs-extra"; import { getPackages, Package } from "@manypkg/get-packages"; import path from "path"; @@ -86,12 +87,12 @@ export async function runPublish({ getOctokitOptions(githubToken, { throttle: { onRateLimit: (retryAfter, options: any, octokit, retryCount) => { - console.log( + core.warning( `Request quota exhausted for request ${options.method} ${options.url}` ); if (retryCount <= 2) { - console.log(`Retrying after ${retryAfter} seconds!`); + core.info(`Retrying after ${retryAfter} seconds!`); return true; } }, @@ -101,12 +102,12 @@ export async function runPublish({ octokit, retryCount ) => { - console.log( + core.warning( `SecondaryRateLimit detected for request ${options.method} ${options.url}` ); if (retryCount <= 2) { - console.log(`Retrying after ${retryAfter} seconds!`); + core.info(`Retrying after ${retryAfter} seconds!`); return true; } }, @@ -360,7 +361,7 @@ export async function runVersion({ await gitUtils.push(versionBranch, { force: true }); let searchResult = await searchResultPromise; - console.log(JSON.stringify(searchResult.data, null, 2)); + core.info(JSON.stringify(searchResult.data, null, 2)); const changedPackagesInfo = (await changedPackagesInfoPromises) .filter((x) => x) @@ -375,7 +376,7 @@ export async function runVersion({ }); if (searchResult.data.items.length === 0) { - console.log("creating pull request"); + core.info("creating pull request"); const { data: newPullRequest } = await octokit.rest.pulls.create({ base: branch, head: versionBranch, @@ -390,7 +391,7 @@ export async function runVersion({ } else { const [pullRequest] = searchResult.data.items; - console.log(`updating found pull request #${pullRequest.number}`); + core.info(`updating found pull request #${pullRequest.number}`); await octokit.rest.pulls.update({ pull_number: pullRequest.number, title: finalPrTitle,