From aefee050c917cbdba3568bbc2a6bf4dddc077da2 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 23 Jan 2022 20:50:26 +0100 Subject: [PATCH] Update dependencies and CI (#14) --- .github/workflows/bench.yml | 29 +++++++++++++++---------- .github/workflows/cloc.yml | 8 +++---- .github/workflows/golangci-lint.yml | 2 +- .github/workflows/gorelease.yml | 28 ++++++++++++++---------- .github/workflows/test-unit.yml | 33 ++++++++++++++++++++--------- .golangci.yml | 4 ++++ Makefile | 4 ++-- go.mod | 12 ++++++++--- go.sum | 8 +++---- 9 files changed, 82 insertions(+), 46 deletions(-) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index b6cb223..152d4a6 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -16,17 +16,25 @@ env: GO111MODULE: "on" CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results. RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing. + GO_VERSION: 1.17.x jobs: bench: - strategy: - matrix: - go-version: [ 1.17.x ] runs-on: ubuntu-latest steps: - - name: Install Go + - name: Install Go stable + if: env.GO_VERSION != 'tip' uses: actions/setup-go@v2 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ env.GO_VERSION }} + - name: Install Go tip + if: env.GO_VERSION == 'tip' + run: | + curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz + ls -lah gotip.tar.gz + mkdir -p ~/sdk/gotip + tar -C ~/sdk/gotip -xzf gotip.tar.gz + ~/sdk/gotip/bin/go version + echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - name: Checkout code uses: actions/checkout@v2 with: @@ -76,16 +84,15 @@ jobs: export REF_NAME=new BENCH_COUNT=5 make bench OUTPUT=$(make bench-stat-diff) - OUTPUT="${OUTPUT//'%'/'%25'}" - OUTPUT="${OUTPUT//$'\n'/'%0A'}" - OUTPUT="${OUTPUT//$'\r'/'%0D'}" + echo "${OUTPUT}" + OUTPUT="${OUTPUT//$'\n'/%0A}" echo "::set-output name=diff::$OUTPUT" OUTPUT=$(make bench-stat) - OUTPUT="${OUTPUT//'%'/'%25'}" - OUTPUT="${OUTPUT//$'\n'/'%0A'}" - OUTPUT="${OUTPUT//$'\r'/'%0D'}" + echo "${OUTPUT}" + OUTPUT="${OUTPUT//$'\n'/%0A}" echo "::set-output name=result::$OUTPUT" - name: Comment Benchmark Result + continue-on-error: true uses: marocchino/sticky-pull-request-comment@v2 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml index ed1ddb9..7002b22 100644 --- a/.github/workflows/cloc.yml +++ b/.github/workflows/cloc.yml @@ -18,14 +18,14 @@ jobs: - name: Count Lines Of Code id: loc run: | - curl -OL https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz + curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz OUTPUT=$(cd pr && ../sccdiff -basedir ../base) - OUTPUT="${OUTPUT//'%'/'%25'}" - OUTPUT="${OUTPUT//$'\n'/'%0A'}" - OUTPUT="${OUTPUT//$'\r'/'%0D'}" + echo "${OUTPUT}" + OUTPUT="${OUTPUT//$'\n'/%0A}" echo "::set-output name=diff::$OUTPUT" - name: Comment Code Lines + continue-on-error: true uses: marocchino/sticky-pull-request-comment@v2 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index cf9c148..58c0ec6 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -18,7 +18,7 @@ jobs: uses: golangci/golangci-lint-action@v2.5.2 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.41.1 + version: v1.43.0 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml index a733761..94c6966 100644 --- a/.github/workflows/gorelease.yml +++ b/.github/workflows/gorelease.yml @@ -3,18 +3,25 @@ name: gorelease on: pull_request: env: - GO111MODULE: "on" + GO_VERSION: 1.17.x jobs: gorelease: - strategy: - matrix: - go-version: [ 1.17.x ] runs-on: ubuntu-latest steps: - - name: Install Go + - name: Install Go stable + if: env.GO_VERSION != 'tip' uses: actions/setup-go@v2 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ env.GO_VERSION }} + - name: Install Go tip + if: env.GO_VERSION == 'tip' + run: | + curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz + ls -lah gotip.tar.gz + mkdir -p ~/sdk/gotip + tar -C ~/sdk/gotip -xzf gotip.tar.gz + ~/sdk/gotip/bin/go version + echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - name: Checkout code uses: actions/checkout@v2 - name: Gorelease cache @@ -28,17 +35,16 @@ jobs: run: | test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest OUTPUT=$(gorelease || exit 0) - OUTPUT="${OUTPUT//'%'/'%25'}" - OUTPUT="${OUTPUT//$'\n'/'%0A'}" - OUTPUT="${OUTPUT//$'\r'/'%0D'}" + echo "${OUTPUT}" + OUTPUT="${OUTPUT//$'\n'/%0A}" echo "::set-output name=report::$OUTPUT" - name: Comment Report + continue-on-error: true uses: marocchino/sticky-pull-request-comment@v2 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} header: gorelease message: | - ### API Changes + ### Go API Changes
             ${{ steps.gorelease.outputs.report }}
diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml
index 1be2e02..6442393 100644
--- a/.github/workflows/test-unit.yml
+++ b/.github/workflows/test-unit.yml
@@ -9,17 +9,28 @@ on:
 env:
   GO111MODULE: "on"
   RUN_BASE_COVERAGE: "on"  # Runs test for PR base in case base test coverage is missing.
+  COV_GO_VERSION: 1.17.x   # Version of Go to collect coverage
 jobs:
   test:
     strategy:
       matrix:
-        go-version: [ 1.16.x, 1.17.x ]
+        go-version: [ 1.16.x, 1.17.x, tip ]
     runs-on: ubuntu-latest
     steps:
-      - name: Install Go
+      - name: Install Go stable
+        if: matrix.go-version != 'tip'
         uses: actions/setup-go@v2
         with:
           go-version: ${{ matrix.go-version }}
+      - name: Install Go tip
+        if: matrix.go-version == 'tip'
+        run: |
+          curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
+          ls -lah gotip.tar.gz
+          mkdir -p ~/sdk/gotip
+          tar -C ~/sdk/gotip -xzf gotip.tar.gz
+          ~/sdk/gotip/bin/go version
+          echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
       - name: Checkout code
         uses: actions/checkout@v2
       - name: Go cache
@@ -35,7 +46,8 @@ jobs:
           restore-keys: |
             ${{ runner.os }}-go-cache
       - name: Restore base test coverage
-        if: matrix.go-version == '1.17.x'
+        id: base-coverage
+        if: matrix.go-version == env.COV_GO_VERSION
         uses: actions/cache@v2
         with:
           path: |
@@ -43,13 +55,13 @@ jobs:
           # Use base sha for PR or new commit hash for master/main push in test result key.
           key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
       - name: Checkout base code
-        if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
+        if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
         uses: actions/checkout@v2
         with:
           ref: ${{ github.event.pull_request.base.sha }}
           path: __base
       - name: Run test for base code
-        if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
+        if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
         run: |
           cd __base
           make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g'  > ../unit-base.txt) || echo "No test-unit in base"
@@ -59,17 +71,18 @@ jobs:
           make test-unit
           go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g'  > unit.txt
           OUTPUT=$(test -e unit-base.txt && (diff unit-base.txt unit.txt || exit 0) || cat unit.txt)
-          OUTPUT="${OUTPUT//'%'/'%25'}"
-          OUTPUT="${OUTPUT//$'\n'/'%0A'}"
-          OUTPUT="${OUTPUT//$'\r'/'%0D'}"
+          echo "${OUTPUT}"
+          OUTPUT="${OUTPUT//$'\n'/%0A}"
           TOTAL=$(grep 'total:' unit.txt)
+          echo "${TOTAL}"
           echo "::set-output name=diff::$OUTPUT"
           echo "::set-output name=total::$TOTAL"
       - name: Store base coverage
         if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
         run: cp unit.txt unit-base.txt
       - name: Comment Test Coverage
-        if: matrix.go-version == '1.17.x'
+        continue-on-error: true
+        if: matrix.go-version == env.COV_GO_VERSION
         uses: marocchino/sticky-pull-request-comment@v2
         with:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -85,7 +98,7 @@ jobs:
             
 
       - name: Upload code coverage
-        if: matrix.go-version == '1.17.x'
+        if: matrix.go-version == env.COV_GO_VERSION
         uses: codecov/codecov-action@v1
         with:
           file: ./unit.coverprofile
diff --git a/.golangci.yml b/.golangci.yml
index e89882f..58351e4 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -37,6 +37,10 @@ linters:
     - scopelint # deprecated
     - ifshort # too many false positives
     - golint # deprecated
+    - varnamelen
+    - tagliatelle
+    - errname
+    - ireturn
 
 issues:
   exclude-use-default: false
diff --git a/Makefile b/Makefile
index d60ee4b..4b37b06 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-#GOLANGCI_LINT_VERSION := "v1.41.1" # Optional configuration to pinpoint golangci-lint version.
+#GOLANGCI_LINT_VERSION := "v1.43.0" # Optional configuration to pinpoint golangci-lint version.
 
 # The head of Makefile determines location of dev-go to include standard targets.
 GO ?= go
@@ -23,7 +23,7 @@ ifeq ($(DEVGO_PATH),)
 	DEVGO_PATH := $(shell GO111MODULE=on $(GO) list ${modVendor} -f '{{.Dir}}' -m github.com/bool64/dev)
 	ifeq ($(DEVGO_PATH),)
     	$(info Module github.com/bool64/dev not found, downloading.)
-    	DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) mod tidy && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
+    	DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) get github.com/bool64/dev && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
 	endif
 endif
 
diff --git a/go.mod b/go.mod
index 7fab76b..2a27dbb 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,15 @@
 module github.com/vearutop/statigz
 
-go 1.16
+go 1.17
 
 require (
-	github.com/andybalholm/brotli v1.0.3
-	github.com/bool64/dev v0.1.41
+	github.com/andybalholm/brotli v1.0.4
+	github.com/bool64/dev v0.2.5
 	github.com/stretchr/testify v1.4.0
 )
+
+require (
+	github.com/davecgh/go-spew v1.1.0 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
+	gopkg.in/yaml.v2 v2.2.2 // indirect
+)
diff --git a/go.sum b/go.sum
index fa15692..17053bd 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
-github.com/andybalholm/brotli v1.0.3 h1:fpcw+r1N1h0Poc1F/pHbW40cUm/lMEQslZtCkBQ0UnM=
-github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
-github.com/bool64/dev v0.1.41 h1:L554LCQZc3d7mtcdPUgDbSrCVbr48/30zgu0VuC/FTA=
-github.com/bool64/dev v0.1.41/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
+github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
+github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
+github.com/bool64/dev v0.2.5 h1:H0bylghwcjDBBhEwSFTjArEO9Dr8cCaB54QSOF7esOA=
+github.com/bool64/dev v0.2.5/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
 github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=