stringlint: add string comparison linter #954
Workflow file for this run
This file contains hidden or 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
| name: Run Style Check And Unit Test | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # actions/checkout@v4.2.2 | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
| - name: Get changed files | |
| id: changed-files | |
| # tj-actions/changed-files@v45.0.9 | |
| uses: tj-actions/changed-files@a284dc1814e3fd07f2e34267fc8f81227ed29fb8 | |
| - name: Get all changed packages | |
| id: updated_pkgs | |
| env: | |
| ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
| run: | | |
| # Extract directories from changed files | |
| changed_dirs=() | |
| for file in $ALL_CHANGED_FILES; do | |
| # Get the directory part of the file path | |
| dir=$(dirname "$file") | |
| changed_dirs+=("$dir") | |
| done | |
| # Unique the changed directories | |
| changed_dirs=($(printf "%s\n" "${changed_dirs[@]}" | sort -u)) | |
| # Get all changed packages | |
| updated_pkgs=() | |
| for dir in "${changed_dirs[@]}"; do | |
| # Check if the dir has go.mod in it or in parent directories | |
| current_dir="$dir" | |
| while [[ "$current_dir" != "." && "$current_dir" != "/" ]]; do | |
| if [[ -f "$current_dir/go.mod" ]]; then | |
| updated_pkgs+=("$current_dir") | |
| break | |
| fi | |
| # Move to parent directory | |
| current_dir=$(dirname "$current_dir") | |
| done | |
| done | |
| # Unique the changed packages | |
| updated_pkgs=($(printf "%s\n" "${updated_pkgs[@]}" | sort -u)) | |
| echo "updated_pkgs=${updated_pkgs[*]}" >> $GITHUB_OUTPUT | |
| has_changed_packages=false | |
| if (( ${#updated_pkgs[@]} > 0 )); then | |
| has_changed_packages=true | |
| fi | |
| echo "has_changed_packages=$has_changed_packages" >> $GITHUB_OUTPUT | |
| - name: Set up Go | |
| # actions/setup-go@v5.4.0 | |
| uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b | |
| if: ${{ steps.updated_pkgs.outputs.has_changed_packages == 'true' }} | |
| with: | |
| go-version: ^1.20 | |
| - name: Set up tools | |
| if: ${{ steps.updated_pkgs.outputs.has_changed_packages == 'true' }} | |
| run: | | |
| sudo apt update && sudo apt install -y build-essential bc | |
| go install github.com/mgechev/revive@latest | |
| - name: Style Check | |
| env: | |
| UPDATED_PKGS: ${{ steps.updated_pkgs.outputs.updated_pkgs }} | |
| run: | | |
| # get all the changed directories | |
| updated_pkgs=($UPDATED_PKGS) | |
| revive_config=$(realpath revive.toml) | |
| for pkg in "${updated_pkgs[@]}"; do | |
| # check do we need to run revive, include go files | |
| have_go_files=$(find "$pkg" -name '*.go' -maxdepth 1 -exec dirname {} \; | sort -u | uniq) | |
| if [ -z "$have_go_files" ]; then | |
| continue | |
| fi | |
| echo "running go vet and revive for $pkg" | |
| pushd "$pkg" >/dev/null 2>&1 || exit 255 | |
| go vet ./... || exit 255 | |
| revive -formatter friendly -config $revive_config ./... || exit 255 | |
| popd >/dev/null 2>&1 || exit 255 | |
| done | |
| - name: Run Unit Test | |
| env: | |
| UPDATED_PKGS: ${{ steps.updated_pkgs.outputs.updated_pkgs }} | |
| run: | | |
| # get all the changed packages | |
| updated_pkgs=($UPDATED_PKGS) | |
| for pkg in "${updated_pkgs[@]}"; do | |
| # check do we need to run revive, include _test.go files | |
| have_go_files=$(find "$pkg" -name '*_test.go' -maxdepth 1 -exec dirname {} \; | sort -u | uniq) | |
| if [ -z "$have_go_files" ]; then | |
| echo "skipping empty $pkg" | |
| continue | |
| fi | |
| echo "running go test for $pkg" | |
| pushd > /dev/null 2>&1 "$pkg" || exit 255 | |
| num_of_pros=$(grep -c ^processor /proc/cpuinfo) | |
| go test ./... -race -cover -p "$num_of_pros" | |
| popd > /dev/null 2>&1 || exit 255 | |
| done |