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

Input file(s) from glob pattern #98

Open
CraigChamberlain opened this issue Nov 2, 2020 · 4 comments
Open

Input file(s) from glob pattern #98

CraigChamberlain opened this issue Nov 2, 2020 · 4 comments

Comments

@CraigChamberlain
Copy link

CraigChamberlain commented Nov 2, 2020

Imagine you have two or more test projects in a solution.

- root
-- proj1
-- proj1.test
-- proj2
-- proj2.test

Coverlet/ vstest outputs to a guid based directory:

- root
-- proj1
-- proj1.tes
--- TestResults
---- 169afa78-d0cc-4c4d-b011-2139a9197fbd
-- proj2
-- proj2.test
--- TestResults
---- 3102b23b-cae0-45b6-8abe-2d52b0ac36e0

I can upload multiple files in one hit like this:

csmacnz.Coveralls \
  --multiple \
  -i "opencover=$BASEPATH${TEST1}TestResults/3102b23b-cae0-45b6-8abe-2d52b0ac36e0/coverage.opencover.xml;opencover=$BASEPATH${TEST2}TestResults/169afa78-d0cc-4c4d-b011-2139a9197fbd/coverage.opencover.xml" \
  --useRelativePaths --basePath $BASEPATH \
  --commitId 2b47e3dc280fdf2bf8474b3160a5465399cf436b \
  --commitBranch MrOrange

However, the guids change each time I output the coverage report. I still have guids, even if I centralise the files to the project root for example:

dotnet test --results-directory:"$BASEPATH/resDir"

Could -i take a glob parameter?

*/**/coverage.opencover.xml.

Again I may be able to use mv in combination with an index to create files 1coverage.opencover.xml, 2coverage.opencover.xml ect. I would still have to add another clause to my -i argument for every time I added a new test.

- root
--TestResults
-- proj1
-- proj1.test
-- proj2
-- proj2.test

At this stage the best option may be recreating a file structure as such as this with mv so there is no concern about creating unique names.

- root
-- proj1
-- proj1.test
--- TestResults
-- proj2
-- proj2.test
--- TestResults
@CraigChamberlain
Copy link
Author

CraigChamberlain commented Nov 2, 2020

The following workaround achieves what I want it to:

COVERAGEFILES=""
for x in $(find . -path */coverage.opencover.xml); do
    COVERAGEFILES+="opencover=$x;"
done
COVERAGEFILES="$(sed -e 's/;$//' <<< $COVERAGEFILES)"

csmacnz.Coveralls \
  --multiple \
  -i $COVERAGEFILES \
  --useRelativePaths --basePath $BASEPATH \
  --commitId $(git log --format="%H" -n 1) \
  --commitBranch $(git rev-parse --abbrev-ref HEAD)

e.g

echo $COVERAGEFILES
opencover=./proj1.test/TestResults/cb508f99-76a1-466e-b554-d9d8058bf476/coverage.opencover.xml;opencover=./proj2.test/TestResults/b9acf4b3-7a2b-4c76-8a23-b9899a12798e/coverage.opencover.xml;

@csMACnz
Copy link
Owner

csMACnz commented Nov 5, 2020

Something to investigate for sure. I've always had 'fun' with globbing, especially when sometimes it is done by the shell, and sometime by the cli tool... maybe documenting this as an example would be valuable enough to start with.

@CraigChamberlain
Copy link
Author

I think your right, at this stage just having an example like this would probably cover 90% of uses. Most CI's are running bash commands.

By the time this came to the top of the pile it looks like globbing might be supported by .NET
dotnet/runtime#21362

There is some support for recursive seeking to match a pattern in the Directory.GetFiles() api
https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-3.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_SearchOption_

@CraigChamberlain
Copy link
Author

CraigChamberlain commented Nov 5, 2020

Quick and dirty in powershell:

 [System.IO.Directory]::GetFiles($pwd,"coverage.opencover.xml",1)

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