Skip to content

Commit

Permalink
Merge pull request #550 from reviewdog/fix-path-for-go.sum
Browse files Browse the repository at this point in the history
Fix path for go.sum
  • Loading branch information
shogo82148 committed Jun 25, 2023
2 parents 6ce6d52 + 3cb83a2 commit 22adb9d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
15 changes: 12 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/cache.ts
@@ -1,5 +1,6 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as crypto from "crypto";
import * as fs from "fs";
import * as path from "path";
Expand All @@ -15,7 +16,10 @@ export interface State {

export async function restore(cwd: string): Promise<State> {
const keyPrefix = `${process.platform}-golangci-`;
const hash = await hashFiles(path.join(cwd, "go.sum"));
const goSumPath = await getGoSumPath(cwd);
core.info(`go.sum path is ${goSumPath}`);

const hash = await hashFiles(goSumPath);
const key = keyPrefix + hash;
const restoreKeys = [keyPrefix];

Expand All @@ -40,6 +44,13 @@ export async function restore(cwd: string): Promise<State> {
return { key, cachedKey };
}

async function getGoSumPath(cwd: string): Promise<string> {
const opt = { cwd };
const output = await exec.getExecOutput("go", ["env", "GOMOD"], opt);
const goModPath = output.stdout.trim();
return path.join(path.dirname(goModPath), "go.sum");
}

export async function save(state: State): Promise<void> {
const { cachedKey, key } = state;
if (cachedKey === key) {
Expand Down
2 changes: 1 addition & 1 deletion src/installer.ts
Expand Up @@ -109,7 +109,7 @@ async function tagToVersion(tag: string, owner: string, repo: string): Promise<s
const headers = { [http.Headers.Accept]: "application/json" };
const response = await client.getJson<Release>(url, headers);

if (response.statusCode != http.HttpCodes.OK) {
if (response.statusCode !== http.HttpCodes.OK) {
core.error(`${url} returns unexpected HTTP status code: ${response.statusCode}`);
}
if (!response.result) {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Expand Up @@ -11,7 +11,7 @@ import * as flags from "./flags";
import * as setupGo from "./setup-go/main";
import * as cache from "./cache";

async function run() {
async function run(): Promise<void> {
const runnerTmpdir = process.env["RUNNER_TEMP"] || os.tmpdir();
const tmpdir = await fs.mkdtemp(path.join(runnerTmpdir, "reviewdog-"));

Expand Down Expand Up @@ -119,4 +119,4 @@ async function run() {
}
}

run();
void run();

0 comments on commit 22adb9d

Please sign in to comment.