Compare commits
98 Commits
v3.6.0
...
4b1e98b37d
Author | SHA1 | Date | |
---|---|---|---|
|
4b1e98b37d | ||
|
5a72764667 | ||
|
30416f05a0 | ||
|
a555e8cdd0 | ||
|
c8710f274e | ||
|
40776d7557 | ||
|
9cb5ef734c | ||
|
62f96762dd | ||
|
84072ff78e | ||
|
a625c15a6b | ||
|
5545aac6a3 | ||
|
e09eda33b5 | ||
|
526ce234e5 | ||
|
507ec96a74 | ||
|
252bd8e8ba | ||
|
07341d3490 | ||
|
9df6f480ac | ||
|
6f4d254d44 | ||
|
a24255b274 | ||
|
c12092e88f | ||
|
031ba7f7a9 | ||
|
c8d4ef2f53 | ||
|
31c1b1aa98 | ||
|
31eb4eaded | ||
|
5f5f252fe2 | ||
|
c624d54a53 | ||
|
d735dc073f | ||
|
846e7ddcd9 | ||
|
d66278f1e9 | ||
|
1afd74ce23 | ||
|
c67416616c | ||
|
29052a94fb | ||
|
2d06cf1746 | ||
|
953db97e74 | ||
|
f7b4bdd2ad | ||
|
239c8dab36 | ||
|
237bd9f909 | ||
|
fef6a0f2be | ||
|
2d891f879c | ||
|
1e9c424622 | ||
|
cf670955c6 | ||
|
c49c2afa5d | ||
|
81871bcfd1 | ||
|
b2f426ba19 | ||
|
f8a3dc114e | ||
|
1330ad3e73 | ||
|
6efbbade29 | ||
|
3a91952989 | ||
|
5e676315e9 | ||
|
18dad33d2e | ||
|
945dc98b91 | ||
|
cac24f53b7 | ||
|
ab66454db6 | ||
|
a2527500a4 | ||
|
44d9998d44 | ||
|
b6bdfb3d14 | ||
|
c0cd965566 | ||
|
66268c5fbe | ||
|
2ab8c4423e | ||
|
2c52863893 | ||
|
77db3f966c | ||
|
797977b61a | ||
|
015f418198 | ||
|
88ae11c65f | ||
|
51e800db2c | ||
|
f05002851f | ||
|
b39364735e | ||
|
a657dba833 | ||
|
ba65924209 | ||
|
c0edea7835 | ||
|
a1145a6b27 | ||
|
83e5ccebf6 | ||
|
8457318a42 | ||
|
a422a812eb | ||
|
84836b13d8 | ||
|
360e5b76ee | ||
|
42ba3c24d6 | ||
|
4f5a3af221 | ||
|
f1690ab489 | ||
|
98d324947b | ||
|
5326fa0045 | ||
|
4d9aae64da | ||
|
d29c0cc90a | ||
|
28fa3382e3 | ||
|
715abd3467 | ||
|
01827479ce | ||
|
05fe2da5ec | ||
|
2a20098909 | ||
|
71a9ad5faf | ||
|
b814b8606f | ||
|
455ad55fab | ||
|
cde40a3b90 | ||
|
444727df93 | ||
|
aca98fe711 | ||
|
8078b42bbd | ||
|
1577f9c80c | ||
|
313d11ed7d | ||
|
907f20a45e |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
dist/** linguist-generated=true
|
15
.github/release.yml
vendored
Normal file
15
.github/release.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: Changes
|
||||
labels:
|
||||
- '*'
|
||||
exclude:
|
||||
labels:
|
||||
- documentation
|
||||
- dependencies
|
||||
- title: Documentation
|
||||
labels:
|
||||
- documentation
|
||||
- title: Dependencies
|
||||
labels:
|
||||
- dependencies
|
2
.github/workflows/codeql.yaml
vendored
2
.github/workflows/codeql.yaml
vendored
@@ -16,7 +16,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# Must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head of the pull request.
|
||||
|
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
@@ -11,9 +11,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- if: ${{ !(github.event_name == 'pull_request' && (github.event.pull_request.user.id == 49699333 || contains(github.event.pull_request.labels.*.name, 'dependencies'))) }}
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- if: github.event_name == 'pull_request' && (github.event.pull_request.user.id == 49699333 || contains(github.event.pull_request.labels.*.name, 'dependencies'))
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
@@ -87,7 +87,7 @@ jobs:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
@@ -110,7 +110,7 @@ jobs:
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
cache: false # setup-go v4 caches by default
|
||||
|
30
README.md
30
README.md
@@ -41,37 +41,39 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20'
|
||||
go-version: '1.21'
|
||||
cache: false
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
# 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.54
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# 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=`
|
||||
# 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`.
|
||||
# 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.
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
```
|
||||
|
||||
@@ -100,7 +102,7 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go: ['1.20']
|
||||
go: ['1.21']
|
||||
os: [macos-latest, windows-latest]
|
||||
name: lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -113,8 +115,10 @@ jobs:
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
# Require: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.53
|
||||
# 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.54
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
15
action.yml
15
action.yml
@@ -3,7 +3,10 @@ description: "Official golangci-lint action with line-attached annotations for f
|
||||
author: "golangci"
|
||||
inputs:
|
||||
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
|
||||
args:
|
||||
description: "golangci-lint command line arguments"
|
||||
@@ -18,28 +21,28 @@ inputs:
|
||||
required: false
|
||||
only-new-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
|
||||
skip-cache:
|
||||
description: |
|
||||
if set to true then the all caching functionality will be complete disabled,
|
||||
takes precedence over all other caching options.
|
||||
default: false
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-pkg-cache:
|
||||
description: "if set to true then the action doesn't cache or restore ~/go/pkg."
|
||||
default: false
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-build-cache:
|
||||
description: "if set to true then the action doesn't cache or restore ~/.cache/go-build."
|
||||
default: false
|
||||
default: 'false'
|
||||
required: false
|
||||
install-mode:
|
||||
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
|
||||
default: "binary"
|
||||
required: false
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "dist/run/index.js"
|
||||
post: "dist/post_run/index.js"
|
||||
branding:
|
||||
|
27772
dist/post_run/index.js
generated
vendored
27772
dist/post_run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
27772
dist/run/index.js
generated
vendored
27772
dist/run/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2649
package-lock.json
generated
2649
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@@ -24,27 +24,27 @@
|
||||
"author": "golangci",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.2.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/cache": "^3.2.2",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@actions/http-client": "^2.1.0",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/http-client": "^2.2.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@types/tmp": "^0.2.3",
|
||||
"@types/node": "^20.8.6",
|
||||
"@types/semver": "^7.5.3",
|
||||
"@types/tmp": "^0.2.4",
|
||||
"tmp": "^0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
||||
"@typescript-eslint/parser": "^6.7.5",
|
||||
"@vercel/ncc": "^0.38.0",
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"typescript": "^5.1.3"
|
||||
"prettier": "^3.0.3",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import { promisify } from "util"
|
||||
|
||||
import { restoreCache, saveCache } from "./cache"
|
||||
import { installLint, InstallMode } from "./install"
|
||||
import { alterDiffPatch } from "./utils/diffUtils"
|
||||
import { findLintVersion } from "./version"
|
||||
|
||||
const execShellCommand = promisify(exec)
|
||||
@@ -68,7 +69,7 @@ async function fetchPatch(): Promise<string> {
|
||||
const tempDir = await createTempDir()
|
||||
const patchPath = path.join(tempDir, "pull.patch")
|
||||
core.info(`Writing patch to ${patchPath}`)
|
||||
await writeFile(patchPath, patch)
|
||||
await writeFile(patchPath, alterDiffPatch(patch))
|
||||
return patchPath
|
||||
} catch (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 cmdArgs: ExecOptions = {}
|
||||
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()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
||||
}
|
||||
|
56
src/utils/diffUtils.ts
Normal file
56
src/utils/diffUtils.ts
Normal 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
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"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'. */
|
||||
"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. */
|
||||
|
Reference in New Issue
Block a user