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>
This commit is contained in:
Viktor Varland
2023-05-08 23:42:00 +02:00
committed by GitHub
co-authored by Mateusz Burzyński
parent ab485bff43
commit 8b2818674d
3 changed files with 24 additions and 18 deletions
+11 -11
View File
@@ -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);
});
+8 -7
View File
@@ -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,