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

Support for go modules in subdirectories #17

Closed
ryeguard opened this issue Dec 8, 2024 · 4 comments
Closed

Support for go modules in subdirectories #17

ryeguard opened this issue Dec 8, 2024 · 4 comments

Comments

@ryeguard
Copy link

ryeguard commented Dec 8, 2024

I have a project where the root does not contain the go module (go.mod, etc). It would be nice to be able to support creating a badge for such projects.

I looked around in the code but I could not find support for it in the current state. Please correct me if I am wrong. Would you be open to supporting this? If so, I can help out implementing it.

Ideally, it would be nice if the workflow "respected" the working-directory which can be set on jobs/steps. (It does not seem to be that way currently.)

I.e., it'd be nice if the following worked as expected. It does not now.

on:
  push:
    branches: ["main"]

jobs:
  test-and-coverage:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./dir/to/module

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v4
        with:
          go-version: "1.22"

      - run: go test -v ./...

      - name: Go coverage report
        uses: ncruces/[email protected]
@ncruces
Copy link
Owner

ncruces commented Dec 8, 2024

This project has increasingly steered away from generating coverage for anything but a bog standard simple repo, where the default just works.

We focus on the badge, the chart, the report, and saving those in the wiki in a seamless way.

What you can do, what I do for any more complex case, is to generate the coverage file yourself, and then use this action to generate the report/badge/chart from that file using the coverage-file input property.

So, instead of:

run: go test -v ./...

Do whatever you need to test your package with coverage, and write coverage to a file like coverage.out.

Then do:

- name: Update coverage report
  uses: ncruces/go-coverage-report@v0
  with:
    coverage-file: coverage.out

@ncruces ncruces closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2024
@ncruces ncruces reopened this Dec 8, 2024
@ncruces
Copy link
Owner

ncruces commented Dec 8, 2024

I missed the working-directory bit. I can look into that, if I can be persuaded that it makes sense.

But really, I want to keep this simple and straightforward. Otherwise, the escape hatch is that you can generate coverage however you want, and this simply does the rest.

E.g. here I use an entirely different tool to generate coverage.

@ncruces
Copy link
Owner

ncruces commented Dec 8, 2024

Ideally there wouldn't be any new configuration parameters.

If I'm not respecting existing GitHub Actions configuration parameters (e.g. that the Go action supports), then that's something I'd really like to fix.

@ncruces
Copy link
Owner

ncruces commented Jan 8, 2025

working-directory does not support uses steps, so this would need to be a new configuration knob, which I'd rather avoid.

You can generate your own coverage in a run step, and then pass the output to the action.

@ncruces ncruces closed this as completed Jan 8, 2025
@ncruces ncruces closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2025
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