Skip to content

Commit

Permalink
Upgrade @actions/* dependencies (#123)
Browse files Browse the repository at this point in the history
* Upgrade `@actions/*` dependencies

* bumps deps again

* add changeset
  • Loading branch information
Andarist authored Nov 8, 2022
1 parent ca3c2e0 commit b78f480
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-scissors-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": patch
---

Updated `@actions/*` dependencies to avoid using deprecated features of the runner.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"node": ">= 16"
},
"dependencies": {
"@actions/core": "^1.3.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^4.0.0",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-typescript": "^7.13.0",
Expand Down
7 changes: 3 additions & 4 deletions src/gitUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { exec } from "@actions/exec";
import { execWithOutput } from "./utils";
import { exec, getExecOutput } from "@actions/exec";

export const setupUser = async () => {
await exec("git", [
Expand Down Expand Up @@ -35,7 +34,7 @@ export const pushTags = async () => {
};

export const switchToMaybeExistingBranch = async (branch: string) => {
let { stderr } = await execWithOutput("git", ["checkout", branch], {
let { stderr } = await getExecOutput("git", ["checkout", branch], {
ignoreReturnCode: true,
});
let isCreatingBranch = !stderr
Expand All @@ -59,6 +58,6 @@ export const commitAll = async (message: string) => {
};

export const checkIfClean = async (): Promise<boolean> => {
const { stdout } = await execWithOutput("git", ["status", "--porcelain"]);
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
return !stdout.length;
};
4 changes: 3 additions & 1 deletion src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ let mockedGithubMethods = {
createRelease: jest.fn(),
},
};
(github.getOctokit as any).mockImplementation(() => mockedGithubMethods);
(github.getOctokit as any).mockImplementation(() => ({
rest: mockedGithubMethods,
}));

let f = fixturez(__dirname);

Expand Down
17 changes: 8 additions & 9 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from "@actions/exec";
import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import fs from "fs-extra";
import { getPackages, Package } from "@manypkg/get-packages";
Expand All @@ -7,7 +7,6 @@ import * as semver from "semver";
import { PreState } from "@changesets/types";
import {
getChangelogEntry,
execWithOutput,
getChangedPackages,
sortTheThings,
getVersionsByDirectory,
Expand Down Expand Up @@ -40,14 +39,14 @@ const createRelease = async (
);
}

await octokit.repos.createRelease({
await octokit.rest.repos.createRelease({
name: tagName,
tag_name: tagName,
body: changelogEntry.content,
prerelease: pkg.packageJson.version.includes("-"),
...github.context.repo,
});
} catch (err: any) {
} catch (err) {
// if we can't find a changelog, the user has probably disabled changelogs
if (err.code !== "ENOENT") {
throw err;
Expand Down Expand Up @@ -82,7 +81,7 @@ export async function runPublish({
let octokit = github.getOctokit(githubToken);
let [publishCommand, ...publishArgs] = script.split(/\s+/);

let changesetPublishOutput = await execWithOutput(
let changesetPublishOutput = await getExecOutput(
publishCommand,
publishArgs,
{ cwd }
Expand Down Expand Up @@ -165,7 +164,7 @@ export async function runPublish({
const requireChangesetsCliPkgJson = (cwd: string) => {
try {
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
} catch (err: any) {
} catch (err) {
if (err && err.code === "MODULE_NOT_FOUND") {
throw new Error(
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
Expand Down Expand Up @@ -292,7 +291,7 @@ export async function runVersion({
}

let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}+is:pull-request`;
let searchResultPromise = octokit.search.issuesAndPullRequests({
let searchResultPromise = octokit.rest.search.issuesAndPullRequests({
q: searchQuery,
});
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
Expand Down Expand Up @@ -342,7 +341,7 @@ export async function runVersion({

if (searchResult.data.items.length === 0) {
console.log("creating pull request");
const { data: newPullRequest } = await octokit.pulls.create({
const { data: newPullRequest } = await octokit.rest.pulls.create({
base: branch,
head: versionBranch,
title: finalPrTitle,
Expand All @@ -357,7 +356,7 @@ export async function runVersion({
const [pullRequest] = searchResult.data.items;

console.log(`updating found pull request #${pullRequest.number}`);
await octokit.pulls.update({
await octokit.rest.pulls.update({
pull_number: pullRequest.number,
title: finalPrTitle,
body: prBody,
Expand Down
26 changes: 0 additions & 26 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,6 @@ export function getChangelogEntry(changelog: string, version: string) {
};
}

export async function execWithOutput(
command: string,
args?: string[],
options?: { ignoreReturnCode?: boolean; cwd?: string }
) {
let myOutput = "";
let myError = "";

return {
code: await exec(command, args, {
listeners: {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
},
},

...options,
}),
stdout: myOutput,
stderr: myError,
};
}

export function sortTheThings(
a: { private: boolean; highestLevel: number },
b: { private: boolean; highestLevel: number }
Expand Down
Loading

0 comments on commit b78f480

Please sign in to comment.