Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
544d2efb30 | |||
0dd30832fc | |||
e1ae6cf354 | |||
0ef0ffc44e | |||
125ac487c1 | |||
e246bba31d | |||
147f37a473 | |||
a19645e82f | |||
286cf073ea | |||
7641a6707d | |||
e4e910b0ce | |||
89d96d6c20 | |||
45f3a377de | |||
943013ec20 | |||
49a9e469b1 | |||
528677aa24 | |||
85798b53e5 | |||
d164f0d6d8 | |||
9cf34bb2b8 | |||
629aad184c | |||
1bac7d9888 | |||
44fae30515 | |||
689e90e8a0 | |||
d73150ab3c | |||
2c3839ff26 | |||
f881d993a0 | |||
d3f3b8adb7 | |||
e3e2a92cbd | |||
e1bd4355fb | |||
345e5340e3 | |||
13e9e901f4 | |||
771153bfbc | |||
e868220d9f | |||
0348c21999 | |||
a1c5369c06 | |||
90fbd40fc4 | |||
3d2a5790a3 |
@ -1,7 +1,13 @@
|
|||||||
{
|
{
|
||||||
"env": { "node": true, "jest": true },
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": { "ecmaVersion": 2020, "sourceType": "module" },
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2020,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"eslint:recommended",
|
||||||
"plugin:@typescript-eslint/eslint-recommended",
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
@ -12,12 +18,16 @@
|
|||||||
"plugin:prettier/recommended",
|
"plugin:prettier/recommended",
|
||||||
"prettier/@typescript-eslint"
|
"prettier/@typescript-eslint"
|
||||||
],
|
],
|
||||||
"plugins": ["@typescript-eslint", "simple-import-sort"],
|
"plugins": [
|
||||||
|
"@typescript-eslint",
|
||||||
|
"simple-import-sort"
|
||||||
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"import/first": "error",
|
"import/first": "error",
|
||||||
"import/newline-after-import": "error",
|
"import/newline-after-import": "error",
|
||||||
"import/no-duplicates": "error",
|
"import/no-duplicates": "error",
|
||||||
"simple-import-sort/sort": "error",
|
"simple-import-sort/imports": "error",
|
||||||
|
"simple-import-sort/exports": "error",
|
||||||
"sort-imports": "off"
|
"sort-imports": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
44
.github/workflows/codeql.yaml
vendored
Normal file
44
.github/workflows/codeql.yaml
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
name: "Code Scanning - Action"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 17 * * 5'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
codeQL:
|
||||||
|
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
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.
|
||||||
|
# Only include this option if you are running this workflow on pull requests.
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
# If this run was triggered by a pull request event then checkout
|
||||||
|
# the head of the pull request instead of the merge commit.
|
||||||
|
# Only include this step if you are running this workflow on pull requests.
|
||||||
|
- run: git checkout HEAD^2
|
||||||
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
|
with:
|
||||||
|
language: 'javascript'
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
npm install
|
||||||
|
npm run all
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
17
.github/workflows/test.yml
vendored
17
.github/workflows/test.yml
vendored
@ -29,3 +29,20 @@ jobs:
|
|||||||
version: latest
|
version: latest
|
||||||
args: --issues-exit-code=0 ./sample/...
|
args: --issues-exit-code=0 ./sample/...
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
|
||||||
|
# Test with full version vX.Y.Z
|
||||||
|
test-full-version:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
version: v1.28.3
|
||||||
|
args: --issues-exit-code=0 ./sample/...
|
||||||
|
only-new-issues: true
|
||||||
|
11
README.md
11
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://github.com/golangci/golangci-lint-action/actions)
|
[](https://github.com/golangci/golangci-lint-action/actions)
|
||||||
|
|
||||||
It's the official GitHub action for [golangci-lint](https://github.com/golangci/golangci-lint) from it's authors.
|
It's the official GitHub action for [golangci-lint](https://github.com/golangci/golangci-lint) from its authors.
|
||||||
The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters.
|
The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and reports issues from linters.
|
||||||
|
|
||||||

|

|
||||||
@ -47,6 +47,15 @@ jobs:
|
|||||||
|
|
||||||
# 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 action will use pre-installed Go.
|
||||||
|
# skip-go-installation: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don'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.
|
||||||
|
# skip-build-cache: true
|
||||||
```
|
```
|
||||||
|
|
||||||
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)
|
||||||
|
16
action.yml
16
action.yml
@ -1,10 +1,9 @@
|
|||||||
---
|
|
||||||
name: "Run golangci-lint"
|
name: "Run golangci-lint"
|
||||||
description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
|
description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
|
||||||
author: "golangci"
|
author: "golangci"
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
|
description: "version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version"
|
||||||
required: false
|
required: false
|
||||||
args:
|
args:
|
||||||
description: "golangci-lint command line arguments"
|
description: "golangci-lint command line arguments"
|
||||||
@ -21,7 +20,18 @@ inputs:
|
|||||||
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: true
|
required: true
|
||||||
|
skip-go-installation:
|
||||||
|
description: "if set to true then action uses pre-installed Go"
|
||||||
|
default: false
|
||||||
|
required: true
|
||||||
|
skip-pkg-cache:
|
||||||
|
description: "if set to true then the action don't cache or restore ~/go/pkg."
|
||||||
|
default: false
|
||||||
|
required: true
|
||||||
|
skip-build-cache:
|
||||||
|
description: "if set to true then the action don't cache or restore ~/.cache/go-build."
|
||||||
|
default: false
|
||||||
|
required: true
|
||||||
runs:
|
runs:
|
||||||
using: "node12"
|
using: "node12"
|
||||||
main: "dist/run/index.js"
|
main: "dist/run/index.js"
|
||||||
|
20214
dist/post_run/index.js
vendored
20214
dist/post_run/index.js
vendored
File diff suppressed because it is too large
Load Diff
20216
dist/run/index.js
vendored
20216
dist/run/index.js
vendored
File diff suppressed because it is too large
Load Diff
3232
package-lock.json
generated
3232
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -16,7 +16,8 @@
|
|||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"all": "npm run prepare-deps && npm run build && npm run format-check && npm run lint",
|
"all": "npm run prepare-deps && npm run build && npm run format-check && npm run lint",
|
||||||
"local": "npm run build && act -j test -b"
|
"local": "npm run build && act -j test -b",
|
||||||
|
"local-full-version": "npm run build && act -j test-full-version -b"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,28 +26,28 @@
|
|||||||
"author": "golangci",
|
"author": "golangci",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^1.0.2",
|
"@actions/cache": "^1.0.6",
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^4.0.0",
|
||||||
"@actions/tool-cache": "^1.6.0",
|
"@actions/tool-cache": "^1.6.1",
|
||||||
"@types/semver": "^7.3.4",
|
"@types/semver": "^7.3.4",
|
||||||
"@types/tmp": "^0.2.0",
|
"@types/tmp": "^0.2.0",
|
||||||
"setup-go": "git+https://github.com/actions/setup-go.git#v2.1.3",
|
"setup-go": "git+https://github.com/actions/setup-go.git#v2.1.3",
|
||||||
"tmp": "^0.2.1"
|
"tmp": "^0.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^14.11.2",
|
"@types/node": "^14.14.25",
|
||||||
"@types/uuid": "^8.3.0",
|
"@types/uuid": "^8.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
||||||
"@typescript-eslint/parser": "^2.34.0",
|
"@typescript-eslint/parser": "^2.34.0",
|
||||||
"@zeit/ncc": "^0.22.3",
|
"@zeit/ncc": "^0.22.3",
|
||||||
"eslint": "^6.6.0",
|
"eslint": "^6.6.0",
|
||||||
"eslint-config-prettier": "^6.12.0",
|
"eslint-config-prettier": "^6.15.0",
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.22.1",
|
||||||
"eslint-plugin-prettier": "^3.1.4",
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
"eslint-plugin-simple-import-sort": "^5.0.2",
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
||||||
"prettier": "^2.1.2",
|
"prettier": "^2.2.1",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
src/cache.ts
17
src/cache.ts
@ -25,7 +25,22 @@ const getLintCacheDir = (): string => {
|
|||||||
|
|
||||||
const getCacheDirs = (): string[] => {
|
const getCacheDirs = (): string[] => {
|
||||||
// Not existing dirs are ok here: it works.
|
// Not existing dirs are ok here: it works.
|
||||||
return [getLintCacheDir(), path.resolve(`${process.env.HOME}/.cache/go-build`), path.resolve(`${process.env.HOME}/go/pkg`)]
|
const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim()
|
||||||
|
const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim()
|
||||||
|
const dirs = [getLintCacheDir()]
|
||||||
|
|
||||||
|
if (skipBuildCache.toLowerCase() == "true") {
|
||||||
|
core.info(`Omitting ~/.cache/go-build from cache directories`)
|
||||||
|
} else {
|
||||||
|
dirs.push(path.resolve(`${process.env.HOME}/.cache/go-build`))
|
||||||
|
}
|
||||||
|
if (skipPkgCache.toLowerCase() == "true") {
|
||||||
|
core.info(`Omitting ~/go/pkg from cache directories`)
|
||||||
|
} else {
|
||||||
|
dirs.push(path.resolve(`${process.env.HOME}/go/pkg`))
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
||||||
|
@ -56,6 +56,12 @@ export async function installLint(versionConfig: VersionConfig): Promise<string>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function installGo(): Promise<void> {
|
export async function installGo(): Promise<void> {
|
||||||
|
const skipGoInstallation = core.getInput(`skip-go-installation`, { required: true }).trim()
|
||||||
|
if (skipGoInstallation.toLowerCase() == "true") {
|
||||||
|
core.info(`Skipping the installation of Go`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
process.env[`INPUT_GO-VERSION`] = `1`
|
process.env[`INPUT_GO-VERSION`] = `1`
|
||||||
await setupGo()
|
await setupGo()
|
||||||
|
@ -187,6 +187,7 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
|
|||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
|
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
|
||||||
|
core.addPath(path.dirname(lintPath))
|
||||||
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath))
|
await core.group(`run golangci-lint`, () => runLint(lintPath, patchPath))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Failed to run: ${error}, ${error.stack}`)
|
core.error(`Failed to run: ${error}, ${error.stack}`)
|
||||||
|
@ -61,11 +61,6 @@ const getRequestedLintVersion = (): Version => {
|
|||||||
if (parsedRequestedLintVersion == null) {
|
if (parsedRequestedLintVersion == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (parsedRequestedLintVersion.patch !== null) {
|
|
||||||
throw new Error(
|
|
||||||
`requested golangci-lint version '${requestedLintVersion}' was specified with the patch version, need specify only minor version`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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(
|
||||||
@ -109,6 +104,17 @@ const getConfig = async (): Promise<Config> => {
|
|||||||
|
|
||||||
export async function findLintVersion(): Promise<VersionConfig> {
|
export async function findLintVersion(): Promise<VersionConfig> {
|
||||||
core.info(`Finding needed golangci-lint version...`)
|
core.info(`Finding needed golangci-lint version...`)
|
||||||
|
const reqLintVersion = getRequestedLintVersion()
|
||||||
|
// if the patched version is passed, just use it
|
||||||
|
if (reqLintVersion?.major !== null && reqLintVersion?.minor != null && reqLintVersion?.patch !== null) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const versionWithoutV = `${reqLintVersion.major}.${reqLintVersion.minor}.${reqLintVersion.patch}`
|
||||||
|
resolve({
|
||||||
|
TargetVersion: `v${versionWithoutV}`,
|
||||||
|
AssetURL: `https://github.com/golangci/golangci-lint/releases/download/v${versionWithoutV}/golangci-lint-${versionWithoutV}-linux-amd64.tar.gz`,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
|
|
||||||
const config = await getConfig()
|
const config = await getConfig()
|
||||||
@ -117,7 +123,6 @@ export async function findLintVersion(): Promise<VersionConfig> {
|
|||||||
throw new Error(`invalid config: no MinorVersionToConfig field`)
|
throw new Error(`invalid config: no MinorVersionToConfig field`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const reqLintVersion = getRequestedLintVersion()
|
|
||||||
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
|
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
|
||||||
if (!versionConfig) {
|
if (!versionConfig) {
|
||||||
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
|
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
|
||||||
|
Reference in New Issue
Block a user