Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
54a84d46fb | |||
ba0e91ca3a | |||
4957db1776 | |||
2ea701ccbd | |||
b6429a6771 | |||
7ba2fe0d4d | |||
b248ff60d3 | |||
0f7d62b0dc | |||
f16cd8cd00 | |||
f745d2bb6b | |||
9bf04a21dc | |||
273fa7ab10 | |||
18087a51d1 | |||
37037d32f2 | |||
9d250b4a7c | |||
e820a262b2 | |||
3b7ba9cb59 | |||
2efd4a3be8 | |||
0098fd17c9 | |||
863caeb194 | |||
1d3f25bff9 | |||
62252c6349 | |||
9535745fa5 | |||
dc87c27dac | |||
87260465c1 | |||
014f5e25d2 | |||
a520c23e6f | |||
6317259e28 | |||
809d3b078b | |||
b026646c83 | |||
c598686db1 | |||
25d72af787 | |||
79f232513c | |||
f7f5eff206 | |||
485c6a047e | |||
e2ff3f296a | |||
294f27a519 |
31
.github/workflows/test.yml
vendored
31
.github/workflows/test.yml
vendored
@ -4,23 +4,28 @@ on: # rebuild any PRs and main branch changes
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
- "releases/*"
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
npm run prepare-deps
|
||||
npm run all
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
version: v1.28
|
||||
args: --issues-exit-code=0 ./sample/...
|
||||
only-new-issues: true
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
version: latest
|
||||
args: --issues-exit-code=0 ./sample/...
|
||||
only-new-issues: true
|
||||
|
56
README.md
56
README.md
@ -9,7 +9,7 @@ The action runs [golangci-lint](https://github.com/golangci/golangci-lint) and r
|
||||
|
||||
## Compatibility
|
||||
|
||||
* `v2.0.0` works with `golangci-lint` version >= `v1.28.3`
|
||||
* `v2.0.0+` works with `golangci-lint` version >= `v1.28.3`
|
||||
* `v1.2.2` is deprecated due to we forgot to change the minimum version of `golangci-lint` to `v1.28.3` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
* `v1.2.1` works with `golangci-lint` version >= `v1.14.0` ([issue](https://github.com/golangci/golangci-lint-action/issues/39))
|
||||
|
||||
@ -25,6 +25,7 @@ on:
|
||||
- v*
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
jobs:
|
||||
golangci:
|
||||
@ -33,10 +34,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v1
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.28
|
||||
version: v1.29
|
||||
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
@ -51,6 +52,51 @@ jobs:
|
||||
We recommend running this action in a job separate from other jobs (`go test`, etc)
|
||||
because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
|
||||
|
||||
### Multiple OS Support
|
||||
|
||||
If you need to run linters for specific operating systems, you will need to use `v2` of the action. Here is a sample configuration file:
|
||||
|
||||
```yaml
|
||||
name: golangci-lint
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.15.x]
|
||||
os: [macos-latest, windows-latest]
|
||||
name: lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.29
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
```
|
||||
|
||||
You will also likely need to add the following `.gitattributes` file to ensure that line endings for windows builds are properly formatted:
|
||||
|
||||
```.gitattributes
|
||||
*.go text eol=lf
|
||||
```
|
||||
|
||||
## Comments and Annotations
|
||||
|
||||
Currently, GitHub parses the action's output and creates [annotations](https://github.community/t5/GitHub-Actions/What-are-annotations/td-p/30770).
|
||||
@ -82,6 +128,8 @@ We use JavaScript-based action. We don't use Docker-based action because:
|
||||
1. docker pulling is slow currently
|
||||
2. it's easier to use caching from [@actions/cache](https://github.com/actions/toolkit/tree/master/packages/cache)
|
||||
|
||||
We support different platforms, such as `ubuntu`, `macos` and `windows` with `x32` and `x64` archs.
|
||||
|
||||
Inside our action we perform 3 steps:
|
||||
|
||||
1. Setup environment running in parallel:
|
||||
@ -95,7 +143,7 @@ Inside our action we perform 3 steps:
|
||||
### Caching internals
|
||||
|
||||
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
|
||||
2. The primary caching key looks like `golangci-lint.cache-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
|
||||
2. The primary caching key looks like `golangci-lint.cache-{platform-arch}-{interval_number}-{go.mod_hash}`. Interval number ensures that we periodically invalidate
|
||||
our cache (every 7 days). `go.mod` hash ensures that we invalidate the cache early - as soon as dependencies have changed.
|
||||
3. We use [restore keys](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key): `golangci-lint.cache-{interval_number}-`, `golangci-lint.cache-`. GitHub matches keys by prefix if we have no exact match for the primary cache.
|
||||
|
||||
|
30
action.yml
30
action.yml
@ -1,31 +1,31 @@
|
||||
---
|
||||
name: 'Run golangci-lint'
|
||||
description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution.'
|
||||
author: 'golangci'
|
||||
name: "Run golangci-lint"
|
||||
description: "Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution."
|
||||
author: "golangci"
|
||||
inputs:
|
||||
version:
|
||||
description: 'version of golangci-lint to use in form of v1.2'
|
||||
required: true
|
||||
description: "version of golangci-lint to use in form of v1.2 or `latest` to use the latest version"
|
||||
required: false
|
||||
args:
|
||||
description: 'golangci-lint command line arguments'
|
||||
default: ''
|
||||
description: "golangci-lint command line arguments"
|
||||
default: ""
|
||||
required: false
|
||||
working-directory:
|
||||
description: 'golangci-lint working directory, default is project root'
|
||||
description: "golangci-lint working directory, default is project root"
|
||||
required: false
|
||||
github-token:
|
||||
description: 'the token is used for fetching patch of a pull request to show only new issues'
|
||||
description: "the token is used for fetching patch of a pull request to show only new issues"
|
||||
default: ${{ github.token }}
|
||||
required: true
|
||||
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
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/run/index.js'
|
||||
post: 'dist/post_run/index.js'
|
||||
using: "node12"
|
||||
main: "dist/run/index.js"
|
||||
post: "dist/post_run/index.js"
|
||||
branding:
|
||||
icon: 'shield'
|
||||
color: 'yellow'
|
||||
icon: "shield"
|
||||
color: "yellow"
|
||||
|
70984
dist/post_run/index.js
vendored
70984
dist/post_run/index.js
vendored
File diff suppressed because one or more lines are too long
70984
dist/run/index.js
vendored
70984
dist/run/index.js
vendored
File diff suppressed because one or more lines are too long
814
package-lock.json
generated
814
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@ -15,7 +15,7 @@
|
||||
"lint-fix": "eslint **/*.ts --cache --fix",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"all": "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"
|
||||
},
|
||||
"repository": {
|
||||
@ -25,28 +25,28 @@
|
||||
"author": "golangci",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^0.2.1",
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/cache": "^1.0.2",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.1",
|
||||
"@actions/github": "^2.1.1",
|
||||
"@actions/tool-cache": "^1.5.5",
|
||||
"@types/semver": "^7.3.1",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@actions/tool-cache": "^1.6.0",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@types/tmp": "^0.2.0",
|
||||
"setup-go": "git+https://github.com/actions/setup-go.git#v2.1.0",
|
||||
"setup-go": "git+https://github.com/actions/setup-go.git#v2.1.3",
|
||||
"tmp": "^0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.0.23",
|
||||
"@types/uuid": "^8.0.0",
|
||||
"@types/node": "^14.11.2",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
||||
"@typescript-eslint/parser": "^2.34.0",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^6.6.0",
|
||||
"eslint-config-prettier": "^6.5.0",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"eslint-config-prettier": "^6.12.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"eslint-plugin-simple-import-sort": "^5.0.2",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^3.9.6"
|
||||
"prettier": "^2.1.2",
|
||||
"typescript": "^4.0.3"
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import * as cache from "@actions/cache"
|
||||
import * as core from "@actions/core"
|
||||
import * as crypto from "crypto"
|
||||
import * as fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
import { Events, State } from "./constants"
|
||||
import * as utils from "./utils/actionUtils"
|
||||
@ -18,11 +19,13 @@ function checksumFile(hashName: string, path: string): Promise<string> {
|
||||
|
||||
const pathExists = async (path: string): Promise<boolean> => !!(await fs.promises.stat(path).catch(() => false))
|
||||
|
||||
const getLintCacheDir = (): string => `${process.env.HOME}/.cache/golangci-lint`
|
||||
const getLintCacheDir = (): string => {
|
||||
return path.resolve(`${process.env.HOME}/.cache/golangci-lint`)
|
||||
}
|
||||
|
||||
const getCacheDirs = (): string[] => {
|
||||
// Not existing dirs are ok here: it works.
|
||||
return [getLintCacheDir(), `${process.env.HOME}/.cache/go-build`, `${process.env.HOME}/go/pkg`]
|
||||
return [getLintCacheDir(), path.resolve(`${process.env.HOME}/.cache/go-build`), path.resolve(`${process.env.HOME}/go/pkg`)]
|
||||
}
|
||||
|
||||
const getIntervalKey = (invalidationIntervalDays: number): string => {
|
||||
|
@ -1,21 +1,55 @@
|
||||
import * as core from "@actions/core"
|
||||
import * as tc from "@actions/tool-cache"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { run as setupGo } from "setup-go/lib/main"
|
||||
|
||||
import { VersionConfig } from "./version"
|
||||
|
||||
const downloadURL = "https://github.com/golangci/golangci-lint/releases/download"
|
||||
|
||||
const getAssetURL = (versionConfig: VersionConfig): string => {
|
||||
let ext = "tar.gz"
|
||||
let platform = os.platform().toString()
|
||||
switch (platform) {
|
||||
case "win32":
|
||||
platform = "windows"
|
||||
ext = "zip"
|
||||
break
|
||||
}
|
||||
let arch = os.arch()
|
||||
switch (arch) {
|
||||
case "x64":
|
||||
arch = "amd64"
|
||||
break
|
||||
case "x32":
|
||||
case "ia32":
|
||||
arch = "386"
|
||||
break
|
||||
}
|
||||
const noPrefix = versionConfig.TargetVersion.slice(1)
|
||||
|
||||
return `${downloadURL}/${versionConfig.TargetVersion}/golangci-lint-${noPrefix}-${platform}-${arch}.${ext}`
|
||||
}
|
||||
|
||||
// The installLint returns path to installed binary of golangci-lint.
|
||||
export async function installLint(versionConfig: VersionConfig): Promise<string> {
|
||||
core.info(`Installing golangci-lint ${versionConfig.TargetVersion}...`)
|
||||
const startedAt = Date.now()
|
||||
const assetURL = getAssetURL(versionConfig)
|
||||
core.info(`Downloading ${assetURL} ...`)
|
||||
const archivePath = await tc.downloadTool(assetURL)
|
||||
let extractedDir = ""
|
||||
let repl = /\.tar\.gz$/
|
||||
if (assetURL.endsWith("zip")) {
|
||||
extractedDir = await tc.extractZip(archivePath, process.env.HOME)
|
||||
repl = /\.zip$/
|
||||
} else {
|
||||
extractedDir = await tc.extractTar(archivePath, process.env.HOME)
|
||||
}
|
||||
|
||||
core.info(`Downloading ${versionConfig.AssetURL} ...`)
|
||||
const tarGzPath = await tc.downloadTool(versionConfig.AssetURL)
|
||||
const extractedDir = await tc.extractTar(tarGzPath, process.env.HOME)
|
||||
|
||||
const urlParts = versionConfig.AssetURL.split(`/`)
|
||||
const dirName = urlParts[urlParts.length - 1].replace(/\.tar\.gz$/, ``)
|
||||
const urlParts = assetURL.split(`/`)
|
||||
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
|
||||
const lintPath = path.join(extractedDir, dirName, `golangci-lint`)
|
||||
core.info(`Installed golangci-lint into ${lintPath} in ${Date.now() - startedAt}ms`)
|
||||
return lintPath
|
||||
|
@ -38,8 +38,7 @@ async function fetchPatch(): Promise<string> {
|
||||
core.warning(`No pull request in context`)
|
||||
return ``
|
||||
}
|
||||
|
||||
const octokit = new github.GitHub(core.getInput(`github-token`, { required: true }))
|
||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||
let patch: string
|
||||
try {
|
||||
const patchResp = await octokit.pulls.get({
|
||||
|
@ -6,11 +6,14 @@ export type Version = {
|
||||
major: number
|
||||
minor: number
|
||||
patch: number | null
|
||||
}
|
||||
} | null
|
||||
|
||||
const versionRe = /^v(\d+)\.(\d+)(?:\.(\d+))?$/
|
||||
|
||||
const parseVersion = (s: string): Version => {
|
||||
if (s == "latest" || s == "") {
|
||||
return null
|
||||
}
|
||||
const match = s.match(versionRe)
|
||||
if (!match) {
|
||||
throw new Error(`invalid version string '${s}', expected format v1.2 or v1.2.3`)
|
||||
@ -23,7 +26,12 @@ const parseVersion = (s: string): Version => {
|
||||
}
|
||||
}
|
||||
|
||||
export const stringifyVersion = (v: Version): string => `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
|
||||
export const stringifyVersion = (v: Version): string => {
|
||||
if (v == null) {
|
||||
return "latest"
|
||||
}
|
||||
return `v${v.major}.${v.minor}${v.patch !== null ? `.${v.patch}` : ``}`
|
||||
}
|
||||
|
||||
const minVersion = {
|
||||
major: 1,
|
||||
@ -32,6 +40,12 @@ const minVersion = {
|
||||
}
|
||||
|
||||
const isLessVersion = (a: Version, b: Version): boolean => {
|
||||
if (a == null) {
|
||||
return true
|
||||
}
|
||||
if (b == null) {
|
||||
return false
|
||||
}
|
||||
if (a.major != b.major) {
|
||||
return a.major < b.major
|
||||
}
|
||||
@ -42,8 +56,11 @@ const isLessVersion = (a: Version, b: Version): boolean => {
|
||||
}
|
||||
|
||||
const getRequestedLintVersion = (): Version => {
|
||||
const requestedLintVersion = core.getInput(`version`, { required: true })
|
||||
const requestedLintVersion = core.getInput(`version`)
|
||||
const parsedRequestedLintVersion = parseVersion(requestedLintVersion)
|
||||
if (parsedRequestedLintVersion == 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`
|
||||
@ -93,15 +110,14 @@ const getConfig = async (): Promise<Config> => {
|
||||
export async function findLintVersion(): Promise<VersionConfig> {
|
||||
core.info(`Finding needed golangci-lint version...`)
|
||||
const startedAt = Date.now()
|
||||
const reqLintVersion = getRequestedLintVersion()
|
||||
|
||||
const config = await getConfig()
|
||||
|
||||
if (!config.MinorVersionToConfig) {
|
||||
core.warning(JSON.stringify(config))
|
||||
throw new Error(`invalid config: no MinorVersionToConfig field`)
|
||||
}
|
||||
|
||||
const reqLintVersion = getRequestedLintVersion()
|
||||
const versionConfig = config.MinorVersionToConfig[stringifyVersion(reqLintVersion)]
|
||||
if (!versionConfig) {
|
||||
throw new Error(`requested golangci-lint version '${stringifyVersion(reqLintVersion)}' doesn't exist`)
|
||||
|
Reference in New Issue
Block a user