Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
58 changes: 58 additions & 0 deletions .github/scripts/fetch-base-incrementally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
set -euo pipefail

# Incrementally fetch git history until we find the merge base with the target branch
# Usage: ./fetch-base-incrementally.sh <base-ref>

if [ $# -eq 0 ]; then
echo "Error: No base branch specified"
echo "Usage: $0 <base-ref>"
exit 1
fi

BASE_REF="$1"
echo "Fetching git history to find merge base with $BASE_REF branch..."

# Check if we have the merge base and print it
check_merge_base() {
if MERGE_BASE=$(git merge-base HEAD "origin/$BASE_REF" 2>/dev/null); then
echo "✓ Found merge base: $(git rev-parse --short "$MERGE_BASE")"
return 0
fi
return 1
}

FETCH_INCREMENT=50 # How many commits to deepen on each iteration
MAX_ITERATIONS=10 # The number of times to deepen before we just fetch everything

# Start with a minimal fetch of just the base ref
git fetch --depth=1 origin "$BASE_REF" >/dev/null 2>&1

# Now deepen to get history from both branches
echo "→ Fetching up to $FETCH_INCREMENT commits of shared history..."
git fetch --deepen=$FETCH_INCREMENT origin HEAD "$BASE_REF"

# Check if we already have the merge base
if check_merge_base; then
exit 0
fi

# Incrementally deepen by FETCH_INCREMENT commits at a time
for i in $(seq 1 $MAX_ITERATIONS); do
echo "→ Need more history, fetching up to $FETCH_INCREMENT additional commits..."
git fetch --deepen=$FETCH_INCREMENT origin HEAD "$BASE_REF"

if check_merge_base; then
exit 0
fi
done

# Final fallback to full fetch if needed
echo "⚠ Branch history is deep, fetching all commits..."
git fetch --unshallow origin "$BASE_REF" || git fetch origin "$BASE_REF"

# Verify we found it
if ! check_merge_base; then
echo "✗ Failed to find merge base with $BASE_REF even after full fetch"
exit 1
fi
13 changes: 12 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ jobs:
- name: Checkout EigenDA
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #4.2.2

# Fetch git history of the base branch so golangci-lint can analyze only the diff
# between the feature branch and base branch (via --new-from-rev flag)
- name: Fetch base branch history
if: github.event_name == 'pull_request'
run: bash .github/scripts/fetch-base-incrementally.sh "${{ github.event.pull_request.base.ref }}"

- uses: jdx/mise-action@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the hash here as well please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean for mise?

I can open a separate PR for that if you'd like, since it's not related to this linter change.

with:
version: ${{ env.MISE_VERSION }}
experimental: true
- run: go version
- run: make lint

- name: Run linter
run: |
# Use PR base branch if available, otherwise the command line flag is ignored and master is used
golangci-lint run --new-from-rev=origin/${{ github.event.pull_request.base.ref || 'master' }}

- run: make fmt-check
26 changes: 9 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@ run:
linters:
enable:
- protogetter # reports direct reads from proto message fields when getters should be used.
# Right now revive raises 50+ issues, whereas golint didn't have any.
# despite revive being recommended as a replacement for golint.
# TODO: should we turn on revive and fix the issues?
# - revive # drop-in replacement for golint
exclusions:
rules:
- linters:
- staticcheck
# https://staticcheck.dev/docs/checks#QF1008
# There were lots of this error and I didn't feel like fixing them all.
text: "QF1008"
- linters:
- staticcheck
# https://staticcheck.dev/docs/checks#QF1003
# We have a lot of these and I don't want to fix them all.
# Also doesn't feel like a big deal.
text: "QF1003"
- revive # drop-in replacement for golint

issues:
# Only show issues in new/modified code, not existing code
new: true
# Diff compared to master will be linted by default, but the --new-from-rev= flag can be used when running the linter
# to lint the diff between the feature and a different target. This is how CI handles the linting: it lints the diff
# between the feature branch, and the branch being merged into.
new-from-rev: master
Loading