From 87b19204c0e895876ea2d7975da93b054e977d82 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 08:42:50 +0000 Subject: [PATCH 01/12] Migrate from docker to composite run actions https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action It should be able to reuse the go build cache and share the same build context/environment by using the same default workspace instead of using Docker. It should resolve an issue such as #21 as well. --- .github/workflows/dockerimage.yml | 14 -------------- Dockerfile | 11 ----------- action.yml | 18 ++++++++++++++++-- entrypoint.sh | 11 +++++++++++ 4 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/dockerimage.yml delete mode 100644 Dockerfile diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml deleted file mode 100644 index a924ec71..00000000 --- a/.github/workflows/dockerimage.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Docker Image CI - -on: [push] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag reviewdog-golangci-lint:$(date +%s) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 9a36602b..00000000 --- a/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM golangci/golangci-lint:v1.30-alpine - -ENV REVIEWDOG_VERSION=v0.10.2 - -RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${REVIEWDOG_VERSION} - -RUN apk --no-cache add git - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index 7b4dd091..183b79a1 100644 --- a/action.yml +++ b/action.yml @@ -35,8 +35,22 @@ inputs: description: 'Working directory relative to the root directory.' default: '.' runs: - using: 'docker' - image: 'Dockerfile' + using: 'composite' + steps: + - run: $GITHUB_ACTION_PATH/entrypoint.sh + shell: bash + env: + REVIEWDOG_VERSION: v0.10.2 + GOLANGCI_LINT_VERSION: v1.30.0 + INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} + INPUT_GOLANGCI_LINT_FLAGS: ${{ inputs.golangci_lint_flags }} + INPUT_TOOL_NAME: ${{ inputs.tool_name }} + INPUT_LEVEL: ${{ inputs.level }} + INPUT_REPORTER: ${{ inputs.reporter }} + INPUT_FILTER_MODE: ${{ inputs.filter_mode }} + INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} + INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} + INPUT_WORKDIR: ${{ inputs.workdir }} branding: icon: 'check-circle' color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh index 4ab27324..e496e98c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,17 @@ cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1 +TEMP_PATH="$(mktemp -d)" +PATH="${TEMP_PATH}:$PATH" + +echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/reviewdog' +curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 +echo '::endgroup::' + +echo '::group::🐶 Installing golangci-lint ... https://github.com/golangci/golangci-lint' +curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${GOLANGCI_LINT_VERSION}" 2>&1 +echo '::endgroup::' + export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" # shellcheck disable=SC2086 From 6e2fb34488eaea6a97bdabb0bcf32a6de076f2c0 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 08:54:51 +0000 Subject: [PATCH 02/12] tweak action log --- entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e496e98c..c0b6c3c6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,12 +9,13 @@ echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/review curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 echo '::endgroup::' -echo '::group::🐶 Installing golangci-lint ... https://github.com/golangci/golangci-lint' +echo '::group:: Installing golangci-lint ... https://github.com/golangci/golangci-lint' curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${GOLANGCI_LINT_VERSION}" 2>&1 echo '::endgroup::' export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +echo '::group:: Running golangci-lint with reviewdog 🐶 ...' # shellcheck disable=SC2086 golangci-lint run --out-format line-number ${INPUT_GOLANGCI_LINT_FLAGS} \ | reviewdog -f=golangci-lint \ @@ -24,3 +25,4 @@ golangci-lint run --out-format line-number ${INPUT_GOLANGCI_LINT_FLAGS} \ -fail-on-error="${INPUT_FAIL_ON_ERROR:-false}" \ -level="${INPUT_LEVEL}" \ ${INPUT_REVIEWDOG_FLAGS} +echo '::endgroup::' From a2698fc86ddc61aebb2374ef0cda81dc6b787be5 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 08:56:29 +0000 Subject: [PATCH 03/12] remove docker tests --- .github/workflows/reviewdog.yml | 36 ++++++++++----------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 5667dd2b..19db1db9 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -5,31 +5,17 @@ jobs: # different linters and just report one of the errors? golangci-lint: - name: runner / golangci-lint (pre-build docker image) + name: runner / golangci-lint runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: golangci-lint - # uses: ./ # Build with Dockerfile - uses: docker://reviewdog/action-golangci-lint:v1 # Pre-built image + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.github/.golangci.yml ./testdata" - golangci-lint-dockerfile: - name: runner / golangci-lint (Dockerfile) - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - name: golangci-lint w/ Dockerfile - uses: ./ # Build with Dockerfile - # uses: docker://reviewdog/action-golangci-lint:v1 # Pre-built image - with: - golangci_lint_flags: "./testdata" - tool_name: "golangci-lint-dockerfile" - golangci-lint-github-pr-review: name: runner / golangci-lint (github-pr-review) runs-on: ubuntu-latest @@ -37,7 +23,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: golangci-lint w/ github-pr-review - uses: ./ # Build with Dockerfile + uses: ./ with: golangci_lint_flags: "./testdata" tool_name: "golangci-lint-github-pr-review" @@ -50,7 +36,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: golangci-lint w/ github-check - uses: ./ # Build with Dockerfile + uses: ./ with: golangci_lint_flags: "./testdata" tool_name: "golangci-lint-github-check" @@ -63,7 +49,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: golangci-lint (workdir) - uses: ./ # Build with Dockerfile + uses: ./ with: workdir: "./testdata" golangci_lint_flags: "" @@ -79,7 +65,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: golangci-lint (All-In-One config) - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--enable-all --exclude-use-default=false ./testdata" @@ -91,7 +77,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: govet - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--disable-all -E govet ./testdata" @@ -104,7 +90,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: staticcheck - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--disable-all -E staticcheck ./testdata" @@ -117,7 +103,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: golint - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--disable-all -E golint ./testdata" @@ -131,7 +117,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: errcheck - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--disable-all -E errcheck ./testdata" @@ -145,7 +131,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - name: misspell - uses: docker://reviewdog/action-golangci-lint:v1 + uses: ./ with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--disable-all -E misspell ./testdata" From ae8a740eb0b6d6d8071340e78e9eb607e908f132 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 08:57:21 +0000 Subject: [PATCH 04/12] debug: update test code data for debug --- testdata/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/testdata/main.go b/testdata/main.go index cbd7b822..6a45ed1b 100644 --- a/testdata/main.go +++ b/testdata/main.go @@ -1,21 +1,21 @@ package testdata import ( - "os" "fmt" + "os" ) -func Main( ) { - // langauge +func Main() { + // langauge - x := 2 + x := 2 x += 1 fmt.Sprintf("%d") - os.Open("main.go") + os.Open("main1.go") } -func unused(unusedParam int) error { +func unused1(unusedParam int) error { return nil From 8754127bae38baf8e965fb2649e7babdccedbdfb Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:03:58 +0000 Subject: [PATCH 05/12] use warning level not to mark the build as failure --- .github/workflows/reviewdog.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 19db1db9..03d05dd7 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -14,6 +14,7 @@ jobs: uses: ./ with: github_token: ${{ secrets.github_token }} + level: warning golangci_lint_flags: "--config=.github/.golangci.yml ./testdata" golangci-lint-github-pr-review: From 6b20b92da480f98e7cd95a18df4c244385b27585 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:18:48 +0000 Subject: [PATCH 06/12] Update depup workflow --- .github/workflows/depup.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index 79336db6..d281d953 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -13,7 +13,7 @@ jobs: - uses: haya14busa/action-depup@v1 id: depup with: - file: Dockerfile + file: action.yml version_name: REVIEWDOG_VERSION repo: reviewdog/reviewdog @@ -31,3 +31,29 @@ jobs: branch: depup/reviewdog base: master labels: "bump:minor" + + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-depup@v1 + id: depup + with: + file: action.yml + version_name: REVIEWDOG_VERSION + repo: golangci/golangci-lint + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: "chore(deps): update golangci-lint to ${{ steps.depup.outputs.latest }}" + commit-message: "chore(deps): update golangci-lint to ${{ steps.depup.outputs.latest }}" + body: | + Update golangci-lint to [v${{ steps.depup.outputs.latest }}](https://github.com/golangci-lint/golangci/releases/tag/v${{ steps.depup.outputs.latest }}) + Compare [v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}](https://github.com/golangci/golangci-lint/compare/v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}) + + This PR is auto generated by [depup workflow](https://github.com/${{ github.repository }}/actions?query=workflow%3Adepup). + branch: depup/golangci-lint + base: master + labels: "bump:minor" From ad4b1150e41e174aa66d5d2948f4f729c4ae385f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:19:12 +0000 Subject: [PATCH 07/12] rename entrypoint.sh to script.sh --- action.yml | 2 +- entrypoint.sh => script.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename entrypoint.sh => script.sh (100%) diff --git a/action.yml b/action.yml index 183b79a1..e6af2881 100644 --- a/action.yml +++ b/action.yml @@ -37,7 +37,7 @@ inputs: runs: using: 'composite' steps: - - run: $GITHUB_ACTION_PATH/entrypoint.sh + - run: $GITHUB_ACTION_PATH/script.sh shell: bash env: REVIEWDOG_VERSION: v0.10.2 diff --git a/entrypoint.sh b/script.sh similarity index 100% rename from entrypoint.sh rename to script.sh From 8cbfd903f9b80ebf23b69704ac17fa284b417297 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:22:41 +0000 Subject: [PATCH 08/12] Test multiple platform support --- .github/workflows/reviewdog.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 03d05dd7..d7daabc6 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -17,6 +17,22 @@ jobs: level: warning golangci_lint_flags: "--config=.github/.golangci.yml ./testdata" + golangci-lint-platform: + name: runner / golangci-lint-platform + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - name: golangci-lint (platform) + uses: ./ + with: + github_token: ${{ secrets.github_token }} + tool_name: golangci-lint-${{ matrix.platform }} + level: warning + golangci_lint_flags: "--config=.github/.golangci.yml ./testdata" + golangci-lint-github-pr-review: name: runner / golangci-lint (github-pr-review) runs-on: ubuntu-latest From a346a388a91141adaf025323fbb1347bc67e8094 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:31:54 +0000 Subject: [PATCH 09/12] Remove docker related documents --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index f2834215..6da47785 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # GitHub Action: Run golangci-lint with reviewdog -[![Docker Image CI](https://github.com/reviewdog/action-golangci-lint/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/reviewdog/action-golangci-lint/actions) -[![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/reviewdog/action-golangci-lint)](https://hub.docker.com/r/reviewdog/action-golangci-lint) -[![Docker Pulls](https://img.shields.io/docker/pulls/reviewdog/action-golangci-lint)](https://hub.docker.com/r/reviewdog/action-golangci-lint) [![depup](https://github.com/reviewdog/action-golangci-lint/workflows/depup/badge.svg)](https://github.com/reviewdog/action-golangci-lint/actions?query=workflow%3Adepup) [![release](https://github.com/reviewdog/action-golangci-lint/workflows/release/badge.svg)](https://github.com/reviewdog/action-golangci-lint/actions?query=workflow%3Arelease) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-golangci-lint?logo=github&sort=semver)](https://github.com/reviewdog/action-golangci-lint/releases) @@ -20,7 +17,7 @@ code review experience. ### `github_token` -**Required**. Default is `${{ github.token }}`. If using a pre-built docker image, you must set it explicitly to `github_token: ${{ secrets.github_token }}`. +**Required**. Default is `${{ github.token }}`. ### `golangci_lint_flags` From 8bdc1f125d317e0ce868e72316b37f9f5bb89301 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:35:33 +0000 Subject: [PATCH 10/12] add comments --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index e6af2881..468e7933 100644 --- a/action.yml +++ b/action.yml @@ -40,8 +40,12 @@ runs: - run: $GITHUB_ACTION_PATH/script.sh shell: bash env: + # We may want to allow specifing reviewdog and golangci-lint version as + # action's input, but let's start with hard coded latest stable version. REVIEWDOG_VERSION: v0.10.2 GOLANGCI_LINT_VERSION: v1.30.0 + # INPUT_ is not available in Composite run steps + # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} INPUT_GOLANGCI_LINT_FLAGS: ${{ inputs.golangci_lint_flags }} INPUT_TOOL_NAME: ${{ inputs.tool_name }} From 8769f60bab17228e9705adb06b03347e6c332763 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 15 Aug 2020 09:39:04 +0000 Subject: [PATCH 11/12] fix golangci-lint with all in one test configuration --- .github/workflows/reviewdog.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index d7daabc6..b024e645 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -85,6 +85,8 @@ jobs: uses: ./ with: github_token: ${{ secrets.github_token }} + tool_name: "golangci-lint-all-in-one" + level: warning golangci_lint_flags: "--enable-all --exclude-use-default=false ./testdata" govet: From 3b90a2c935763b025af86d1bfcf549841d489690 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 16 Aug 2020 07:20:23 +0000 Subject: [PATCH 12/12] Use /bin/bash --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index c0b6c3c6..02f6cc3b 100755 --- a/script.sh +++ b/script.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1