Skip to content

Commit

Permalink
Merge pull request #239 from reviewdog/save-cache-always
Browse files Browse the repository at this point in the history
Save cache always
  • Loading branch information
shogo82148 committed Mar 11, 2022
2 parents 6d205b0 + 77f8013 commit 03507ec
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 59 deletions.
78 changes: 47 additions & 31 deletions __test__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {promises as fs} from 'fs';
import * as path from 'path';
import { promises as fs } from "fs";
import * as path from "path";

const tempDir = path.join(__dirname, '_temp');
process.env['RUNNER_TEMP'] = tempDir;
const tempDir = path.join(__dirname, "_temp");
process.env["RUNNER_TEMP"] = tempDir;

import * as io from '@actions/io';
import * as exec from '@actions/exec';
import * as installer from '../src/installer';
import * as io from "@actions/io";
import * as exec from "@actions/exec";
import * as installer from "../src/installer";

describe('installer', () => {
describe("installer", () => {
beforeAll(async () => {
await io.mkdirP(tempDir);
});
Expand All @@ -17,27 +17,43 @@ describe('installer', () => {
await io.rmRF(tempDir);
});

it('installs specific version of reviewdog', async () => {
const dir = await fs.mkdtemp(path.join(tempDir, 'reviewdog-'));
const reviewdog = await installer.installReviewdog('v0.12.0', dir);
await exec.exec(reviewdog, ['--version']);
}, 10000);

it('installs the latest version of reviewdog', async () => {
const dir = await fs.mkdtemp(path.join(tempDir, 'reviewdog-'));
const reviewdog = await installer.installReviewdog('latest', dir);
await exec.exec(reviewdog, ['--version']);
}, 10000);

it('installs specific version of golangci-lint', async () => {
const dir = await fs.mkdtemp(path.join(tempDir, 'golangci-'));
const golangci = await installer.installGolangciLint('v1.41.1', dir);
await exec.exec(golangci, ['--version']);
}, 20000);

it('installs the latest version of golangci-lint', async () => {
const dir = await fs.mkdtemp(path.join(tempDir, 'golangci-'));
const golangci = await installer.installGolangciLint('latest', dir);
await exec.exec(golangci, ['--version']);
}, 20000);
it(
"installs specific version of reviewdog",
async () => {
const dir = await fs.mkdtemp(path.join(tempDir, "reviewdog-"));
const reviewdog = await installer.installReviewdog("v0.12.0", dir);
await exec.exec(reviewdog, ["--version"]);
},
5 * 60 * 1000
);

it(
"installs the latest version of reviewdog",
async () => {
const dir = await fs.mkdtemp(path.join(tempDir, "reviewdog-"));
const reviewdog = await installer.installReviewdog("latest", dir);
await exec.exec(reviewdog, ["--version"]);
},
5 * 60 * 1000
);

it(
"installs specific version of golangci-lint",
async () => {
const dir = await fs.mkdtemp(path.join(tempDir, "golangci-"));
const golangci = await installer.installGolangciLint("v1.41.1", dir);
await exec.exec(golangci, ["--version"]);
},
5 * 60 * 1000
);

it(
"installs the latest version of golangci-lint",
async () => {
const dir = await fs.mkdtemp(path.join(tempDir, "golangci-"));
const golangci = await installer.installGolangciLint("latest", dir);
await exec.exec(golangci, ["--version"]);
},
5 * 60 * 1000
);
});
11 changes: 6 additions & 5 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.

9 changes: 7 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function run() {
});
}

await core.group("Running golangci-lint with reviewdog 🐶 ...", async () => {
const code = await core.group("Running golangci-lint with reviewdog 🐶 ...", async (): Promise<number> => {
const output = await exec.getExecOutput(
golangci,
["run", "--out-format", "line-number", ...flags.parse(golangciLintFlags)],
Expand All @@ -68,7 +68,7 @@ async function run() {
);

process.env["REVIEWDOG_GITHUB_API_TOKEN"] = core.getInput("github_token");
await exec.exec(
return await exec.exec(
reviewdog,
[
"-f=golangci-lint",
Expand All @@ -82,6 +82,7 @@ async function run() {
{
cwd,
input: Buffer.from(output.stdout, "utf-8"),
ignoreReturnCode: true,
}
);
});
Expand All @@ -93,6 +94,10 @@ async function run() {
}
});
}

if (code !== 0) {
core.setFailed(`reviewdog exited with status code: ${code}`);
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error);
Expand Down
4 changes: 0 additions & 4 deletions src/setup-go/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export async function run(versionSpec: string): Promise<void> {
core.info(`Successfully setup go version ${versionSpec}`);
}

// add problem matchers
const matchersPath = path.join(__dirname, "..", "matchers.json");
core.info(`##[add-matcher]${matchersPath}`);

// output the version actually being used
const goPath = await io.which("go");
const goVersion = (cp.execSync(`${goPath} version`) || "").toString();
Expand Down
16 changes: 0 additions & 16 deletions src/setup-go/matchers.json

This file was deleted.

0 comments on commit 03507ec

Please sign in to comment.