diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3545a7..1f73f47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,8 +54,8 @@ jobs: version: - "" - "latest" - - "v1.63" # TODO(ldez): it should be updated for v2. - - "v1.63.4" # TODO(ldez): it should be updated for v2. + - "v2.0" + - "v2.0.0" runs-on: ${{ matrix.os }} permissions: contents: read @@ -83,8 +83,8 @@ jobs: version: - "" - "latest" - - "v1.63.4" # TODO(ldez): it should be updated for v2. - - "95c39ac1fbaf66475705c06c16259ffd9d6bf9a2" # TODO(ldez): it should be updated for v2. + - "v2.0.0" + - "1f032fbc4b117e4247b19ff606cc847ab5383bc9" runs-on: ${{ matrix.os }} permissions: contents: read diff --git a/.golangci.yml b/.golangci.yml index ad24fce..e6015c6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ +version: "2" + output: show-stats: true - sort-results: true sort-order: + - file - linter - - file \ No newline at end of file diff --git a/README.md b/README.md index bb49486..5dd431d 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,9 @@ jobs: with: go-version: stable - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.64 + version: v2.0 ``` @@ -92,9 +92,9 @@ jobs: with: go-version: ${{ matrix.go }} - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.64 + version: v2.0 ``` You will also likely need to add the following `.gitattributes` file to ensure that line endings for Windows builds are properly formatted: @@ -120,7 +120,7 @@ on: env: GO_VERSION: stable - GOLANGCI_LINT_VERSION: v1.64 + GOLANGCI_LINT_VERSION: v2.0 jobs: detect-modules: @@ -147,7 +147,7 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - name: golangci-lint ${{ matrix.modules }} - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: ${{ env.GOLANGCI_LINT_VERSION }} working-directory: ${{ matrix.modules }} @@ -179,7 +179,7 @@ jobs: with: os: ${{ matrix.os }} go-version: ${{ matrix.go-version }} - golangci-lint-version: v1.64 + golangci-lint-version: v2.0 ``` ```yaml @@ -201,7 +201,7 @@ on: golangci-lint-version: description: 'Golangci-lint version' type: string - default: 'v1.64' + default: 'v2.0' jobs: detect-modules: @@ -229,7 +229,7 @@ jobs: with: go-version: ${{ inputs.go-version }} - name: golangci-lint ${{ matrix.modules }} - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: ${{ inputs.golangci-lint-version }} working-directory: ${{ matrix.modules }} @@ -245,6 +245,7 @@ You will also likely need to add the following `.gitattributes` file to ensure t ## Compatibility +* `v7.0.0` supports golangci-lint v2 only. * `v6.0.0+` removes `annotations` option, removes the default output format (`github-actions`). * `v5.0.0+` removes `skip-pkg-cache` and `skip-build-cache` because the cache related to Go itself is already handled by `actions/setup-go`. * `v4.0.0+` requires an explicit `actions/setup-go` installation step before using this action: `uses: actions/setup-go@v5`. @@ -262,17 +263,17 @@ You will also likely need to add the following `.gitattributes` file to ensure t The version of golangci-lint to use. When `install-mode` is: -* `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version. -* `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit. +* `binary` (default): the value can be v2.3 or v2.3.4 or `latest` to use the latest version. +* `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit. * `none`: the value is ignored.
Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: - version: v1.58 + version: v2.0 # ... ``` @@ -290,7 +291,7 @@ The default value is `binary`. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: install-mode: "goinstall" # ... @@ -310,7 +311,7 @@ By default, it uses the `github.token` from the action. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: github-token: xxx # ... @@ -333,7 +334,7 @@ The JSONSchema used to validate the configuration depends on the version of gola Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: verify: false # ... @@ -358,7 +359,7 @@ The default value is `false`. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: only-new-issues: true # ... @@ -376,7 +377,7 @@ Working directory, useful for monorepos. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: working-directory: somedir # ... @@ -397,9 +398,9 @@ The location of the configuration file can be changed by using `--config=` Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: - args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + args: --config=/my/path/.golangci.yml --issues-exit-code=0 # ... ``` @@ -411,7 +412,7 @@ with: Force the usage of the embedded problem matchers. -By default, the [problem matcher of Go (`actions/setup-go`)](https://github.com/actions/setup-go/blob/main/matchers.json) already handles the golangci-lint output (`colored-line-number`). +By default, the [problem matcher of Go (`actions/setup-go`)](https://github.com/actions/setup-go/blob/main/matchers.json) already handles the default golangci-lint output (`text`). Works only with `colored-line-number` (the golangci-lint default). @@ -423,7 +424,7 @@ The default value is `false`. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: problem-matchers: true # ... @@ -444,7 +445,7 @@ The default value is `false`. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: skip-cache: true # ... @@ -464,7 +465,7 @@ The default value is `false`. Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: skip-save-cache: true # ... @@ -486,7 +487,7 @@ If set the number is `<= 0`, the cache will be always invalidate (Not recommende Example ```yml -uses: golangci/golangci-lint-action@v6 +uses: golangci/golangci-lint-action@v7 with: cache-invalidation-interval: 15 # ... @@ -515,7 +516,7 @@ permissions: pull-requests: read ``` -For annotations to work use the default `colored-line-number` output and either use `actions/setup-go` in the job or enable the internal [problem matchers](#problem-matchers). +For annotations to work use the default format output (`text`) and either use `actions/setup-go` in the job or enable the internal [problem matchers](#problem-matchers). ## Performance diff --git a/action.yml b/action.yml index 1db3570..23f71a9 100644 --- a/action.yml +++ b/action.yml @@ -7,8 +7,8 @@ inputs: description: | The version of golangci-lint to use. When `install-mode` is: - - `binary` (default): the value can be v1.2 or v1.2.3 or `latest` to use the latest version. - - `goinstall`: the value can be v1.2.3, `latest`, or the hash of a commit. + - `binary` (default): the value can be v2.3 or v2.3.4 or `latest` to use the latest version. + - `goinstall`: the value can be v2.3.4, `latest`, or the hash of a commit. - `none`: the value is ignored. required: false install-mode: diff --git a/dist/post_run/index.js b/dist/post_run/index.js index ee29f7b..8a1a945 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -92568,11 +92568,9 @@ async function goInstall(versionInfo) { core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`); const startedAt = Date.now(); const options = { env: { ...process.env, CGO_ENABLED: "1" } }; - // TODO(ldez): it should be updated for v2. - const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); + const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); printOutput(exres); - // TODO(ldez): it should be updated for v2. - const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); + const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); printOutput(res); // The output of `go install -n` when the binary is already installed is `touch `. const binPath = res.stderr @@ -92873,7 +92871,7 @@ async function runLint(binPath, patchPath) { const res = await execShellCommand(`${binPath} cache status`); printOutput(res); } - let userArgs = core.getInput(`args`); + const userArgs = core.getInput(`args`); const addedArgs = []; const userArgsList = userArgs .trim() @@ -92893,20 +92891,11 @@ async function runLint(binPath, patchPath) { core.info(`##[add-matcher]${matchersPath}`); } } - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format. - .join(","); - if (formats) { - // Adds formats but without `github-actions` format. - addedArgs.push(`--out-format=${formats}`); - } - // Removes `--out-format` from the user flags because it's already inside `addedArgs`. - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); if ((0, patch_1.isOnlyNewIssues)()) { - if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { + if (userArgNames.has(`new`) || + userArgNames.has(`new-from-rev`) || + userArgNames.has(`new-from-patch`) || + userArgNames.has(`new-from-merge-base`)) { throw new Error(`please, don't specify manually --new* args when requesting only new issues`); } const ctx = github.context; @@ -92920,6 +92909,7 @@ async function runLint(binPath, patchPath) { // Override config values. addedArgs.push(`--new=false`); addedArgs.push(`--new-from-rev=`); + addedArgs.push(`--new-from-merge-base=`); } break; case `merge_group`: @@ -92927,6 +92917,7 @@ async function runLint(binPath, patchPath) { // Override config values. addedArgs.push(`--new=false`); addedArgs.push(`--new-from-patch=`); + addedArgs.push(`--new-from-merge-base=`); break; default: break; @@ -92954,7 +92945,6 @@ async function runLint(binPath, patchPath) { } catch (exc) { // This logging passes issues to GitHub annotations but comments can be more convenient for some users. - // TODO: support reviewdog or leaving comments by GitHub API. printOutput(exc); if (exc.code === 1) { core.setFailed(`issues found`); @@ -93233,20 +93223,17 @@ const fs = __importStar(__nccwpck_require__(9896)); const path_1 = __importDefault(__nccwpck_require__(6928)); const install_1 = __nccwpck_require__(232); const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; -// TODO(ldez): it should be updated to match v2 module name. -const modVersionRe = /github.com\/golangci\/golangci-lint\s(v\S+)/; +const modVersionRe = /github.com\/golangci\/golangci-lint\/v2\s(v\S+)/; const parseVersion = (s) => { if (s == "latest" || s == "") { - // TODO(ldez): v2: it should be replaced with "return null" - return { major: 1, minor: 64, patch: 8 }; + return null; } const match = s.match(versionRe); if (!match) { throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`); } - // TODO(ldez): v2: to remove. - if (parseInt(match[1]) > 1) { - throw new Error(`invalid version string '${s}', golangci-lint v2 is not supported by golangci-lint-action v6, you must update to golangci-lint-action v7.`); + if (parseInt(match[1]) !== 2) { + throw new Error(`invalid version string '${s}', golangci-lint v${match[1]} is not supported by golangci-lint-action v7.`); } return { major: parseInt(match[1]), @@ -93261,11 +93248,10 @@ const stringifyVersion = (v) => { return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`; }; exports.stringifyVersion = stringifyVersion; -// TODO(ldez): it should be updated to v2.0.0. const minVersion = { - major: 1, - minor: 28, - patch: 3, + major: 2, + minor: 0, + patch: 0, }; const isLessVersion = (a, b) => { if (a == null) { @@ -93311,7 +93297,7 @@ const fetchVersionMapping = async () => { maxRetries: 5, }); try { - const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v1.json`; + const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v2.json`; const response = await http.get(url); if (response.message.statusCode !== 200) { throw new Error(`failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`); @@ -93327,17 +93313,11 @@ async function getVersion(mode) { core.info(`Finding needed golangci-lint version...`); if (mode == install_1.InstallMode.GoInstall) { const v = core.getInput(`version`); - // TODO(ldez): v2: to remove. - if (v == "latest") { - return { TargetVersion: "v1.64.8" }; - } - // TODO(ldez): v2: "v1.64.8" should be replaced with "latest". - return { TargetVersion: v ? v : "v1.64.8" }; + return { TargetVersion: v ? v : "latest" }; } const reqVersion = getRequestedVersion(); // if the patched version is passed, just use it - // TODO(ldez): should be updated to `reqVersion?.major === 2`. - if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) { + if (reqVersion?.major === 2 && reqVersion?.minor != null && reqVersion?.patch !== null) { return new Promise((resolve) => { const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`; resolve({ TargetVersion: `v${versionWithoutV}` }); diff --git a/dist/run/index.js b/dist/run/index.js index 1bf5694..db40d4e 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -92568,11 +92568,9 @@ async function goInstall(versionInfo) { core.info(`Installing golangci-lint ${versionInfo.TargetVersion}...`); const startedAt = Date.now(); const options = { env: { ...process.env, CGO_ENABLED: "1" } }; - // TODO(ldez): it should be updated for v2. - const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); + const exres = await execShellCommand(`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); printOutput(exres); - // TODO(ldez): it should be updated for v2. - const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); + const res = await execShellCommand(`go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options); printOutput(res); // The output of `go install -n` when the binary is already installed is `touch `. const binPath = res.stderr @@ -92873,7 +92871,7 @@ async function runLint(binPath, patchPath) { const res = await execShellCommand(`${binPath} cache status`); printOutput(res); } - let userArgs = core.getInput(`args`); + const userArgs = core.getInput(`args`); const addedArgs = []; const userArgsList = userArgs .trim() @@ -92893,20 +92891,11 @@ async function runLint(binPath, patchPath) { core.info(`##[add-matcher]${matchersPath}`); } } - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format. - .join(","); - if (formats) { - // Adds formats but without `github-actions` format. - addedArgs.push(`--out-format=${formats}`); - } - // Removes `--out-format` from the user flags because it's already inside `addedArgs`. - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim(); if ((0, patch_1.isOnlyNewIssues)()) { - if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { + if (userArgNames.has(`new`) || + userArgNames.has(`new-from-rev`) || + userArgNames.has(`new-from-patch`) || + userArgNames.has(`new-from-merge-base`)) { throw new Error(`please, don't specify manually --new* args when requesting only new issues`); } const ctx = github.context; @@ -92920,6 +92909,7 @@ async function runLint(binPath, patchPath) { // Override config values. addedArgs.push(`--new=false`); addedArgs.push(`--new-from-rev=`); + addedArgs.push(`--new-from-merge-base=`); } break; case `merge_group`: @@ -92927,6 +92917,7 @@ async function runLint(binPath, patchPath) { // Override config values. addedArgs.push(`--new=false`); addedArgs.push(`--new-from-patch=`); + addedArgs.push(`--new-from-merge-base=`); break; default: break; @@ -92954,7 +92945,6 @@ async function runLint(binPath, patchPath) { } catch (exc) { // This logging passes issues to GitHub annotations but comments can be more convenient for some users. - // TODO: support reviewdog or leaving comments by GitHub API. printOutput(exc); if (exc.code === 1) { core.setFailed(`issues found`); @@ -93233,20 +93223,17 @@ const fs = __importStar(__nccwpck_require__(9896)); const path_1 = __importDefault(__nccwpck_require__(6928)); const install_1 = __nccwpck_require__(232); const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/; -// TODO(ldez): it should be updated to match v2 module name. -const modVersionRe = /github.com\/golangci\/golangci-lint\s(v\S+)/; +const modVersionRe = /github.com\/golangci\/golangci-lint\/v2\s(v\S+)/; const parseVersion = (s) => { if (s == "latest" || s == "") { - // TODO(ldez): v2: it should be replaced with "return null" - return { major: 1, minor: 64, patch: 8 }; + return null; } const match = s.match(versionRe); if (!match) { throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`); } - // TODO(ldez): v2: to remove. - if (parseInt(match[1]) > 1) { - throw new Error(`invalid version string '${s}', golangci-lint v2 is not supported by golangci-lint-action v6, you must update to golangci-lint-action v7.`); + if (parseInt(match[1]) !== 2) { + throw new Error(`invalid version string '${s}', golangci-lint v${match[1]} is not supported by golangci-lint-action v7.`); } return { major: parseInt(match[1]), @@ -93261,11 +93248,10 @@ const stringifyVersion = (v) => { return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`; }; exports.stringifyVersion = stringifyVersion; -// TODO(ldez): it should be updated to v2.0.0. const minVersion = { - major: 1, - minor: 28, - patch: 3, + major: 2, + minor: 0, + patch: 0, }; const isLessVersion = (a, b) => { if (a == null) { @@ -93311,7 +93297,7 @@ const fetchVersionMapping = async () => { maxRetries: 5, }); try { - const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v1.json`; + const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v2.json`; const response = await http.get(url); if (response.message.statusCode !== 200) { throw new Error(`failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`); @@ -93327,17 +93313,11 @@ async function getVersion(mode) { core.info(`Finding needed golangci-lint version...`); if (mode == install_1.InstallMode.GoInstall) { const v = core.getInput(`version`); - // TODO(ldez): v2: to remove. - if (v == "latest") { - return { TargetVersion: "v1.64.8" }; - } - // TODO(ldez): v2: "v1.64.8" should be replaced with "latest". - return { TargetVersion: v ? v : "v1.64.8" }; + return { TargetVersion: v ? v : "latest" }; } const reqVersion = getRequestedVersion(); // if the patched version is passed, just use it - // TODO(ldez): should be updated to `reqVersion?.major === 2`. - if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) { + if (reqVersion?.major === 2 && reqVersion?.minor != null && reqVersion?.patch !== null) { return new Promise((resolve) => { const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}`; resolve({ TargetVersion: `v${versionWithoutV}` }); diff --git a/go.mod b/go.mod index e591614..2ae3ad2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/golangci/golangci-lint-action -go 1.14 +go 1.23 diff --git a/sample-go-mod/.golangci.yml b/sample-go-mod/.golangci.yml index ad24fce..e6015c6 100644 --- a/sample-go-mod/.golangci.yml +++ b/sample-go-mod/.golangci.yml @@ -1,6 +1,7 @@ +version: "2" + output: show-stats: true - sort-results: true sort-order: + - file - linter - - file \ No newline at end of file diff --git a/sample-go-mod/go.mod b/sample-go-mod/go.mod index 0184a16..e4c5b91 100644 --- a/sample-go-mod/go.mod +++ b/sample-go-mod/go.mod @@ -2,7 +2,7 @@ module sample go 1.22.1 -require github.com/golangci/golangci-lint v1.60.1 +require github.com/golangci/golangci-lint/v2 v2.0.0 require ( 4d63.com/gocheckcompilerdirectives v1.2.1 // indirect diff --git a/sample-go-mod/tools.go b/sample-go-mod/tools.go index 9660590..1a0e055 100644 --- a/sample-go-mod/tools.go +++ b/sample-go-mod/tools.go @@ -3,5 +3,5 @@ package main import ( - _ "github.com/golangci/golangci-lint/cmd/golangci-lint" + _ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint" ) diff --git a/sample-go-tool/.golangci.yml b/sample-go-tool/.golangci.yml index ad24fce..e6015c6 100644 --- a/sample-go-tool/.golangci.yml +++ b/sample-go-tool/.golangci.yml @@ -1,6 +1,7 @@ +version: "2" + output: show-stats: true - sort-results: true sort-order: + - file - linter - - file \ No newline at end of file diff --git a/sample-go-tool/go.mod b/sample-go-tool/go.mod index 0bab3be..ebc15d2 100644 --- a/sample-go-tool/go.mod +++ b/sample-go-tool/go.mod @@ -4,7 +4,7 @@ go 1.24 toolchain go1.24.0 -tool github.com/golangci/golangci-lint/cmd/golangci-lint +tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint require ( 4d63.com/gocheckcompilerdirectives v1.2.1 // indirect @@ -68,7 +68,7 @@ require ( github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect github.com/golangci/go-printf-func-name v0.1.0 // indirect github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect - github.com/golangci/golangci-lint v1.64.4 // indirect + github.com/golangci/golangci-lint/v2 v2.0.0 // indirect github.com/golangci/misspell v0.6.0 // indirect github.com/golangci/plugin-module-register v0.1.1 // indirect github.com/golangci/revgrep v0.8.0 // indirect diff --git a/src/install.ts b/src/install.ts index 960fa8d..1f5083f 100644 --- a/src/install.ts +++ b/src/install.ts @@ -84,16 +84,14 @@ async function goInstall(versionInfo: VersionInfo): Promise { const options: ExecOptions = { env: { ...process.env, CGO_ENABLED: "1" } } - // TODO(ldez): it should be updated for v2. const exres = await execShellCommand( - `go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, + `go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options ) printOutput(exres) - // TODO(ldez): it should be updated for v2. const res = await execShellCommand( - `go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionInfo.TargetVersion}`, + `go install -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${versionInfo.TargetVersion}`, options ) printOutput(res) diff --git a/src/run.ts b/src/run.ts index 55864df..db02b3f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -51,7 +51,7 @@ async function runLint(binPath: string, patchPath: string): Promise { printOutput(res) } - let userArgs = core.getInput(`args`) + const userArgs = core.getInput(`args`) const addedArgs: string[] = [] const userArgsList = userArgs @@ -76,23 +76,13 @@ async function runLint(binPath: string, patchPath: string): Promise { } } - const formats = (userArgsMap.get("out-format") || "") - .trim() - .split(",") - .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format. - .join(",") - - if (formats) { - // Adds formats but without `github-actions` format. - addedArgs.push(`--out-format=${formats}`) - } - - // Removes `--out-format` from the user flags because it's already inside `addedArgs`. - userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim() - if (isOnlyNewIssues()) { - if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) { + if ( + userArgNames.has(`new`) || + userArgNames.has(`new-from-rev`) || + userArgNames.has(`new-from-patch`) || + userArgNames.has(`new-from-merge-base`) + ) { throw new Error(`please, don't specify manually --new* args when requesting only new issues`) } @@ -110,6 +100,7 @@ async function runLint(binPath: string, patchPath: string): Promise { // Override config values. addedArgs.push(`--new=false`) addedArgs.push(`--new-from-rev=`) + addedArgs.push(`--new-from-merge-base=`) } break case `merge_group`: @@ -118,6 +109,7 @@ async function runLint(binPath: string, patchPath: string): Promise { // Override config values. addedArgs.push(`--new=false`) addedArgs.push(`--new-from-patch=`) + addedArgs.push(`--new-from-merge-base=`) break default: break @@ -150,7 +142,6 @@ async function runLint(binPath: string, patchPath: string): Promise { core.info(`golangci-lint found no issues`) } catch (exc) { // This logging passes issues to GitHub annotations but comments can be more convenient for some users. - // TODO: support reviewdog or leaving comments by GitHub API. printOutput(exc) if (exc.code === 1) { diff --git a/src/version.ts b/src/version.ts index 337fc8f..1860007 100644 --- a/src/version.ts +++ b/src/version.ts @@ -13,13 +13,11 @@ export type Version = { } | null const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/ -// TODO(ldez): it should be updated to match v2 module name. -const modVersionRe = /github.com\/golangci\/golangci-lint\s(v\S+)/ +const modVersionRe = /github.com\/golangci\/golangci-lint\/v2\s(v\S+)/ const parseVersion = (s: string): Version => { if (s == "latest" || s == "") { - // TODO(ldez): v2: it should be replaced with "return null" - return { major: 1, minor: 64, patch: 8 } + return null } const match = s.match(versionRe) @@ -27,11 +25,8 @@ const parseVersion = (s: string): Version => { throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`) } - // TODO(ldez): v2: to remove. - if (parseInt(match[1]) > 1) { - throw new Error( - `invalid version string '${s}', golangci-lint v2 is not supported by golangci-lint-action v6, you must update to golangci-lint-action v7.` - ) + if (parseInt(match[1]) !== 2) { + throw new Error(`invalid version string '${s}', golangci-lint v${match[1]} is not supported by golangci-lint-action v7.`) } return { @@ -48,11 +43,10 @@ export const stringifyVersion = (v: Version): string => { return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}` } -// TODO(ldez): it should be updated to v2.0.0. const minVersion = { - major: 1, - minor: 28, - patch: 3, + major: 2, + minor: 0, + patch: 0, } const isLessVersion = (a: Version, b: Version): boolean => { @@ -122,7 +116,7 @@ const fetchVersionMapping = async (): Promise => { maxRetries: 5, }) try { - const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v1.json` + const url = `https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/assets/github-action-config-v2.json` const response: httpm.HttpClientResponse = await http.get(url) if (response.message.statusCode !== 200) { throw new Error(`failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`) @@ -140,20 +134,14 @@ export async function getVersion(mode: InstallMode): Promise { if (mode == InstallMode.GoInstall) { const v: string = core.getInput(`version`) - // TODO(ldez): v2: to remove. - if (v == "latest") { - return { TargetVersion: "v1.64.8" } - } - // TODO(ldez): v2: "v1.64.8" should be replaced with "latest". - return { TargetVersion: v ? v : "v1.64.8" } + return { TargetVersion: v ? v : "latest" } } const reqVersion = getRequestedVersion() // if the patched version is passed, just use it - // TODO(ldez): should be updated to `reqVersion?.major === 2`. - if (reqVersion?.major === 1 && reqVersion?.minor != null && reqVersion?.patch !== null) { + if (reqVersion?.major === 2 && reqVersion?.minor != null && reqVersion?.patch !== null) { return new Promise((resolve) => { const versionWithoutV = `${reqVersion.major}.${reqVersion.minor}.${reqVersion.patch}` resolve({ TargetVersion: `v${versionWithoutV}` })