Open pixo-wnobrien opened 6 months ago
@pixo-wnobrien hey, sorry for late response. could you read this https://github.com/vladopajic/go-test-coverage/issues/55, and try two options that have been explained here
1) use v2.8.1
version
2) set local prefix for both apps (github.com/org/repo/app1
and github.com/org/repo/app2
)
please let me know if this has resolved your issue.
I'm having a similar issue, with a monorepo containing a single Go module nested a few directories inside. I think the issue is similar to in @pixo-wnobrien's case, github.com/org/repo/app1
and github.com/org/repo/app2
likely have their own separate go.mod
files and aren't discoverable, neither is there a go.work
file present.
Setting local-prefixes
also doesn't seem to solve the issue in my case as the relative path to the module and the module name is not 1:1.
hello gents,
i have started to work on feature that will allow user to set source directory. this feature should allow use of this tool in monorepos. could you please test it out and give me insights?
to test it you can use 028b5bedcf5d71e9e59fcc5ca7219ec772197382
version.
in ci:
- name: check test coverage (app 1)
uses: vladopajic/go-test-coverage@028b5bedcf5d71e9e59fcc5ca7219ec772197382
with:
config: ./.testcoverage_app1.yml
source-dir: ./app1
- name: check test coverage (app 2)
uses: vladopajic/go-test-coverage@028b5bedcf5d71e9e59fcc5ca7219ec772197382
with:
config: ./.testcoverage_app2.yml
source-dir: ./app2
locally:
go install github.com/vladopajic/go-test-coverage/v2@028b5bedcf5d71e9e59fcc5ca7219ec772197382
go-test-coverage -config=./.testcoverage_app1.yml -source-dir=app1
@vladopajic tried with the commit provided, it still doesnt work after providing source-dir also
go.mod file not found in current directory or any parent directory
Same error here, have altered the full output to make it clearer (new lines my own):
failed to generate coverage statistics: could not find file [github.com/org/repo/subdir/module/package/example.go]:
can't find file "github.com/org/repo/subdir/module/package/example.go": no required module provides package github.com/org/repo/subdir/module/package:
go.mod file not found in current directory or any parent directory; see 'go help modules'
In the above, the go.mod
lives in github.com/org/repo/subdir/module
, and the coverage stats generation fails when analysing the cover output of a sub-package of the module (github.com/org/repo/subdir/module/package
).
hello gents,
not sure how do you actually want to setup you repositories. it would require me to see in the details your project setup to understand what is happening.
please feel free to this example https://github.com/vladopajic/monorepo-covrage where coverage check is configured to work with monorepo. would something like this work for you?
@vladopajic The in monorepo-covrage lacks the github-action setup. Please try to set github actions in this repo for both projects and you will see the problem that issue describes.
jobs:
backend-unit-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: proja
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- name: run tests
run: go test -v -cover -coverprofile=test.cover.out ./...
- name: check test coverage
# run go-test-coverage as a go command - this is a workaround I use today
# to make sure go-test-coverage is executed inside proja dir
run: go run github.com/vladopajic/go-test-coverage/v2 -c .testcoverage.yml
# ideal solution would be to pass a working-directory and go-test-coverage
# change the dir and execute the cover change there.
uses: vladopajic/go-test-coverage@v2
with:
config: .testcoverage.yml
working-directory: proja
I have a repo with a couple different projects in it, and I would like to set up a workflow that tests all the projects on a PR. It would be great if I could set the working directory in the step like below:
I usually use golangci-lint in the same pipeline before I run my tests, and the Github Action for that works in this way
I've tried many different workarounds, but I'm having a hard time getting it to work in my repo with multiple projects without this feature. If there are any suggestions that would be greatly appreciated! I put my workflow file below for reference
I can configure the step to use the corresponding
cover.out
file, but since the step is not running in the directory that the tests were run in I get the following error: