From 7347a443818815b9ee9c986106d791cb2d859e2f Mon Sep 17 00:00:00 2001 From: Oleg Shokin Date: Wed, 22 Apr 2026 15:59:16 +0300 Subject: [PATCH] CAP-2634 | fix: remove test coverage badge from README.md --- .github/workflows/CI.yml | 37 ++--------- Makefile | 5 ++ README.md | 1 - make-workflows.md | 1 + scripts/sync_ci_golangci_lint_version.sh | 84 ++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 scripts/sync_ci_golangci_lint_version.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 03c0816..0f8f9c3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,21 +7,24 @@ on: branches: [main, master, develop] permissions: - contents: write + contents: read jobs: CI: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - with: - persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. - fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - uses: actions/setup-go@v6 with: go-version-file: go.mod + - name: Lint + uses: golangci/golangci-lint-action@v9 + with: + version: v2.11.4 + args: ./... + - name: Verify dependencies run: | go mod verify @@ -43,29 +46,3 @@ jobs: - name: Test run: make test - - - name: Go Coverage Badge # Pass the `coverage.out` output to this action - uses: tj-actions/coverage-badge-go@v3 - with: - filename: coverage.out - - - name: Verify changed files - uses: tj-actions/verify-changed-files@v20 - id: verify-changed-files - with: - files: README.md - - - name: Commit changes - if: steps.verify-changed-files.outputs.files_changed == 'true' - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add README.md - git commit -m "chore: Updated coverage badge." - - - name: Push changes - if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@v1.0.0 - with: - github_token: ${{ github.token }} - branch: ${{ github.head_ref || github.ref_name }} diff --git a/Makefile b/Makefile index 35bf954..63d2d9a 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,11 @@ lint: lint-prepare ## Use project-local golangci-lint from ./bin. $(GOLANGCI_LINT) run ./... +.PHONY: sync-ci-lint-version +sync-ci-lint-version: +## Sync CI golangci-lint version with Makefile pin. + ./scripts/sync_ci_golangci_lint_version.sh + .PHONY: fix fix: lint-prepare ## Apply automatic source fixes. diff --git a/README.md b/README.md index 842ac3a..9672fc2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/newcloudtechnologies/memlimiter.svg)](https://pkg.go.dev/github.com/newcloudtechnologies/memlimiter) [![Go Report Card](https://goreportcard.com/badge/github.com/newcloudtechnologies/memlimiter)](https://goreportcard.com/report/github.com/newcloudtechnologies/memlimiter) -![Coverage](https://img.shields.io/badge/Coverage-82.9%25-brightgreen) ![CI](https://github.com/newcloudtechnologies/memlimiter/actions/workflows/CI.yml/badge.svg) `memlimiter` helps a Go service avoid OOM by combining adaptive GC tuning and request throttling under memory pressure. diff --git a/make-workflows.md b/make-workflows.md index 58f35fd..4872f00 100644 --- a/make-workflows.md +++ b/make-workflows.md @@ -121,6 +121,7 @@ Expected generated files: - `make allocator-build` - build `test/allocator/allocator` only. - `make generate` - regenerate protobuf files for allocator schema. - `make lint-prepare` - install lint tools and verify lint config. +- `make sync-ci-lint-version` - copy `GOLANGCI_LINT_VERSION` from `Makefile` to `.github/workflows/CI.yml`. - `make clean` - remove generated binaries, coverage files, and Python cache for analyzer scripts. ## Common Overrides diff --git a/scripts/sync_ci_golangci_lint_version.sh b/scripts/sync_ci_golangci_lint_version.sh new file mode 100644 index 0000000..1242eb3 --- /dev/null +++ b/scripts/sync_ci_golangci_lint_version.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +# +# Sync golangci-lint version in CI workflow with Makefile pin. +# Usage: +# scripts/sync_ci_golangci_lint_version.sh [makefile] [workflow] + +set -euo pipefail + +if [[ "$#" -gt 2 ]]; then + echo "usage: $0 [makefile] [workflow]" >&2 + exit 2 +fi + +makefile_path="${1:-Makefile}" +workflow_path="${2:-.github/workflows/CI.yml}" + +if [[ ! -f "${makefile_path}" ]]; then + echo "makefile not found: ${makefile_path}" >&2 + exit 1 +fi + +if [[ ! -f "${workflow_path}" ]]; then + echo "workflow file not found: ${workflow_path}" >&2 + exit 1 +fi + +# Read pinned local linter version from Makefile. +desired_version="$( + sed -nE 's/^[[:space:]]*GOLANGCI_LINT_VERSION[[:space:]]*[:?+]?=[[:space:]]*(v[0-9]+\.[0-9]+\.[0-9]+).*/\1/p' "${makefile_path}" | head -n1 +)" + +if [[ -z "${desired_version}" ]]; then + echo "failed to read GOLANGCI_LINT_VERSION from ${makefile_path}" >&2 + exit 1 +fi + +# Read current CI linter version for status output. +current_version="$( + awk ' + /^[[:space:]]*uses:[[:space:]]*golangci\/golangci-lint-action@/ { in_step=1; next } + in_step && /^[[:space:]]*version:[[:space:]]*/ { + sub(/^[[:space:]]*version:[[:space:]]*/, "", $0) + print $0 + exit + } + in_step && /^[[:space:]]*-[[:space:]]*name:[[:space:]]*/ { in_step=0 } + ' "${workflow_path}" +)" + +if [[ -z "${current_version}" ]]; then + echo "failed to read golangci-lint version from ${workflow_path}" >&2 + exit 1 +fi + +tmp_file="$(mktemp)" +trap 'rm -f "${tmp_file}"' EXIT + +if ! awk -v desired_version="${desired_version}" ' + /^[[:space:]]*uses:[[:space:]]*golangci\/golangci-lint-action@/ { in_step=1 } + in_step && /^[[:space:]]*version:[[:space:]]*/ { + sub(/version:[[:space:]]*.*/, "version: " desired_version) + updated=1 + in_step=0 + } + { print } + END { + if (updated != 1) { + exit 3 + } + } +' "${workflow_path}" > "${tmp_file}"; then + echo "failed to update golangci-lint version in ${workflow_path}" >&2 + exit 1 +fi + +if cmp -s "${tmp_file}" "${workflow_path}"; then + echo "golangci-lint CI version already synced (${current_version})" + exit 0 +fi + +mv "${tmp_file}" "${workflow_path}" +trap - EXIT + +echo "updated ${workflow_path}: golangci-lint version ${current_version} -> ${desired_version}"