Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
639cd343e1 | |||
569abaa281 | |||
c57cc43669 | |||
322510a3ea | |||
185e7a2f8f | |||
5be60c708e | |||
825a50d3a2 | |||
8c13ec4e5d | |||
416b5d0b48 | |||
66a608006f | |||
f0ba586c1f | |||
b8fff06a27 |
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
|
37
.github/workflows/test.yml
vendored
37
.github/workflows/test.yml
vendored
@ -52,8 +52,8 @@ jobs:
|
|||||||
version:
|
version:
|
||||||
- ""
|
- ""
|
||||||
- "latest"
|
- "latest"
|
||||||
- "v1.51"
|
- "v1.53"
|
||||||
- "v1.51.2"
|
- "v1.53.2"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@ -66,9 +66,38 @@ jobs:
|
|||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
args: --timeout=3m --issues-exit-code=0 ./sample/...
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
|
||||||
|
test-go-install: # make sure the action works on a clean machine without building (go-install mode)
|
||||||
|
needs: [ build ]
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
|
version:
|
||||||
|
- ""
|
||||||
|
- "latest"
|
||||||
|
- "v1.53.2"
|
||||||
|
- "b5093688c0d3008eaacd6066773a1a52e689252f"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
cache: false # setup-go v4 caches by default
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ matrix.version }}
|
||||||
|
args: --timeout=5m --issues-exit-code=0 ./sample/...
|
||||||
|
only-new-issues: true
|
||||||
|
install-mode: goinstall
|
||||||
|
|
||||||
test-go-mod-version:
|
test-go-mod-version:
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
strategy:
|
strategy:
|
||||||
@ -88,4 +117,4 @@ jobs:
|
|||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
working-directory: sample-go-mod
|
working-directory: sample-go-mod
|
||||||
args: --timeout=3m --issues-exit-code=0 ./...
|
args: --timeout=5m --issues-exit-code=0 ./...
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -97,3 +97,6 @@ typings/
|
|||||||
|
|
||||||
# Text editor files
|
# Text editor files
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# IntelliJ/WebStorm files
|
||||||
|
.idea
|
||||||
|
49
README.md
49
README.md
@ -23,50 +23,58 @@ Add `.github/workflows/golangci-lint.yml` with the following contents:
|
|||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
|
||||||
- v*
|
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||||
# pull-requests: read
|
# pull-requests: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
golangci:
|
golangci:
|
||||||
name: lint
|
name: lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '1.17'
|
go-version: '1.20'
|
||||||
cache: false
|
cache: false
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
# Optional: 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.
|
||||||
version: v1.29
|
# 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
|
||||||
|
|
||||||
# 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.
|
||||||
# args: --issues-exit-code=0
|
#
|
||||||
|
# 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`.
|
# 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'.
|
||||||
|
# install-mode: "goinstall"
|
||||||
```
|
```
|
||||||
|
|
||||||
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
||||||
@ -80,21 +88,21 @@ If you need to run linters for specific operating systems, you will need to use
|
|||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
|
||||||
- v*
|
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||||
# pull-requests: read
|
# pull-requests: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
golangci:
|
golangci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go: [1.17]
|
go: ['1.20']
|
||||||
os: [macos-latest, windows-latest]
|
os: [macos-latest, windows-latest]
|
||||||
name: lint
|
name: lint
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@ -107,16 +115,25 @@ jobs:
|
|||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Require: The version of golangci-lint to use.
|
||||||
version: v1.29
|
# 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
|
||||||
|
|
||||||
# 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.
|
||||||
# args: --issues-exit-code=0
|
#
|
||||||
|
# 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`.
|
# 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:The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
|
||||||
|
# install-mode: "goinstall"
|
||||||
```
|
```
|
||||||
|
|
||||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for windows builds are properly formatted:
|
You will also likely need to add the following `.gitattributes` file to ensure that line endings for windows builds are properly formatted:
|
||||||
|
17
action.yml
17
action.yml
@ -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,25 @@ 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
|
||||||
|
install-mode:
|
||||||
|
description: "The mode to install golangci-lint. It can be 'binary' or 'goinstall'."
|
||||||
|
default: "binary"
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
|
1077
dist/post_run/index.js
generated
vendored
1077
dist/post_run/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
1077
dist/run/index.js
generated
vendored
1077
dist/run/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2259
package-lock.json
generated
2259
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -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.7",
|
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
||||||
"@typescript-eslint/parser": "^5.59.7",
|
"@typescript-eslint/parser": "^6.3.0",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.36.1",
|
||||||
"eslint": "^8.41.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.0.4"
|
"typescript": "^5.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as tc from "@actions/tool-cache"
|
import * as tc from "@actions/tool-cache"
|
||||||
|
import { exec, ExecOptions } from "child_process"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { promisify } from "util"
|
||||||
|
|
||||||
import { VersionConfig } from "./version"
|
import { VersionConfig } from "./version"
|
||||||
|
|
||||||
|
const execShellCommand = promisify(exec)
|
||||||
|
|
||||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
||||||
|
|
||||||
const getAssetURL = (versionConfig: VersionConfig): string => {
|
const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||||
@ -31,13 +35,95 @@ const getAssetURL = (versionConfig: VersionConfig): string => {
|
|||||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// The installLint returns path to installed binary of golangci-lint.
|
export enum InstallMode {
|
||||||
export async function installLint(versionConfig: VersionConfig): Promise<string> {
|
Binary = "binary",
|
||||||
|
GoInstall = "goinstall",
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExecRes = {
|
||||||
|
stdout: string
|
||||||
|
stderr: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const printOutput = (res: ExecRes): void => {
|
||||||
|
if (res.stdout) {
|
||||||
|
core.info(res.stdout)
|
||||||
|
}
|
||||||
|
if (res.stderr) {
|
||||||
|
core.info(res.stderr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @param mode installation mode.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function installLint(versionConfig: VersionConfig, mode: InstallMode): Promise<string> {
|
||||||
|
core.info(`Installation mode: ${mode}`)
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case InstallMode.Binary:
|
||||||
|
return installBin(versionConfig)
|
||||||
|
case InstallMode.GoInstall:
|
||||||
|
return goInstall(versionConfig)
|
||||||
|
default:
|
||||||
|
return installBin(versionConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via `go install`.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function goInstall(versionConfig: VersionConfig): Promise<string> {
|
||||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
|
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
|
const options: ExecOptions = { env: { ...process.env, CGO_ENABLED: "1" } }
|
||||||
|
|
||||||
|
const exres = await execShellCommand(
|
||||||
|
`go install github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
printOutput(exres)
|
||||||
|
|
||||||
|
const res = await execShellCommand(
|
||||||
|
`go install -n github.com/golangci/golangci-lint/cmd/golangci-lint@${versionConfig.TargetVersion}`,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
printOutput(res)
|
||||||
|
|
||||||
|
// The output of `go install -n` when the binary is already installed is `touch <path_to_the_binary>`.
|
||||||
|
const lintPath = res.stderr.trimStart().trimEnd().split(` `, 2)[1]
|
||||||
|
|
||||||
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
|
return lintPath
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install golangci-lint via the precompiled binary.
|
||||||
|
*
|
||||||
|
* @param versionConfig information about version to install.
|
||||||
|
* @returns path to installed binary of golangci-lint.
|
||||||
|
*/
|
||||||
|
export async function installBin(versionConfig: VersionConfig): Promise<string> {
|
||||||
|
core.info(`Installing golangci-lint binary ${versionConfig.TargetVersion}...`)
|
||||||
|
|
||||||
|
const startedAt = Date.now()
|
||||||
|
|
||||||
const assetURL = getAssetURL(versionConfig)
|
const assetURL = getAssetURL(versionConfig)
|
||||||
core.info(`Downloading ${assetURL} ...`)
|
|
||||||
|
core.info(`Downloading binary ${assetURL} ...`)
|
||||||
|
|
||||||
const archivePath = await tc.downloadTool(assetURL)
|
const archivePath = await tc.downloadTool(assetURL)
|
||||||
|
|
||||||
let extractedDir = ""
|
let extractedDir = ""
|
||||||
let repl = /\.tar\.gz$/
|
let repl = /\.tar\.gz$/
|
||||||
if (assetURL.endsWith("zip")) {
|
if (assetURL.endsWith("zip")) {
|
||||||
@ -55,6 +141,8 @@ export async function installLint(versionConfig: VersionConfig): Promise<string>
|
|||||||
const urlParts = assetURL.split(`/`)
|
const urlParts = assetURL.split(`/`)
|
||||||
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
|
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
|
||||||
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
|
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
|
||||||
|
|
||||||
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
return lintPath
|
return lintPath
|
||||||
}
|
}
|
||||||
|
58
src/run.ts
58
src/run.ts
@ -7,7 +7,8 @@ import { dir } from "tmp"
|
|||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
|
|
||||||
import { restoreCache, saveCache } from "./cache"
|
import { restoreCache, saveCache } from "./cache"
|
||||||
import { installLint } 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)
|
||||||
@ -15,8 +16,10 @@ const writeFile = promisify(fs.writeFile)
|
|||||||
const createTempDir = promisify(dir)
|
const createTempDir = promisify(dir)
|
||||||
|
|
||||||
async function prepareLint(): Promise<string> {
|
async function prepareLint(): Promise<string> {
|
||||||
const versionConfig = await findLintVersion()
|
const mode = core.getInput("install-mode").toLowerCase()
|
||||||
return await installLint(versionConfig)
|
const versionConfig = await findLintVersion(<InstallMode>mode)
|
||||||
|
|
||||||
|
return await installLint(versionConfig, <InstallMode>mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchPatch(): Promise<string> {
|
async function fetchPatch(): Promise<string> {
|
||||||
@ -66,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)
|
||||||
@ -83,15 +86,15 @@ async function prepareEnv(): Promise<Env> {
|
|||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
// Prepare cache, lint and go in parallel.
|
// Prepare cache, lint and go in parallel.
|
||||||
const restoreCachePromise = restoreCache()
|
await restoreCache()
|
||||||
const prepareLintPromise = prepareLint()
|
const prepareLintPromise = prepareLint()
|
||||||
const patchPromise = fetchPatch()
|
const patchPromise = fetchPatch()
|
||||||
|
|
||||||
const lintPath = await prepareLintPromise
|
const lintPath = await prepareLintPromise
|
||||||
await restoreCachePromise
|
|
||||||
const patchPath = await patchPromise
|
const patchPath = await patchPromise
|
||||||
|
|
||||||
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
core.info(`Prepared env in ${Date.now() - startedAt}ms`)
|
||||||
|
|
||||||
return { lintPath, patchPath }
|
return { lintPath, patchPath }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,21 +119,30 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
|||||||
printOutput(res)
|
printOutput(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
const userArgs = core.getInput(`args`)
|
let userArgs = core.getInput(`args`)
|
||||||
const addedArgs: string[] = []
|
const addedArgs: string[] = []
|
||||||
|
|
||||||
const userArgNames = new Set<string>(
|
const userArgsList = userArgs
|
||||||
userArgs
|
.trim()
|
||||||
.trim()
|
.split(/\s+/)
|
||||||
.split(/\s+/)
|
.filter((arg) => arg.startsWith(`-`))
|
||||||
.map((arg) => arg.split(`=`)[0])
|
.map((arg) => arg.replace(/^-+/, ``))
|
||||||
.filter((arg) => arg.startsWith(`-`))
|
.map((arg) => arg.split(/=(.*)/, 2))
|
||||||
.map((arg) => arg.replace(/^-+/, ``))
|
.map<[string, string]>(([key, value]) => [key.toLowerCase(), value ?? ""])
|
||||||
)
|
|
||||||
if (userArgNames.has(`out-format`)) {
|
const userArgsMap = new Map<string, string>(userArgsList)
|
||||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`)
|
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))
|
||||||
}
|
|
||||||
addedArgs.push(`--out-format=github-actions`)
|
const formats = (userArgsMap.get("out-format") || "")
|
||||||
|
.trim()
|
||||||
|
.split(",")
|
||||||
|
.filter((f) => f.length > 0)
|
||||||
|
.filter((f) => !f.startsWith(`github-actions`))
|
||||||
|
.concat("github-actions")
|
||||||
|
.join(",")
|
||||||
|
|
||||||
|
addedArgs.push(`--out-format=${formats}`)
|
||||||
|
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()
|
||||||
|
|
||||||
if (patchPath) {
|
if (patchPath) {
|
||||||
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`)) {
|
||||||
@ -146,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`)
|
||||||
}
|
}
|
||||||
@ -159,8 +167,10 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
|||||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimRight()
|
const cmd = `${lintPath} run ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
|
||||||
|
|
||||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`)
|
core.info(`Running [${cmd}] in [${cmdArgs.cwd || ``}] ...`)
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
try {
|
try {
|
||||||
const res = await execShellCommand(cmd, cmdArgs)
|
const res = await execShellCommand(cmd, cmdArgs)
|
||||||
|
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
|
||||||
|
}
|
@ -3,6 +3,8 @@ import * as httpm from "@actions/http-client"
|
|||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
|
||||||
|
import { InstallMode } from "./install"
|
||||||
|
|
||||||
// TODO: make a class
|
// TODO: make a class
|
||||||
export type Version = {
|
export type Version = {
|
||||||
major: number
|
major: number
|
||||||
@ -17,6 +19,7 @@ const parseVersion = (s: string): Version => {
|
|||||||
if (s == "latest" || s == "") {
|
if (s == "latest" || s == "") {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = s.match(versionRe)
|
const match = s.match(versionRe)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
||||||
@ -61,6 +64,7 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
|||||||
const getRequestedLintVersion = (): Version => {
|
const getRequestedLintVersion = (): Version => {
|
||||||
let requestedLintVersion = core.getInput(`version`)
|
let requestedLintVersion = core.getInput(`version`)
|
||||||
const workingDirectory = core.getInput(`working-directory`)
|
const workingDirectory = core.getInput(`working-directory`)
|
||||||
|
|
||||||
let goMod = "go.mod"
|
let goMod = "go.mod"
|
||||||
if (workingDirectory) {
|
if (workingDirectory) {
|
||||||
goMod = path.join(workingDirectory, goMod)
|
goMod = path.join(workingDirectory, goMod)
|
||||||
@ -79,6 +83,7 @@ const getRequestedLintVersion = (): Version => {
|
|||||||
if (parsedRequestedLintVersion == null) {
|
if (parsedRequestedLintVersion == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
|
if (isLessVersion(parsedRequestedLintVersion, minVersion)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
|
`requested golangci-lint version '${requestedLintVersion}' isn't supported: we support only ${stringifyVersion(
|
||||||
@ -86,6 +91,7 @@ const getRequestedLintVersion = (): Version => {
|
|||||||
)} and later versions`
|
)} and later versions`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedRequestedLintVersion
|
return parsedRequestedLintVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,9 +126,16 @@ const getConfig = async (): Promise<Config> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findLintVersion(): Promise<VersionConfig> {
|
export async function findLintVersion(mode: InstallMode): Promise<VersionConfig> {
|
||||||
core.info(`Finding needed golangci-lint version...`)
|
core.info(`Finding needed golangci-lint version...`)
|
||||||
|
|
||||||
|
if (mode == InstallMode.GoInstall) {
|
||||||
|
const v: string = core.getInput(`version`)
|
||||||
|
return { TargetVersion: v ? v : "latest", AssetURL: "github.com/golangci/golangci-lint" }
|
||||||
|
}
|
||||||
|
|
||||||
const reqLintVersion = getRequestedLintVersion()
|
const reqLintVersion = getRequestedLintVersion()
|
||||||
|
|
||||||
// if the patched version is passed, just use it
|
// if the patched version is passed, just use it
|
||||||
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
|
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -133,6 +146,7 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
const config = await getConfig()
|
const config = await getConfig()
|
||||||
@ -155,5 +169,6 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
|||||||
Date.now() - startedAt
|
Date.now() - startedAt
|
||||||
}ms`
|
}ms`
|
||||||
)
|
)
|
||||||
|
|
||||||
return versionConfig
|
return versionConfig
|
||||||
}
|
}
|
||||||
|
@ -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. */
|
||||||
|
Reference in New Issue
Block a user