Skip to content

Commit

Permalink
Check if go.mod exists
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby authored Nov 17, 2023
1 parent 9ca3516 commit b904c40
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ jobs:
HEAD_SHA="${{ github.event.after }}"
fi
# Find changed directories that contain go.mod, convert to JSON and export
# Extract directories from changed files
FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA)
GO_MOD_DIRECTORIES=$(find . -name 'go.mod' | xargs -L1 dirname | sort -u)
CHANGED_DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u)
MATCHED_DIRECTORIES=$(echo "${GO_MOD_DIRECTORIES}" "${CHANGED_DIRECTORIES}" | tr ' ' '\n' | sort | uniq -d)
JSON_ARRAY=$(echo "$MATCHED_DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]')
DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u | grep -vE '/\.')
# Check each directory for a go.mod file and prepare JSON array
GO_MOD_DIRECTORIES=()
for dir in $DIRECTORIES; do
if [[ -f "$dir/go.mod" ]]; then
GO_MOD_DIRECTORIES+=("$dir")
fi
done
JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]')
# Export the JSON array
echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT
lint:
Expand Down

0 comments on commit b904c40

Please sign in to comment.