From 60b57697f8101ca17c70891fc7f75934efc699fa Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 03:45:08 +0300 Subject: [PATCH 01/12] mention reviewdog --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dbf8e478d6..1694dff42a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # golangci-lint-action Work in progress + +Based on [reviewdog action](https://github.com/reviewdog/action-golangci-lint). From 6eb54d49f7828ee633453c0a441f202ff76fc0e8 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 03:51:07 +0300 Subject: [PATCH 02/12] add sample --- .github/workflows/golangci.yml | 14 ++++++++++++++ action.yml | 3 +++ sample/sample.go | 14 ++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 .github/workflows/golangci.yml create mode 100644 sample/sample.go diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml new file mode 100644 index 0000000000..1fe6094e65 --- /dev/null +++ b/.github/workflows/golangci.yml @@ -0,0 +1,14 @@ +name: golangci-lint +on: [pull_request] +jobs: + golangci-lint-dockerfile: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + - name: golangci-lint + uses: ./ + with: + github_token: ${{ secrets.github_token }} + flags: "./testdata" diff --git a/action.yml b/action.yml index 4762db3ea4..7baf9ca0cd 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,9 @@ inputs: github_token: description: 'GITHUB_TOKEN' required: true + flags: + description: 'GolangCI command line flags' + required: false runs: using: 'docker' image: 'Dockerfile' diff --git a/sample/sample.go b/sample/sample.go new file mode 100644 index 0000000000..50071d0d16 --- /dev/null +++ b/sample/sample.go @@ -0,0 +1,14 @@ +// Package sample is used as test input for golangci action. +package sample + +import ( + "crypto/md5" + "encoding/hex" +) + +// Hash~ +func Hash(data string) string { + h := md5.New() + h.Write([]byte(data)) + return hex.EncodeToString(h.Sum(nil)) +} From 4787970861b8ab394e62e59d220ce79d0b7c6ea5 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 03:54:00 +0300 Subject: [PATCH 03/12] add entrypoint --- Dockerfile | 4 ++++ entrypoint.sh | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e8f390242c..1a321d0b94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,5 @@ FROM golangci/golangci-lint:v1.25 + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index b63311a046..d9bfab1940 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,4 @@ #!/bin/bash -golangci-lint run --out-format github-actions +# shellcheck disable=SC2086 +golangci-lint run --out-format github-actions ${FLAGS} From bdb0c2099d449c5dd8ff0a6f3b66fcb623a9cc4c Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 03:55:56 +0300 Subject: [PATCH 04/12] short naming --- .github/workflows/golangci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 1fe6094e65..0913e5ca98 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -1,8 +1,8 @@ -name: golangci-lint +name: golangci on: [pull_request] jobs: golangci-lint-dockerfile: - name: golangci-lint + name: lint runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory From 2a6877729d971074aa9fd5bf492365a5d6cd38b1 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 03:58:43 +0300 Subject: [PATCH 05/12] echo start --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index d9bfab1940..ebd75bbb17 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,6 @@ #!/bin/bash +echo 'golangci-lint-action: start' + # shellcheck disable=SC2086 golangci-lint run --out-format github-actions ${FLAGS} From 4cfaabcf3443776ee74e82d74f71903b3bf74ad1 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:01:57 +0300 Subject: [PATCH 06/12] chmod --- entrypoint.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 From c29c0c454f3e13dd8ee2d303ee78f302cf4e2776 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:22:56 +0300 Subject: [PATCH 07/12] add directory arg --- action.yml | 5 +++++ entrypoint.sh | 2 ++ 2 files changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 7baf9ca0cd..6d3d48d820 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,11 @@ inputs: flags: description: 'GolangCI command line flags' required: false + directory: + description: 'Working directory' + required: false + default: '' + runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index ebd75bbb17..405c3dd143 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,5 +2,7 @@ echo 'golangci-lint-action: start' +cd "${GITHUB_WORKSPACE}/${DIRECTORY}" || exit 1 + # shellcheck disable=SC2086 golangci-lint run --out-format github-actions ${FLAGS} From 48933044a03f1dcac56cd8006c6527ffaf34750a Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:23:27 +0300 Subject: [PATCH 08/12] use directory arg --- .github/workflows/golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 0913e5ca98..0234261048 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -11,4 +11,4 @@ jobs: uses: ./ with: github_token: ${{ secrets.github_token }} - flags: "./testdata" + directory: sample From 04ae9387126090f2436496d1e503e5003175c53e Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:27:08 +0300 Subject: [PATCH 09/12] rename docker image step --- .github/workflows/dockerimage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml index fef6ef1a52..5d0e147551 100644 --- a/.github/workflows/dockerimage.yml +++ b/.github/workflows/dockerimage.yml @@ -1,4 +1,4 @@ -name: Docker Image CI +name: docker image on: [push] From 542ddbcf10d70fe3233bdc460948dd680ec18445 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:31:18 +0300 Subject: [PATCH 10/12] use exit code 0 --- .github/workflows/golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 0234261048..961c6019c3 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -12,3 +12,4 @@ jobs: with: github_token: ${{ secrets.github_token }} directory: sample + flags: --issues-exit-code 0 From d3ea46b6e2c66d55192395d663e99e8fb4f8e4e6 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:39:27 +0300 Subject: [PATCH 11/12] add format --- .github/workflows/golangci.yml | 1 + action.yml | 5 +++++ entrypoint.sh | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 961c6019c3..6096b5e3ea 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -12,4 +12,5 @@ jobs: with: github_token: ${{ secrets.github_token }} directory: sample + format: colored-line-number flags: --issues-exit-code 0 diff --git a/action.yml b/action.yml index 6d3d48d820..b6ba408caf 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,11 @@ inputs: description: 'Working directory' required: false default: '' + format: + description: 'Output format of issues' + default: 'github-actions' + required: false + runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 405c3dd143..1ceda4b67c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,4 +5,4 @@ echo 'golangci-lint-action: start' cd "${GITHUB_WORKSPACE}/${DIRECTORY}" || exit 1 # shellcheck disable=SC2086 -golangci-lint run --out-format github-actions ${FLAGS} +golangci-lint run --out-format ${FORMAT} ${FLAGS} From 832a5f00c93ea05fee5b9d0e5ebaa9d0a8687799 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 26 Apr 2020 04:50:20 +0300 Subject: [PATCH 12/12] entrypoint: fix input args --- entrypoint.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1ceda4b67c..ad37aab99a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,10 @@ #!/bin/bash echo 'golangci-lint-action: start' +echo " flags: ${INPUT_FLAGS}" +echo " format: ${INPUT_FORMAT}" -cd "${GITHUB_WORKSPACE}/${DIRECTORY}" || exit 1 +cd "${GITHUB_WORKSPACE}/${INPUT_DIRECTORY}" || exit 1 # shellcheck disable=SC2086 -golangci-lint run --out-format ${FORMAT} ${FLAGS} +golangci-lint run --out-format ${INPUT_FORMAT} ${INPUT_FLAGS}