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

CI: extract the code in .github/workflows/go.yml into a script #1399

Open
ccoVeille opened this issue Jan 18, 2025 · 2 comments
Open

CI: extract the code in .github/workflows/go.yml into a script #1399

ccoVeille opened this issue Jan 18, 2025 · 2 comments

Comments

@ccoVeille
Copy link
Contributor

The current code of .github/workflows/go.yml contains something like this

      - name: Detect and Test Submodules
        run: |
          # Find all directories containing a go.mod file within 'pkg'
          for module in $(find pkg -name "go.mod" -exec dirname {} \;); do
            echo "Testing module: $module"
            cd $module
          
            # Extract module name (replace '/' with '_')
            module_name=$(echo $module | tr '/' '_')

            # Download dependencies for the submodule
            go mod download
            go mod tidy

            # Run tests for the submodule and generate coverage
            export APP_ENV=test
            warning_count=$(go test ./... -v -short -coverprofile=${module_name}.cov -coverpkg=./... | tee /dev/tty | grep -c "WARNING" || true)
            total_warning_count=$((total_warning_count + warning_count))

            # Return to the root directory
            cd -
          done
          
          echo "Total warnings found: $total_warning_count"
          echo "total_warning_count=$total_warning_count" >> $GITHUB_ENV

The code is too complicated to be maintained in a YAML file, and it cannot be easily tested without running it via a GHA
The code could be extracted to something like a shell script or equivalent

This idea comes from the discussion that happened here

@La002
Copy link

La002 commented Jan 26, 2025

@ccoVeille Hi, wanting to take this as first-issue.
Can I know whether you are thinking of moving only this piece of code to a separate script or some others as well. With respect to length and complexity, this is another closest I see.

      - name: Lint Submodules
        run: |
          echo "Searching for submodules..."
          total_errors=0  # Initialize error counter
          for module in $(find pkg -name "go.mod" -exec dirname {} \;); do
            echo "Linting submodule: $module"
            # Change directory to the submodule and run golangci-lint
            cd $module
            go mod tidy
            golangci-lint run --timeout 9m0s || total_errors=$((total_errors + 1))
            cd -  # Return to the root directory
          done
          echo "Total submodule lint errors: $total_errors"
          if [ $total_errors -gt 0 ]; then
            echo "Linting failed for $total_errors submodule(s)."
            exit 1  # Fail the job if there are linting errors in submodules
          fi

@ccoVeille
Copy link
Contributor Author

Hi @La002

Thanks for your interest.

I opened this issue a few days ago.

And the need was real.

Lately, I worked on #1426

And once merged, I'm pretty sure the section of script I quoted and extract in the current issue we are talking on is likely to be deleted.

So for now, I would say this ticket should be considered on hold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants