Compare commits
65 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 | |||
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 |
@ -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
|
25
.github/workflows/test.yml
vendored
25
.github/workflows/test.yml
vendored
@ -15,7 +15,13 @@ jobs:
|
|||||||
npm install
|
npm install
|
||||||
npm run all
|
npm run all
|
||||||
test: # make sure the action works on a clean machine without building
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./
|
- uses: ./
|
||||||
@ -23,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
|
||||||
|
63
README.md
63
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.
|
||||||
|
|
||||||

|

|
||||||
@ -25,6 +25,7 @@ on:
|
|||||||
- v*
|
- v*
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
golangci:
|
golangci:
|
||||||
@ -33,7 +34,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v1
|
uses: golangci/golangci-lint-action@v2
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# 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
|
version: v1.29
|
||||||
@ -46,11 +47,65 @@ 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)
|
||||||
because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
|
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
|
## 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).
|
Currently, GitHub parses the action's output and creates [annotations](https://github.community/t5/GitHub-Actions/What-are-annotations/td-p/30770).
|
||||||
@ -82,6 +137,8 @@ We use JavaScript-based action. We don't use Docker-based action because:
|
|||||||
1. docker pulling is slow currently
|
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)
|
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:
|
Inside our action we perform 3 steps:
|
||||||
|
|
||||||
1. Setup environment running in parallel:
|
1. Setup environment running in parallel:
|
||||||
@ -95,7 +152,7 @@ Inside our action we perform 3 steps:
|
|||||||
### Caching internals
|
### Caching internals
|
||||||
|
|
||||||
1. We save and restore the following directories: `~/.cache/golangci-lint`, `~/.cache/go-build`, `~/go/pkg`.
|
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.
|
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.
|
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.
|
||||||
|
|
||||||
|
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"
|
||||||
|
18972
dist/post_run/index.js
vendored
18972
dist/post_run/index.js
vendored
File diff suppressed because it is too large
Load Diff
18972
dist/run/index.js
vendored
18972
dist/run/index.js
vendored
File diff suppressed because it is too large
Load Diff
3326
package-lock.json
generated
3326
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
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.1",
|
"@actions/cache": "^1.0.6",
|
||||||
"@actions/core": "^1.2.0",
|
"@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.1",
|
"@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.1",
|
"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.0.27",
|
"@types/node": "^14.14.25",
|
||||||
"@types/uuid": "^8.0.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.5.0",
|
"eslint-config-prettier": "^6.15.0",
|
||||||
"eslint-plugin-import": "^2.22.0",
|
"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.0.5",
|
"prettier": "^2.2.1",
|
||||||
"typescript": "^3.9.7"
|
"typescript": "^4.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/cache.ts
22
src/cache.ts
@ -2,6 +2,7 @@ import * as cache from "@actions/cache"
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as crypto from "crypto"
|
import * as crypto from "crypto"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
import { Events, State } from "./constants"
|
import { Events, State } from "./constants"
|
||||||
import * as utils from "./utils/actionUtils"
|
import * as utils from "./utils/actionUtils"
|
||||||
@ -18,11 +19,28 @@ function checksumFile(hashName: string, path: string): Promise<string> {
|
|||||||
|
|
||||||
const pathExists = async (path: string): Promise<boolean> => !!(await fs.promises.stat(path).catch(() => false))
|
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[] => {
|
const getCacheDirs = (): string[] => {
|
||||||
// Not existing dirs are ok here: it works.
|
// Not existing dirs are ok here: it works.
|
||||||
return [getLintCacheDir(), `${process.env.HOME}/.cache/go-build`, `${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 => {
|
||||||
|
@ -1,27 +1,67 @@
|
|||||||
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 os from "os"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { run as setupGo } from "setup-go/lib/main"
|
import { run as setupGo } from "setup-go/lib/main"
|
||||||
|
|
||||||
import { VersionConfig } from "./version"
|
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.
|
// The installLint returns path to installed binary of golangci-lint.
|
||||||
export async function installLint(versionConfig: VersionConfig): Promise<string> {
|
export async function installLint(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 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 urlParts = assetURL.split(`/`)
|
||||||
const tarGzPath = await tc.downloadTool(versionConfig.AssetURL)
|
const dirName = urlParts[urlParts.length - 1].replace(repl, ``)
|
||||||
const extractedDir = await tc.extractTar(tarGzPath, process.env.HOME)
|
|
||||||
|
|
||||||
const urlParts = versionConfig.AssetURL.split(`/`)
|
|
||||||
const dirName = urlParts[urlParts.length - 1].replace(/\.tar\.gz$/, ``)
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
@ -38,7 +38,6 @@ async function fetchPatch(): Promise<string> {
|
|||||||
core.warning(`No pull request in context`)
|
core.warning(`No pull request in context`)
|
||||||
return ``
|
return ``
|
||||||
}
|
}
|
||||||
|
|
||||||
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
const octokit = github.getOctokit(core.getInput(`github-token`, { required: true }))
|
||||||
let patch: string
|
let patch: string
|
||||||
try {
|
try {
|
||||||
@ -188,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