Skip to content

Commit

Permalink
Check that go.mod exists in reading the version (#173)
Browse files Browse the repository at this point in the history
Add additional tests in github actions
Support working directory for reading the version from go.mod
  • Loading branch information
Sergey Vilgelm committed Feb 24, 2021
1 parent 51485a4 commit d9f0e73
Show file tree
Hide file tree
Showing 8 changed files with 744 additions and 15 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -14,24 +14,29 @@ jobs:
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
version:
- ""
- "latest"
- "v1.37"
- "v1.37.1"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: latest
version: ${{ matrix.version }}
args: --issues-exit-code=0 ./sample/...
only-new-issues: true

# Test with full version vX.Y.Z
test-full-version:
test-go-mod-version:
strategy:
matrix:
os:
Expand All @@ -43,6 +48,5 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
version: v1.28.3
args: --issues-exit-code=0 ./sample/...
only-new-issues: true
working-directory: sample-go-mod
args: --issues-exit-code=0 ./...
15 changes: 12 additions & 3 deletions dist/post_run/index.js
Expand Up @@ -2233,11 +2233,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLintVersion = exports.stringifyVersion = void 0;
const core = __importStar(__webpack_require__(470));
const httpm = __importStar(__webpack_require__(539));
const fs = __importStar(__webpack_require__(747));
const path_1 = __importDefault(__webpack_require__(622));
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => {
Expand Down Expand Up @@ -2282,12 +2286,17 @@ const isLessVersion = (a, b) => {
};
const getRequestedLintVersion = () => {
let requestedLintVersion = core.getInput(`version`);
if (requestedLintVersion == "") {
const content = fs.readFileSync("go.mod", "utf-8");
const workingDirectory = core.getInput(`working-directory`);
let goMod = "go.mod";
if (workingDirectory) {
goMod = path_1.default.join(workingDirectory, goMod);
}
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8");
const match = content.match(modVersionRe);
if (match) {
requestedLintVersion = match[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`);
}
}
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
Expand Down
15 changes: 12 additions & 3 deletions dist/run/index.js
Expand Up @@ -2233,11 +2233,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLintVersion = exports.stringifyVersion = void 0;
const core = __importStar(__webpack_require__(470));
const httpm = __importStar(__webpack_require__(539));
const fs = __importStar(__webpack_require__(747));
const path_1 = __importDefault(__webpack_require__(622));
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/;
const modVersionRe = /github.com\/golangci\/golangci-lint\s(v.+)/;
const parseVersion = (s) => {
Expand Down Expand Up @@ -2282,12 +2286,17 @@ const isLessVersion = (a, b) => {
};
const getRequestedLintVersion = () => {
let requestedLintVersion = core.getInput(`version`);
if (requestedLintVersion == "") {
const content = fs.readFileSync("go.mod", "utf-8");
const workingDirectory = core.getInput(`working-directory`);
let goMod = "go.mod";
if (workingDirectory) {
goMod = path_1.default.join(workingDirectory, goMod);
}
if (requestedLintVersion == "" && fs.existsSync(goMod)) {
const content = fs.readFileSync(goMod, "utf-8");
const match = content.match(modVersionRe);
if (match) {
requestedLintVersion = match[1];
core.info(`Found golangci-lint version '${requestedLintVersion}' in go.mod`);
core.info(`Found golangci-lint version '${requestedLintVersion}' in '${goMod}' file`);
}
}
const parsedRequestedLintVersion = parseVersion(requestedLintVersion);
Expand Down
5 changes: 5 additions & 0 deletions sample-go-mod/go.mod
@@ -0,0 +1,5 @@
module sample

go 1.15

require github.com/golangci/golangci-lint v1.37.1

0 comments on commit d9f0e73

Please sign in to comment.