Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions make-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 84 additions & 0 deletions scripts/sync_ci_golangci_lint_version.sh
Original file line number Diff line number Diff line change
@@ -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}"