Compare commits

..

51 Commits

Author SHA1 Message Date
3a91952989 feat: working-directory with only-new-issues (#795)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-08-14 23:13:33 +02:00
5e676315e9 build(deps): bump @actions/cache from 3.2.1 to 3.2.2 (#825)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-08-14 14:11:19 +00:00
18dad33d2e build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.2.1 to 6.3.0 (#822) 2023-08-14 13:10:54 +02:00
945dc98b91 build(deps): bump @types/node from 20.4.8 to 20.5.0 (#824) 2023-08-14 12:52:49 +02:00
cac24f53b7 build(deps-dev): bump eslint from 8.45.0 to 8.47.0 (#823) 2023-08-14 12:52:29 +02:00
ab66454db6 build(deps-dev): bump @typescript-eslint/parser from 6.2.0 to 6.3.0 (#821) 2023-08-14 12:52:04 +02:00
a2527500a4 build(deps): bump @actions/http-client from 2.1.0 to 2.1.1 (#819) 2023-08-07 21:35:27 +00:00
44d9998d44 build(deps-dev): bump eslint-config-prettier from 8.9.0 to 9.0.0 (#818) 2023-08-07 11:54:15 +02:00
b6bdfb3d14 build(deps-dev): bump prettier from 3.0.0 to 3.0.1 (#817) 2023-08-07 11:53:50 +02:00
c0cd965566 build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.2.0 to 6.2.1 (#816) 2023-08-07 11:53:26 +02:00
66268c5fbe build(deps): bump @types/node from 20.4.5 to 20.4.8 (#815) 2023-08-07 11:53:08 +02:00
2ab8c4423e build(deps-dev): bump @typescript-eslint/parser from 6.1.0 to 6.2.0 (#812) 2023-07-31 13:48:18 +02:00
2c52863893 build(deps-dev): bump eslint-config-prettier from 8.8.0 to 8.9.0 (#811) 2023-07-31 13:47:58 +02:00
77db3f966c build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.1.0 to 6.2.0 (#810) 2023-07-31 12:44:38 +02:00
797977b61a build(deps): bump @types/node from 20.4.4 to 20.4.5 (#809) 2023-07-31 12:44:15 +02:00
015f418198 build(deps-dev): bump eslint-plugin-import from 2.27.5 to 2.28.0 (#808) 2023-07-31 12:43:55 +02:00
88ae11c65f build(deps-dev): bump @typescript-eslint/parser from 6.0.0 to 6.1.0 (#805) 2023-07-24 13:37:35 +02:00
51e800db2c build(deps-dev): bump @typescript-eslint/eslint-plugin from 6.0.0 to 6.1.0 (#804) 2023-07-24 13:22:06 +02:00
f05002851f build(deps): bump @types/node from 20.4.2 to 20.4.4 (#803) 2023-07-24 13:10:24 +02:00
b39364735e build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.61.0 to 6.0.0 (#800)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-07-24 13:10:01 +02:00
a657dba833 build(deps-dev): bump eslint from 8.44.0 to 8.45.0 (#801) 2023-07-17 12:50:38 +02:00
ba65924209 build(deps-dev): bump @typescript-eslint/parser from 5.61.0 to 5.62.0 (#799) 2023-07-17 12:50:09 +02:00
c0edea7835 build(deps): bump @types/node from 20.4.1 to 20.4.2 (#798) 2023-07-17 12:49:43 +02:00
a1145a6b27 build(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#794)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-07-11 10:25:55 +02:00
83e5ccebf6 chore: flag dist as generated 2023-07-11 10:12:11 +02:00
8457318a42 build(deps): bump semver from 6.3.0 to 6.3.1 (#796)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2023-07-11 08:10:27 +00:00
a422a812eb build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.60.1 to 5.61.0 (#793) 2023-07-10 12:40:10 +02:00
84836b13d8 build(deps-dev): bump @typescript-eslint/parser from 5.60.1 to 5.61.0 (#792) 2023-07-10 12:18:16 +02:00
360e5b76ee build(deps): bump @types/node from 20.3.3 to 20.4.1 (#791) 2023-07-10 12:17:51 +02:00
42ba3c24d6 build(deps): bump tough-cookie and @azure/ms-rest-js (#790) 2023-07-09 13:04:43 +02:00
4f5a3af221 build(deps-dev): bump eslint from 8.43.0 to 8.44.0 (#788) 2023-07-03 14:30:48 +02:00
f1690ab489 build(deps-dev): bump typescript from 5.1.3 to 5.1.6 (#787) 2023-07-03 14:15:42 +02:00
98d324947b build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.60.0 to 5.60.1 (#786) 2023-07-03 14:15:16 +02:00
5326fa0045 build(deps-dev): bump @typescript-eslint/parser from 5.60.0 to 5.60.1 (#785) 2023-07-03 13:49:40 +02:00
4d9aae64da build(deps): bump @types/node from 20.3.1 to 20.3.3 (#784) 2023-07-03 13:49:17 +02:00
d29c0cc90a build(deps-dev): bump @typescript-eslint/parser from 5.59.11 to 5.60.0 (#783) 2023-06-26 14:05:38 +00:00
28fa3382e3 build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.59.11 to 5.60.0 (#782) 2023-06-26 13:37:32 +02:00
715abd3467 docs: improve How to use section in README.md (#780) 2023-06-24 11:02:32 +00:00
01827479ce build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.59.9 to 5.59.11 (#778) 2023-06-19 12:32:48 +00:00
05fe2da5ec build(deps): bump @types/node from 20.3.0 to 20.3.1 (#777) 2023-06-19 14:20:36 +02:00
2a20098909 build(deps-dev): bump eslint from 8.42.0 to 8.43.0 (#775) 2023-06-19 14:20:27 +02:00
71a9ad5faf build(deps-dev): bump @typescript-eslint/parser from 5.59.9 to 5.59.11 (#776) 2023-06-19 14:20:18 +02:00
b814b8606f chore: flag dist as generated 2023-06-13 11:28:19 +02:00
455ad55fab docs: improve changelog 2023-06-12 20:11:09 +02:00
cde40a3b90 docs: fix default value 2023-06-12 20:07:33 +02:00
444727df93 chore: exclude dependencies PRs from changelog 2023-06-12 19:29:58 +02:00
aca98fe711 chore: exclude dependabot from changelog 2023-06-12 19:22:53 +02:00
8078b42bbd docs: improve version description 2023-06-12 16:12:46 +02:00
1577f9c80c build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.59.8 to 5.59.9 (#773) 2023-06-12 10:22:58 +00:00
313d11ed7d build(deps-dev): bump @typescript-eslint/parser from 5.59.8 to 5.59.9 (#772) 2023-06-12 12:14:22 +02:00
907f20a45e build(deps): bump @types/node from 20.2.5 to 20.3.0 (#771) 2023-06-12 12:14:13 +02:00
11 changed files with 2981 additions and 1526 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
dist/** linguist-generated=true

15
.github/release.yml vendored Normal file
View File

@ -0,0 +1,15 @@
changelog:
categories:
- title: Changes
labels:
- '*'
exclude:
labels:
- documentation
- dependencies
- title: Documentation
labels:
- documentation
- title: Dependencies
labels:
- dependencies

View File

@ -46,32 +46,34 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v3
with: with:
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version # Require: 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.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.53 version: v1.53
# Optional: working directory, useful for monorepos # Optional: working directory, useful for monorepos
# working-directory: somedir # working-directory: somedir
# Optional: golangci-lint command line arguments. # Optional: golangci-lint command line arguments.
# #
# Note: by default the `.golangci.yml` file should be at the root of the repository. # Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=` # The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`. # Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true # only-new-issues: true
# Optional: if set to true then the all caching functionality will be complete disabled, # Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options. # takes precedence over all other caching options.
# skip-cache: true # skip-cache: true
# Optional: if set to true then the action don't cache or restore ~/go/pkg. # Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true # skip-pkg-cache: true
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build. # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true # skip-build-cache: true
# Optional:The mode to install golangci-lint. It can be 'binary' or 'goinstall'. # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall" # install-mode: "goinstall"
``` ```
@ -113,7 +115,9 @@ jobs:
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v3
with: with:
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version # Require: 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.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.53 version: v1.53
# Optional: working directory, useful for monorepos # Optional: working directory, useful for monorepos

View File

@ -3,7 +3,10 @@ description: "Official golangci-lint action with line-attached annotations for f
author: "golangci" author: "golangci"
inputs: inputs:
version: version:
description: "version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version" 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.
When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
required: false required: false
args: args:
description: "golangci-lint command line arguments" description: "golangci-lint command line arguments"
@ -18,21 +21,21 @@ inputs:
required: false required: false
only-new-issues: only-new-issues:
description: "if set to true and the action runs on a pull request - the action outputs only newly found issues" description: "if set to true and the action runs on a pull request - the action outputs only newly found issues"
default: false default: 'false'
required: false required: false
skip-cache: skip-cache:
description: | description: |
if set to true then the all caching functionality will be complete disabled, if set to true then the all caching functionality will be complete disabled,
takes precedence over all other caching options. takes precedence over all other caching options.
default: false default: 'false'
required: false required: false
skip-pkg-cache: skip-pkg-cache:
description: "if set to true then the action doesn't cache or restore ~/go/pkg." description: "if set to true then the action doesn't cache or restore ~/go/pkg."
default: false default: 'false'
required: false required: false
skip-build-cache: skip-build-cache:
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build." description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
default: false default: 'false'
required: false required: false
install-mode: install-mode:
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'." description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."

1064
dist/post_run/index.js generated vendored

File diff suppressed because it is too large Load Diff

1064
dist/run/index.js generated vendored

File diff suppressed because it is too large Load Diff

2241
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,27 +24,27 @@
"author": "golangci", "author": "golangci",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.2.1", "@actions/cache": "^3.2.2",
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@actions/http-client": "^2.1.0", "@actions/http-client": "^2.1.1",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@types/node": "^20.2.5", "@types/node": "^20.5.0",
"@types/semver": "^7.5.0", "@types/semver": "^7.5.0",
"@types/tmp": "^0.2.3", "@types/tmp": "^0.2.3",
"tmp": "^0.2.1" "tmp": "^0.2.1"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.8", "@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^5.59.8", "@typescript-eslint/parser": "^6.3.0",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.42.0", "eslint": "^8.47.0",
"eslint-config-prettier": "^8.8.0", "eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.27.5", "eslint-plugin-import": "^2.28.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-simple-import-sort": "^10.0.0",
"prettier": "^2.8.8", "prettier": "^3.0.1",
"typescript": "^5.1.3" "typescript": "^5.1.6"
} }
} }

View File

@ -8,6 +8,7 @@ import { promisify } from "util"
import { restoreCache, saveCache } from "./cache" import { restoreCache, saveCache } from "./cache"
import { installLint, InstallMode } from "./install" import { installLint, InstallMode } from "./install"
import { alterDiffPatch } from "./utils/diffUtils"
import { findLintVersion } from "./version" import { findLintVersion } from "./version"
const execShellCommand = promisify(exec) const execShellCommand = promisify(exec)
@ -68,7 +69,7 @@ async function fetchPatch(): Promise<string> {
const tempDir = await createTempDir() const tempDir = await createTempDir()
const patchPath = path.join(tempDir, "pull.patch") const patchPath = path.join(tempDir, "pull.patch")
core.info(`Writing patch to ${patchPath}`) core.info(`Writing patch to ${patchPath}`)
await writeFile(patchPath, patch) await writeFile(patchPath, alterDiffPatch(patch))
return patchPath return patchPath
} catch (err) { } catch (err) {
console.warn(`failed to save pull request patch:`, err) console.warn(`failed to save pull request patch:`, err)
@ -157,10 +158,6 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
const workingDirectory = core.getInput(`working-directory`) const workingDirectory = core.getInput(`working-directory`)
const cmdArgs: ExecOptions = {} const cmdArgs: ExecOptions = {}
if (workingDirectory) { if (workingDirectory) {
if (patchPath) {
// TODO: make them compatible
throw new Error(`options working-directory and only-new-issues aren't compatible`)
}
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
throw new Error(`working-directory (${workingDirectory}) was not a path`) throw new Error(`working-directory (${workingDirectory}) was not a path`)
} }

56
src/utils/diffUtils.ts Normal file
View File

@ -0,0 +1,56 @@
import * as core from "@actions/core"
import * as path from "path"
// If needed alter diff file to be compatible with working directory
export function alterDiffPatch(patch: string): string {
const workingDirectory = core.getInput(`working-directory`)
if (workingDirectory) {
return alterPatchWithWorkingDirectory(patch, workingDirectory)
}
return patch
}
function alterPatchWithWorkingDirectory(patch: string, workingDirectory: string): string {
const workspace = process.env["GITHUB_WORKSPACE"] || ""
const wd = path.relative(workspace, workingDirectory)
// ignore diff sections not related to the working directory
let ignore = false
const lines = patch.split("\n")
const filteredLines = []
// starts with "--- a/xxx/" or "+++ a/xxx/" or "--- b/xxx/" or "+++ b/xxx/"
const cleanDiff = new RegExp(`^((?:\\+{3}|-{3}) [ab]\\/)${escapeRegExp(wd)}\\/(.*)`, "gm")
// contains " a/xxx/" or " b/xxx/"
const firstLine = new RegExp(`( [ab]\\/)${escapeRegExp(wd)}\\/(.*)`, "gm")
for (const line of lines) {
if (line.startsWith("diff --git")) {
ignore = !line.includes(` a/${wd}/`)
if (ignore) {
continue
}
filteredLines.push(line.replaceAll(firstLine, "$1$2"))
} else {
if (ignore) {
continue
}
filteredLines.push(line.replaceAll(cleanDiff, "$1$2"))
}
}
// Join the modified lines back into a diff string
return filteredLines.join("\n")
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(exp: string): string {
return exp.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
}

View File

@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "ES2021", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */ "outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */