Skip to content

Commit

Permalink
detect go.sum path from GOMOD env
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Jun 25, 2023
1 parent 03cc0c1 commit 3cb83a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3cb83a2

Please sign in to comment.