Skip to content

ci: upload junit formatted test results#5271

Merged
estesp merged 1 commit intocontainerd:masterfrom
cpuguy83:ci_output_junit
Apr 15, 2021
Merged

ci: upload junit formatted test results#5271
estesp merged 1 commit intocontainerd:masterfrom
cpuguy83:ci_output_junit

Conversation

@cpuguy83
Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 commented Mar 25, 2021

ci: upload junit formatted test results

This allows us to dig more details out of test runs and maintain a
better history.

For this we can use gotestsum, which is a utility that wraps go test
so that it outputs test2json (go's format) and output junit (a format
more easily imported into other systems).

The PR makes it possible to override the Makefile's use of go test to
use any other command tto execute the test. For CI we'll use gotestsum --, where gotestsum expects everything after the -- to be flags for
go test.
We then use environment variables to configure gotestsum (e.g.
GOTESTSUM_JUNITFILE is an env var accepted by gotestsum).

For cri tests, the test suite supports outputing test results to a
directory, these are in junit format already. The file is not named
properly just because the code that creates it (in ginkgo) is not
configured well. We can fix that upstream to give us a better name...
until then I'm keeping those results in a separate dir.

A second workflow is also added so the test results can be summed up and
a report added to the workflow run. The 2nd workflow is required for
this since PR runs do not have access to do some of this due to safety
reasons
(https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

@k8s-ci-robot
Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@cpuguy83 cpuguy83 force-pushed the ci_output_junit branch 5 times, most recently from 0158ab2 to fadb365 Compare March 25, 2021 21:18
@cpuguy83 cpuguy83 marked this pull request as ready for review March 25, 2021 21:59
@cpuguy83 cpuguy83 force-pushed the ci_output_junit branch 4 times, most recently from c51aec8 to 096ed25 Compare March 26, 2021 22:54
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 26, 2021

Build succeeded.

@cpuguy83
Copy link
Copy Markdown
Member Author

This should be ready... I don't actually know how test result parser workflow will work out since it won't run until it is merged.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 27, 2021

Build succeeded.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 31, 2021

Build succeeded.

This allows us to dig more details out of test runs and maintain a
better history.

For this we can use `gotestsum`, which is a utility that wraps `go test`
so that it outputs test2json (go's format) and output junit (a format
more easily imported into other systems).

The PR makes it possible to override the Makefile's use of `go test` to
use any other command tto executet the test. For CI we'll use `gotestsum
--`, where `gotestsum` expects everything after the `--` to be flags for
`go test`.
We then use environment variables to configure `gotestsum` (e.g.
`GOTESTSUM_JUNITFILE` is an env var accepted by `gotestsum`).

For cri tests, the test suite supports outputing test results to a
directory, these are in junit format already. The file is not named
properly just because the code that creates it (in ginkgo) is not
configured well. We can fix that upstream to give us a better name...
until then I'm keeping those results in a separate dir.

A second workflow is also added so the test results can be summed up and
a report added to the workflow run. The 2nd workflow is required for
this since PR runs do not have access to do some of this due to safety
reasons
(https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 requested review from dims, kzys and mxpv and removed request for dims March 31, 2021 17:01
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Mar 31, 2021

Build succeeded.

@cpuguy83 cpuguy83 requested a review from mikebrow March 31, 2021 17:41
@kzys
Copy link
Copy Markdown
Member

kzys commented Mar 31, 2021

How can I access the result?

@cpuguy83
Copy link
Copy Markdown
Member Author

cpuguy83 commented Mar 31, 2021

Under "checks"

image

Artifacts:

image

And then there's the new workflow which should be triggered after the CI workflow runs that would post the results as another check... and optionally a PR comment.

Comment on lines +21 to +43
script: |
var fs = require('fs');
var path = require('path');
var artifacts_path = path.join('${{github.workspace}}', 'artifacts')
fs.mkdirSync(artifacts_path, { recursive: true })

var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});

for (const artifact of artifacts.data.artifacts) {
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
var artifact_path = path.join(artifacts_path, `${artifact.name}.zip`)
fs.writeFileSync(artifact_path, Buffer.from(download.data));
console.log(`Downloaded ${artifact_path}`);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have that as a standalone file instead of inlining in YAML?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we cannot checkout code in this workflow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also to be fair, I have no idea if this will work and no good way to test it here because the workflow won't run until its merged :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It might be better to package that as our own GitHub actions, in future.

@thaJeztah
Copy link
Copy Markdown
Member

@estesp PTAL (as you were working on collecting data from CI)

# See the License for the specific language governing permissions and
# limitations under the License.

GO111MODULE=on go install gotest.tools/gotestsum@v1.6.2 No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit.. missing new line...

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp estesp merged commit 6ef0d38 into containerd:master Apr 15, 2021
@cpuguy83 cpuguy83 deleted the ci_output_junit branch April 15, 2021 19:04
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

Successfully merging this pull request may close these issues.

7 participants