Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add golangci-lint version manager #3457

Merged
merged 44 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
598bf58
feat: add golangci-lint version manager
devin-ai-integration[bot] Dec 12, 2024
415baf1
chore: update golangci-lint version to 1.61.0 and fix linter naming
devin-ai-integration[bot] Dec 12, 2024
25b3818
[goreleaser] refactor: improve module handling and working directory …
devin-ai-integration[bot] Dec 12, 2024
fbadb01
[goreleaser] feat: add goreleaser configuration
devin-ai-integration[bot] Dec 12, 2024
bcc7850
[goreleaser] feat: add Docker configuration for golang-ci-lint
devin-ai-integration[bot] Dec 12, 2024
a254b3b
[goreleaser] feat: add codecov integration and update go-findroot imp…
devin-ai-integration[bot] Dec 12, 2024
b711667
[goreleaser] feat: update Dockerfile with multi-stage build
devin-ai-integration[bot] Dec 12, 2024
01cd002
[goreleaser] fix: improve error handling and context propagation
devin-ai-integration[bot] Dec 12, 2024
1ba588b
[goreleaser] fix: clarify binary permission requirements in error mes…
devin-ai-integration[bot] Dec 12, 2024
9fced1f
[goreleaser] feat: add Makefile for local development
devin-ai-integration[bot] Dec 12, 2024
f7619df
[goreleaser] fix: update binary permissions to 0755 for golangci-lint…
devin-ai-integration[bot] Dec 12, 2024
45320f2
[goreleaser] fix: implement consistent umask handling for secure file…
devin-ai-integration[bot] Dec 12, 2024
d2f957a
[goreleaser] fix: replace syscall.Umask with cross-platform permissio…
devin-ai-integration[bot] Dec 12, 2024
fb9eef2
[goreleaser] fix: add path validation and error wrapping for security
devin-ai-integration[bot] Dec 12, 2024
3fd1746
[goreleaser] fix: strengthen path validation with absolute paths and …
devin-ai-integration[bot] Dec 12, 2024
4bfd12e
[goreleaser] feat: update goreleaser config to v2 and add buildkit su…
devin-ai-integration[bot] Dec 12, 2024
9537dbc
[goreleaser] fix: add nolint directives for validated file operations
devin-ai-integration[bot] Dec 12, 2024
6378b87
[goreleaser] docs: add proper documentation for bridge module constants
devin-ai-integration[bot] Dec 12, 2024
59b5c49
[goreleaser] fix: add API key to etherscan client customization
devin-ai-integration[bot] Dec 14, 2024
be1b388
[goreleaser] chore: align docker and goreleaser configuration with re…
devin-ai-integration[bot] Dec 14, 2024
bc1261a
[goreleaser] refactor: replace go.mod detection with go-findroot for …
devin-ai-integration[bot] Dec 14, 2024
d7b3625
[goreleaser] chore: update codecov configuration with proper yaml for…
devin-ai-integration[bot] Dec 14, 2024
de40af8
[goreleaser] fix: remove buildkit dependency and align with repositor…
devin-ai-integration[bot] Dec 14, 2024
ce76957
[goreleaser] fix: update docker build context and simplify build process
devin-ai-integration[bot] Dec 14, 2024
6330057
[goreleaser] feat: update Docker build context and configuration
devin-ai-integration[bot] Dec 14, 2024
69c371b
[goreleaser] fix: restore golangci configuration files
devin-ai-integration[bot] Dec 14, 2024
d988ff1
[goreleaser] feat: add golang-ci-lint version manager with cross-repo…
devin-ai-integration[bot] Dec 14, 2024
1fd3cc1
[goreleaser] fix: remove unsupported docker build settings
devin-ai-integration[bot] Dec 14, 2024
c2f28de
[goreleaser] fix: add extra_files configuration to resolve build cont…
devin-ai-integration[bot] Dec 14, 2024
3959cfa
[goreleaser] chore: update gitignore and remove binary file
devin-ai-integration[bot] Dec 14, 2024
ba291bc
[goreleaser] refactor: update Dockerfile to copy pre-built binary and…
devin-ai-integration[bot] Dec 14, 2024
e3dcb98
[goreleaser] refactor: remove go install and cleanup generate.go
devin-ai-integration[bot] Dec 14, 2024
c9da56a
[goreleaser] docs: update README with cross-repository usage instruct…
devin-ai-integration[bot] Dec 14, 2024
54ac856
[goreleaser] chore: update Go version to 1.22.4
devin-ai-integration[bot] Dec 14, 2024
55a9700
[goreleaser] revert: restore original RFQ contract generation configu…
devin-ai-integration[bot] Dec 14, 2024
90d49a3
[goreleaser] chore: update go.work version to 1.22.4
devin-ai-integration[bot] Dec 14, 2024
a5e78f6
[goreleaser] test: add MacOS path validation tests and fix path norma…
devin-ai-integration[bot] Dec 14, 2024
1cab263
[goreleaser] docs: add MacOS path handling documentation
devin-ai-integration[bot] Dec 14, 2024
83294d0
[goreleaser] fix: resolve linting issues and improve module detection
devin-ai-integration[bot] Dec 14, 2024
5ab7e6c
[goreleaser] fix: replace unsafe uint64 conversions with validateChainID
devin-ai-integration[bot] Dec 14, 2024
eafb003
[goreleaser] chore: remove golang-ci-lint binary and update gitignore
devin-ai-integration[bot] Dec 14, 2024
72a76b6
reinstate pr metadatA
trajan0x Dec 14, 2024
0396d4b
constant fix
trajan0x Dec 14, 2024
5f25b5f
fix lint [goreleaser]
trajan0x Dec 14, 2024
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
12 changes: 8 additions & 4 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ flags:
paths:
- contrib/screener-api/
carryforward: true
opbot:
paths:
- contrib/opbot/
carryforward: true
git-changes-action:
paths:
- contrib/git-changes-action/
carryforward: true
golang-ci-lint:
paths:
- contrib/golang-ci-lint/
carryforward: true
opbot:
paths:
- contrib/opbot/
carryforward: true
core:
paths:
- core/
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
# note: without building a yaml tree of our workflow, we won't be able to tell if golangci version changed so any ci change triggers full lint.
files: |
.golangci.yml
.golangci-version
.github/workflows/go.yml


Expand Down Expand Up @@ -336,19 +337,21 @@ jobs:
- name: Setup cache key
run: cp ${{matrix.package}}/go.mod go.mod -v

- name: Read golangci-lint version
id: golangci_version
run: echo "version=v$(cat .golangci-version)" >> $GITHUB_OUTPUT

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: ${{matrix.package}}/
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.60.3
# see: https://github.com/golangci/golangci-lint/issues/2654
version: ${{ steps.golangci_version.outputs.version }}
args: --timeout=60m
env:
# GitHub token for annotations (optional)
GITHUB_TOKEN: ${{ secrets.WORKFLOW_PAT || secrets.GITHUB_TOKEN }}
GOMEMLIMIT: 6GiB
GOGC: -1

pr_metadata:
# this is needed to prevent us from hitting the github api rate limit
name: Get PR Metadata
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ main
.devnet/

**/__debug_bin*

# golang-ci-lint binary
contrib/golang-ci-lint/golang-ci-lint
1 change: 1 addition & 0 deletions .golangci-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.61.0
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ linters:
- typecheck
# magic numbers
- mnd
# constants
- goconst
fast: false

issues:
Expand Down Expand Up @@ -138,7 +140,7 @@ issues:
- cyclop
- path: signoz/*
linters:
- mnd
- gomnd
- stylecheck
- path: example/*
linters:
Expand Down
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ If you need to make a new JS/TS package, here are the steps to follow:

## Linting

Linting for go is used using [golangci-lint](https://golangci-lint.run/) at the latest released version. Please upgrade or install using your package manager. and run `make lint` from your desired module.
Linting for Go code uses [golangci-lint](https://golangci-lint.run/). The version is pinned in `.golangci-version` file and managed automatically through our tooling. Simply run `make lint` from your desired module, and the correct version will be downloaded (if not already cached) and used automatically.

### Golang-CI-Lint Module
The `contrib/golang-ci-lint` module provides version-pinned golangci-lint execution across repositories. The module automatically downloads and manages the correct version of golangci-lint based on the version specified in `.golangci-version` file, ensuring consistent linting across all Go modules.

#### Building and Testing
```bash
cd contrib/golang-ci-lint
make lint
make test
```

For more details about the module's implementation and usage, see the [module's README](contrib/golang-ci-lint/README.md).

## Adding a new Go Module

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ Clone the repository, open it, and install nodejs packages with `yarn`:
git clone https://github.com/synapsecns/sanguine --recurse-submodules -j10
cd sanguine
yarn install

### Go Development Setup

For Go development:
1. The project uses a specific version of golangci-lint that is managed automatically through our version management system
2. No manual installation of golangci-lint is required
3. The version is pinned in `.golangci-version` file and managed by the `contrib/golang-ci-lint` module
4. Run `make lint` in any Go module directory to automatically download and use the correct version

### Golang-CI-Lint Version Management
The repository uses a pinned version of golangci-lint specified in `.golangci-version`. The linter is automatically downloaded and executed through `make lint`. This ensures consistent linting across all Go modules and development environments.

Key features:
- Automatic version management based on `.golangci-version`
- Cross-platform compatibility
- Secure download and verification
- Caching for improved performance
```


Expand Down
16 changes: 16 additions & 0 deletions contrib/golang-ci-lint/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
coverage:
status:
project:
default:
target: '80%'
threshold: '1%'
patch:
default:
target: '80%'

ignore:
- '**/testdata/**'
- '**/mocks/**'
- '**/*_test.go'
- '**/cmd/**'
- '**/docs/**'
68 changes: 68 additions & 0 deletions contrib/golang-ci-lint/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
project_name: golang-ci-lint

monorepo:
tag_prefix: contrib/golang-ci-lint/
dir: contrib/golang-ci-lint/

builds:
- id: golang-ci-lint
binary: golang-ci-lint
gcflags:
- all=-dwarflocationlists=true
ldflags:
- -s -w -extldflags '-static'
tags:
- netgo
env:
- CGO_ENABLED=0
main: main.go
flags:
- -trimpath
goos:
- linux
goarch:
- amd64

dockers:
- goos: linux
goarch: amd64
image_templates:
- 'ghcr.io/synapsecns/sanguine/golang-ci-lint:latest'
- 'ghcr.io/synapsecns/sanguine/golang-ci-lint:{{ .FullCommit }}'
- 'ghcr.io/synapsecns/sanguine/golang-ci-lint:{{ .Tag }}'
build_flag_templates:
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.name={{.ProjectName}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--label=org.opencontainers.image.source={{.GitURL}}'
dockerfile: ../../docker/golang-ci-lint.Dockerfile
ids:
- golang-ci-lint

source:
enabled: true

archives:
- format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
name_template: '{{.ProjectName}}-{{.Version}}_{{.Os}}_{{.Arch}}'
files:
- README.md

checksum:
name_template: checksums.txt

changelog:
sort: asc

report_sizes: true

metadata:
mod_timestamp: '{{ .CommitTimestamp }}'

sboms:
- artifacts: archive
1 change: 1 addition & 0 deletions contrib/golang-ci-lint/Makefile
116 changes: 116 additions & 0 deletions contrib/golang-ci-lint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Golang CI Lint Version Manager

A standalone tool for managing and running specific versions of golangci-lint across different repositories. This package can be used in any Go project to ensure consistent linting with version pinning, regardless of where it's installed.

## Features
- **Cross-Repository Usage**: Can be installed and used in any Go project
- **Version Pinning**: Automatically uses the version specified in `.golangci-version`
- **Architecture Support**: Downloads correct binary for your system (AMD64/ARM64)
- **Binary Caching**: Avoids redundant downloads of the same version
- **Secure Downloads**: Verifies binary checksums for security
- **CI/CD Integration**: Easy to integrate with GitHub Actions and other CI systems

## Installation

As a standalone tool:
```bash
go install github.com/synapsecns/sanguine/contrib/golang-ci-lint@latest
```

Or in your project's go.mod:
```go
require github.com/synapsecns/sanguine/contrib/golang-ci-lint v1.0.0
```

## Usage

### 1. Version Configuration
Create a `.golangci-version` file in your repository root:
```
1.61.0
```

### 2. Running the Linter

As a standalone binary:
```bash
golang-ci-lint run --fix --config=.golangci.yml
```

Or using go run:
```bash
go run github.com/synapsecns/sanguine/contrib/golang-ci-lint run --fix --config=.golangci.yml
```

### 3. Makefile Integration

Add to your project's Makefile:
```makefile
.PHONY: lint
lint:
go run github.com/synapsecns/sanguine/contrib/golang-ci-lint run --fix --config=.golangci.yml
```

### 4. CI/CD Integration

GitHub Actions example:
```yaml
name: Lint
on: [push, pull_request]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install golang-ci-lint manager
run: go install github.com/synapsecns/sanguine/contrib/golang-ci-lint@latest
- name: Run linter
run: golang-ci-lint run --config=.golangci.yml
```

## Common Use Cases

1. **Multiple Projects**: Use the same linter version across all your repositories
2. **CI/CD Pipelines**: Ensure consistent linting in automated workflows
3. **Team Collaboration**: Maintain consistent code style across development teams
4. **Version Control**: Lock linter version to avoid unexpected behavior changes

## Troubleshooting

1. **Binary Not Found**
```bash
# Clear the cache and redownload
rm -rf ~/.cache/golangci-lint
golang-ci-lint run
```

2. **Version Mismatch**
- Ensure `.golangci-version` exists in repository root
- Check file permissions and format

3. **Architecture Issues**
- The tool automatically detects and downloads the correct binary
- Supported architectures: linux-amd64, linux-arm64, darwin-amd64, darwin-arm64, windows-amd64
- MacOS (/private/var) symlink handling:
- Properly resolves /private/var to /var for temp directories
- Maintains secure path validation across symlinked paths
- Handles platform-specific temp directory structures

## Contributing

Contributions are welcome! Please ensure:
- Cross-platform compatibility:
- Linux: Standard path resolution
- MacOS: Handles /private/var symlinks and temp directories
- Windows: Supports standard Windows paths
- Backward compatibility with existing `.golangci-version` files
- Proper error handling and user feedback

## License

MIT License - See LICENSE file for details
5 changes: 5 additions & 0 deletions contrib/golang-ci-lint/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/synapsecns/sanguine/contrib/golang-ci-lint

go 1.22.4

require github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc
2 changes: 2 additions & 0 deletions contrib/golang-ci-lint/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc h1:4IZpk3M4m6ypx0IlRoEyEyY1gAdicWLMQ0NcG/gBnnA=
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc/go.mod h1:UlaC6ndby46IJz9m/03cZPKKkR9ykeIVBBDE3UDBdJk=
Loading
Loading