Skip to content

Commit d9f0e73

Browse files
author
Sergey Vilgelm
authored
Check that go.mod exists in reading the version (#173)
Add additional tests in github actions Support working directory for reading the version from go.mod
1 parent 51485a4 commit d9f0e73

File tree

8 files changed

+744
-15
lines changed

8 files changed

+744
-15
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,29 @@ jobs:
1414
- run: |
1515
npm install
1616
npm run all
17+
1718
test: # make sure the action works on a clean machine without building
1819
strategy:
1920
matrix:
2021
os:
2122
- ubuntu-latest
2223
- macos-latest
2324
- windows-latest
25+
version:
26+
- ""
27+
- "latest"
28+
- "v1.37"
29+
- "v1.37.1"
2430
runs-on: ${{ matrix.os }}
2531
steps:
2632
- uses: actions/checkout@v2
2733
- uses: ./
2834
with:
29-
version: latest
35+
version: ${{ matrix.version }}
3036
args: --issues-exit-code=0 ./sample/...
3137
only-new-issues: true
3238

33-
# Test with full version vX.Y.Z
34-
test-full-version:
39+
test-go-mod-version:
3540
strategy:
3641
matrix:
3742
os:
@@ -43,6 +48,5 @@ jobs:
4348
- uses: actions/checkout@v2
4449
- uses: ./
4550
with:
46-
version: v1.28.3
47-
args: --issues-exit-code=0 ./sample/...
48-
only-new-issues: true
51+
working-directory: sample-go-mod
52+
args: --issues-exit-code=0 ./...

dist/post_run/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22332233
step((generator = generator.apply(thisArg, _arguments || [])).next());
22342234
});
22352235
};
2236+
var __importDefault = (this && this.__importDefault) || function (mod) {
2237+
return (mod && mod.__esModule) ? mod : { "default": mod };
2238+
};
22362239
Object.defineProperty(exports, "__esModule", { value: true });
22372240
exports.findLintVersion = exports.stringifyVersion = void 0;
22382241
const core = __importStar(__webpack_require__(470));
22392242
const httpm = __importStar(__webpack_require__(539));
22402243
const fs = __importStar(__webpack_require__(747));
2244+
const path_1 = __importDefault(__webpack_require__(622));
22412245
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
22422246
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
22432247
const parseVersion = (s) => {
@@ -2282,12 +2286,17 @@ const isLessVersion = (a, b) => {
22822286
};
22832287
const getRequestedLintVersion = () => {
22842288
let requestedLintVersion = core.getInput(`version`);
2285-
if (requestedLintVersion == "") {
2286-
const content = fs.readFileSync("go.mod", "utf-8");
2289+
const workingDirectory = core.getInput(`working-directory`);
2290+
let goMod = "go.mod";
2291+
if (workingDirectory) {
2292+
goMod = path_1.default.join(workingDirectory, goMod);
2293+
}
2294+
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
2295+
const content = fs.readFileSync(goMod, "utf-8");
22872296
const match = content.match(modVersionRe);
22882297
if (match) {
22892298
requestedLintVersion = match[1];
2290-
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
2299+
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`);
22912300
}
22922301
}
22932302
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);

dist/run/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22332233
step((generator = generator.apply(thisArg, _arguments || [])).next());
22342234
});
22352235
};
2236+
var __importDefault = (this && this.__importDefault) || function (mod) {
2237+
return (mod && mod.__esModule) ? mod : { "default": mod };
2238+
};
22362239
Object.defineProperty(exports, "__esModule", { value: true });
22372240
exports.findLintVersion = exports.stringifyVersion = void 0;
22382241
const core = __importStar(__webpack_require__(470));
22392242
const httpm = __importStar(__webpack_require__(539));
22402243
const fs = __importStar(__webpack_require__(747));
2244+
const path_1 = __importDefault(__webpack_require__(622));
22412245
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
22422246
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
22432247
const parseVersion = (s) => {
@@ -2282,12 +2286,17 @@ const isLessVersion = (a, b) => {
22822286
};
22832287
const getRequestedLintVersion = () => {
22842288
let requestedLintVersion = core.getInput(`version`);
2285-
if (requestedLintVersion == "") {
2286-
const content = fs.readFileSync("go.mod", "utf-8");
2289+
const workingDirectory = core.getInput(`working-directory`);
2290+
let goMod = "go.mod";
2291+
if (workingDirectory) {
2292+
goMod = path_1.default.join(workingDirectory, goMod);
2293+
}
2294+
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
2295+
const content = fs.readFileSync(goMod, "utf-8");
22872296
const match = content.match(modVersionRe);
22882297
if (match) {
22892298
requestedLintVersion = match[1];
2290-
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
2299+
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`);
22912300
}
22922301
}
22932302
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);

sample-go-mod/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module sample
2+
3+
go 1.15
4+
5+
require github.com/golangci/golangci-lint v1.37.1

0 commit comments

Comments
 (0)