-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d3d3b7
commit 3757168
Showing
1 changed file
with
72 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,78 @@ | ||
name: Golangci Lint Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
- "main" | ||
paths-ignore: | ||
- "**.md" | ||
- LICENSE | ||
- ".github/ISSUE_TEMPLATE/*.yml" | ||
- ".github/dependabot.yml" | ||
pull_request: | ||
branches: | ||
- "*" | ||
paths-ignore: | ||
- "**.md" | ||
- LICENSE | ||
- ".github/ISSUE_TEMPLATE/*.yml" | ||
- ".github/dependabot.yml" | ||
push: | ||
branches: | ||
- "master" | ||
- "main" | ||
paths-ignore: | ||
- "**.md" | ||
- LICENSE | ||
- ".github/ISSUE_TEMPLATE/*.yml" | ||
- ".github/dependabot.yml" | ||
pull_request: | ||
branches: | ||
- "*" | ||
paths-ignore: | ||
- "**.md" | ||
- LICENSE | ||
- ".github/ISSUE_TEMPLATE/*.yml" | ||
- ".github/dependabot.yml" | ||
|
||
jobs: | ||
set-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.generate-matrix.outputs.matrix }} | ||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
- name: Generate Matrix | ||
id: generate-matrix | ||
run: | | ||
SUBDIRS=$(find . -maxdepth 1 -type d -not -name '.*' -not -name 'internal' -not -empty | sed 's|./||' | tr '\n' ' ' | sed 's/ $//') | ||
JSON_MATRIX=$(echo "$SUBDIRS" | jq -R -c -s 'split(" ") | map(select(. != "")) | .[-1] |= sub("\n$"; "")') | ||
echo "matrix=$JSON_MATRIX" >> $GITHUB_OUTPUT | ||
generate-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- id: set-matrix | ||
run: | | ||
# Determine the base and head commits for diff based on the event type | ||
BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}" | ||
HEAD_SHA="${{ github.event.pull_request.head.sha || github.event.after }}" | ||
golangci-lint: | ||
runs-on: ubuntu-latest | ||
needs: set-matrix | ||
strategy: | ||
matrix: | ||
directory: ${{fromJson(needs.set-matrix.outputs.matrix)}} | ||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.x' | ||
- name: Install golangci-lint | ||
run: go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
- name: Run golangci-lint | ||
working-directory: ./${{ matrix.directory }} | ||
run: golangci-lint run --tests=false | ||
# Extract directories from changed files, only include those with go.mod files | ||
GO_MOD_DIRECTORIES=() | ||
CURRENT_BRANCH="${{ github.ref_name }}" | ||
if [[ "$CURRENT_BRANCH" == "main" ]]; then | ||
GO_MOD_DIRECTORIES=$(find . -type f -name "go.mod" -exec dirname {} \; | sort -u) | ||
else | ||
FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -vE '/\.') | ||
DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) | ||
for dir in $DIRECTORIES; do | ||
if [[ -f "$dir/go.mod" ]] && [[ "$dir" != "." ]]; then | ||
GO_MOD_DIRECTORIES+=("$dir") | ||
fi | ||
done | ||
fi | ||
# Check if GO_MOD_DIRECTORIES is empty | ||
if [[ ${#GO_MOD_DIRECTORIES[@]} -eq 0 ]]; then | ||
JSON_ARRAY="[]" | ||
else | ||
# Export the JSON array | ||
JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]') | ||
fi | ||
echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT | ||
lint: | ||
needs: generate-matrix | ||
if: ${{ needs.generate-matrix.outputs.matrix != '[]' }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
modules: ${{fromJson(needs.generate-matrix.outputs.matrix)}} | ||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
- name: Run golangci-lint | ||
uses: reviewdog/action-golangci-lint@v2 | ||
with: | ||
golangci_lint_flags: "--tests=false --timeout=5m" | ||
workdir: ${{ matrix.modules }} | ||
fail_level: "warning" | ||
filter_mode: nofilter |