From 5514fbebff6ca215b53576876868d7023ecc675f Mon Sep 17 00:00:00 2001 From: Vasiliy Vasilyuk Date: Thu, 8 Feb 2024 22:37:22 +0300 Subject: [PATCH] Add check actuality of go.mod and go.sum --- .github/workflows/go.yml | 26 ++++++++++++++++++++++++++ .gitlab-ci.yml | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 49747df..bc8e3e3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -38,6 +38,32 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + # Check actuality of go.mod and go.sum + # + # See https://xorcare.ru/s/8dd13 + check-go-modules: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22.0' + + - name: Check actuality of go.mod and go.sum + run: | + go mod tidy + git diff --exit-code && exit 0 || true + echo '######################################################################' + echo + echo "ERROR: go.mod or go.sum is different from the committed version" + echo "Try using 'go mod tidy' to fix the go.mod and go.sum files" + echo "Also, don't forget to commit and push changes" + echo + echo '######################################################################' + exit 1 + golangci: name: lint runs-on: ubuntu-latest diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 579fcae..cbf5760 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,3 +47,22 @@ test: coverage: '/^total:\s+\(statements\)\s+(\d+(?:\.\d+)?%)/' only: - branches + +# Check actuality of go.mod and go.sum +# +# See https://xorcare.ru/s/8dd13 +check-go-modules: + stage: test + script: + - go mod tidy + - | + git diff --exit-code && exit 0 || true + echo -e "\033[0;31m" + echo '######################################################################' + echo + echo "ERROR: go.mod or go.sum is different from the committed version" + echo "Try using 'go mod tidy' to fix the go.mod and go.sum files" + echo "Also, don't forget to commit and push changes" + echo + echo '######################################################################' + exit 1