ashley-taylor / junit-report-annotations-action

Create an annotation of the build information and also list first n failed tests as seporate annotations
12 stars 29 forks source link

Allow non-"build" name #3

Open MPV opened 4 years ago

MPV commented 4 years ago

I ran into this when trying out this action:

Run ashley-taylor/junit-report-annotations-action@v1.0
  with:
    access-token: ***
    path: target/surefire-reports/*.xml
    includeSummary: true
    numFailures: 10
    testSrcPath: src/test/java/
  env:
    GITHUB_TOKEN: ***
    JAVA_HOME: /runner/.jabba/jdk/adopt@1.8.0-252
##[error]Cannot read property 'id' of undefined
Skärmavbild 2020-05-28 kl  12 15 34

Looking at the code of this action, could it be because it assumes the "check" is expected to be named "build"?

const check_run_id = res.data.check_runs.filter(check => check.name === 'build')[0].id

https://github.com/ashley-taylor/junit-report-annotations-action/blob/master/index.js#L88

ashley-taylor commented 4 years ago

have made a new version ashley-taylor/junit-report-annotations-action@v1.1 It reads the job id from an env variable no longer hard coded.

If it still does not work would you mind doing one run using @master as the version? It should output some debug info so I will be able to understand why its not working. If you could update this ticket with that output would be great.

MPV commented 4 years ago

Indeed 1.2 isn't there yet:

Current runner version: '2.263.0'
Prepare workflow directory
Prepare all required actions
Download action repository 'actions/checkout@v2'
Download action repository 'olafurpg/setup-scala@v5'
Download action repository 'actions/cache@v1'
Download action repository 'ashley-taylor/junit-report-annotations-action@v1.1'
##[error]An action could not be found at the URI 'https://api.github.com/repos/ashley-taylor/junit-report-annotations-action/tarball/v1.1'

So I tried with @master, there I'm getting:

Run ashley-taylor/junit-report-annotations-action@master
  with:
    access-token: ***
    path: target/surefire-reports/*.xml
    includeSummary: true
    numFailures: 10
    testSrcPath: src/test/java/
  env:
    GITHUB_TOKEN: ***
    JAVA_HOME: /runner/.jabba/jdk/adopt@1.8.0-252
{
    "ACTIONS_CACHE_URL": "https://artifactcache.actions.githubusercontent.com/JXFXmkDTLNA9dlq4VskGeHLtjNSJaOGpucslM47meKA7vFGXPd/"
    "ACTIONS_RUNTIME_TOKEN":***,
    "ACTIONS_RUNTIME_URL": "https://pipelines.actions.githubusercontent.com/JXFXmkDTLNA9dlq4VskGeHLtjNSJaOGpucslM47meKA7vFGXPd/",
    "CI": "true",
    "DEBIAN_FRONTEND": "noninteractive",
    "DOCKER_HOST": "tcp://localhost:2375",
    "DOCKER_IP": "172.17.0.1",
    "DOCKER_REGISTRY": "REDACTED",
    "GH_ORG": "REDACTED",
    "GH_TOKEN": "REDACTED",
    "GITHUB_ACTION": "ashley-taylorjunit-report-annotations-action",
    "GITHUB_ACTIONS": "true",
    "GITHUB_ACTOR": "MPV",
    "GITHUB_BASE_REF": "master",
    "GITHUB_EVENT_NAME": "pull_request",
    "GITHUB_EVENT_PATH": "/runner/_work/_temp/_github_workflow/event.json",
    "GITHUB_HEAD_REF": "github-actions-self-hosted-junit-annotations",
    "GITHUB_JOB": "build",
    "GITHUB_REF": "refs/pull/26/merge",
    "GITHUB_REPOSITORY": "REDACTED",
    "GITHUB_REPOSITORY_OWNER": "REDACTED",
    "GITHUB_RUN_ID": "118731344",
    "GITHUB_RUN_NUMBER": "35",
    "GITHUB_SHA": "REDACTED",
    "GITHUB_TOKEN": "***",
    "GITHUB_WORKFLOW": "Continuous Integration",
    "GITHUB_WORKSPACE": "/runner/_work/example-service/example-service",
    "HOME": "/runner",
    "HOSTNAME": "runner-pod-REDACTED",
    "INPUT_ACCESS-TOKEN": "***",
    "INPUT_INCLUDESUMMARY": "true",
    "INPUT_NUMFAILURES": "10",
    "INPUT_PATH": "target/surefire-reports/*.xml",
    "INPUT_TESTSRCPATH": "src/test/java/",
    "JAVA_HOME": "/runner/.jabba/jdk/adopt@1.8.0-252",
    "KUBERNETES_PORT": "tcp://10.66.64.1:443",
    "KUBERNETES_PORT_443_TCP": "tcp://10.66.64.1:443",
    "KUBERNETES_PORT_443_TCP_ADDR": "10.66.64.1",
    "KUBERNETES_PORT_443_TCP_PORT": "443",
    "KUBERNETES_PORT_443_TCP_PROTO": "tcp",
    "KUBERNETES_SERVICE_HOST": "10.66.64.1",
    "KUBERNETES_SERVICE_PORT": "443",
    "KUBERNETES_SERVICE_PORT_HTTPS": "443",
    "LANG": "C.UTF-8",
    "PATH": "/runner/bin:/runner/.jabba/jdk/adopt@1.8.0-252/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "PWD": "/runner",
    "RUNNER_DEBUG": "true",
    "RUNNER_LABELS": "gke",
    "RUNNER_OS": "Linux",
    "RUNNER_TEMP": "/runner/_work/_temp",
    "RUNNER_TOOL_CACHE": "/runner/_work/_tool",
    "RUNNER_TRACKING_ID": "github_a34ff831-ff44-4a5e-b061-868977041afa",
    "RUNNER_WORKSPACE": "/runner/_work/example-service",
    "SHLVL": "1",
    "_": "/runner/bin/Runner.Listener",
}
[]
##[error]Cannot read property 'id' of undefined
MPV commented 4 years ago

Could it be that what you get in GITHUB_JOB isn't a name, but an ID?

I'm thinking that the code might be currently comparing these two?

jobs.<job_id> vs jobs.<job_id>.name

MPV commented 4 years ago

Although, I'm not sure why there wasn't any output logged from:

console.log(JSON.stringify(res.data.check_runs))

(as you see from the next-to-last line logged with [] above)

ashley-taylor commented 4 years ago

Think I can see the cause. Is because is a pull request. Not just a push. Will have a look later.

MPV commented 4 years ago

Ah, nice find!

I'll give this a try too:

Skärmavbild 2020-05-29 kl  16 12 57
MPV commented 4 years ago

Not much better at first glance, I'm afraid:

Skärmavbild 2020-05-29 kl  16 15 56 Skärmavbild 2020-05-29 kl  16 16 22

Need to break for week-end, but I'll try to get back with debug details too, likely next week at earliest though.

MPV commented 4 years ago

@ashley-taylor Here's when I ran this on push (from my last comment above):

[
    {
        "id": 720625993,
        "node_id": "MDg6Q2hlY2tSdW43MjA2MjU5OTM=",
        "head_sha": "129bd843e23bbf9289e88ba6a018be9ce36b09e9",
        "external_id": "cfc9dbcb-a267-518e-5867-d1492fc1c90e",
        "url": "https://api.github.com/repos/my-org/example-service/check-runs/720625993",
        "html_url": "https://github.com/my-org/example-service/runs/720625993",
        "details_url": "https://github.com/my-org/example-service/runs/720625993",
        "status": "completed",
        "conclusion": "success",
        "started_at": "2020-05-29T14:12:18Z",
        "completed_at": "2020-05-29T14:12:19Z",
        "output": {
            "title": null,
            "summary": null,
            "text": null,
            "annotations_count": 0,
            "annotations_url": "https://api.github.com/repos/my-org/example-service/check-runs/720625993/annotations"
        },
        "name": "Delete Artifacts",
        "check_suite": {
            "id": 733437370
        },
        "app": {
            "id": 15368,
            "slug": "github-actions",
            "node_id": "MDM6QXBwMTUzNjg=",
            "owner": {
                "login": "github",
                "id": 9919,
                "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
                "avatar_url": "https://avatars1.githubusercontent.com/u/9919?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/github",
                "html_url": "https://github.com/github",
                "followers_url": "https://api.github.com/users/github/followers",
                "following_url": "https://api.github.com/users/github/following{/other_user}",
                "gists_url": "https://api.github.com/users/github/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/github/subscriptions",
                "organizations_url": "https://api.github.com/users/github/orgs",
                "repos_url": "https://api.github.com/users/github/repos",
                "events_url": "https://api.github.com/users/github/events{/privacy}",
                "received_events_url": "https://api.github.com/users/github/received_events",
                "type": "Organization",
                "site_admin": false
            },
            "name": "GitHub Actions",
            "description": "Automate your workflow from idea to production",
            "external_url": "https://help.github.com/en/actions",
            "html_url": "https://github.com/apps/github-actions",
            "created_at": "2018-07-30T09:30:17Z",
            "updated_at": "2019-12-10T19:04:12Z",
            "permissions": {
                "actions": "write",
                "checks": "write",
                "contents": "write",
                "deployments": "write",
                "issues": "write",
                "metadata": "read",
                "packages": "write",
                "pages": "write",
                "pull_requests": "write",
                "repository_hooks": "write",
                "repository_projects": "write",
                "security_events": "write",
                "statuses": "write",
                "vulnerability_alerts": "read"
            },
            "events": [
                "check_run",
                "check_suite",
                "create",
                "delete",
                "deployment",
                "deployment_status",
                "fork",
                "gollum",
                "issues",
                "issue_comment",
                "label",
                "milestone",
                "page_build",
                "project",
                "project_card",
                "project_column",
                "public",
                "pull_request",
                "pull_request_review",
                "pull_request_review_comment",
                "push",
                "registry_package",
                "release",
                "repository",
                "repository_dispatch",
                "status",
                "watch"
            ]
        },
        "pull_requests": [
            {
                "url": "https://api.github.com/repos/my-org/example-service/pulls/26",
                "id": 424923173,
                "number": 26,
                "head": {
                    "ref": "github-actions-self-hosted-junit-annotations",
                    "sha": "129bd843e23bbf9289e88ba6a018be9ce36b09e9",
                    "repo": {
                        "id": 215329298,
                        "url": "https://api.github.com/repos/my-org/example-service",
                        "name": "example-service"
                    }
                },
                "base": {
                    "ref": "master",
                    "sha": "62af8ed9862efe1979b8e075128c6f84b86ff3ff",
                    "repo": {
                        "id": 215329298,
                        "url": "https://api.github.com/repos/my-org/example-service",
                        "name": "example-service"
                    }
                }
            }
        ]
    },
    {
        "id": 720625955,
        "node_id": "MDg6Q2hlY2tSdW43MjA2MjU5NTU=",
        "head_sha": "129bd843e23bbf9289e88ba6a018be9ce36b09e9",
        "external_id": "87183d11-15b6-51be-c26d-2b47679083ca",
        "url": "https://api.github.com/repos/my-org/example-service/check-runs/720625955",
        "html_url": "https://github.com/my-org/example-service/runs/720625955",
        "details_url": "https://github.com/my-org/example-service/runs/720625955",
        "status": "in_progress",
        "conclusion": null,
        "started_at": "2020-05-29T14:12:15Z",
        "completed_at": null,
        "output": {
            "title": null,
            "summary": null,
            "text": null,
            "annotations_count": 0,
            "annotations_url": "https://api.github.com/repos/my-org/example-service/check-runs/720625955/annotations"
        },
        "name": "Build and Test (self-hosted, 2.13.2, adopt@1.8)",
        "check_suite": {
            "id": 733437335
        },
        "app": {
            "id": 15368,
            "slug": "github-actions",
            "node_id": "MDM6QXBwMTUzNjg=",
            "owner": {
                "login": "github",
                "id": 9919,
                "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
                "avatar_url": "https://avatars1.githubusercontent.com/u/9919?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/github",
                "html_url": "https://github.com/github",
                "followers_url": "https://api.github.com/users/github/followers",
                "following_url": "https://api.github.com/users/github/following{/other_user}",
                "gists_url": "https://api.github.com/users/github/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/github/subscriptions",
                "organizations_url": "https://api.github.com/users/github/orgs",
                "repos_url": "https://api.github.com/users/github/repos",
                "events_url": "https://api.github.com/users/github/events{/privacy}",
                "received_events_url": "https://api.github.com/users/github/received_events",
                "type": "Organization",
                "site_admin": false
            },
            "name": "GitHub Actions",
            "description": "Automate your workflow from idea to production",
            "external_url": "https://help.github.com/en/actions",
            "html_url": "https://github.com/apps/github-actions",
            "created_at": "2018-07-30T09:30:17Z",
            "updated_at": "2019-12-10T19:04:12Z",
            "permissions": {
                "actions": "write",
                "checks": "write",
                "contents": "write",
                "deployments": "write",
                "issues": "write",
                "metadata": "read",
                "packages": "write",
                "pages": "write",
                "pull_requests": "write",
                "repository_hooks": "write",
                "repository_projects": "write",
                "security_events": "write",
                "statuses": "write",
                "vulnerability_alerts": "read"
            },
            "events": [
                "check_run",
                "check_suite",
                "create",
                "delete",
                "deployment",
                "deployment_status",
                "fork",
                "gollum",
                "issues",
                "issue_comment",
                "label",
                "milestone",
                "page_build",
                "project",
                "project_card",
                "project_column",
                "public",
                "pull_request",
                "pull_request_review",
                "pull_request_review_comment",
                "push",
                "registry_package",
                "release",
                "repository",
                "repository_dispatch",
                "status",
                "watch"
            ]
        },
        "pull_requests": []
    }
]
MPV commented 4 years ago

Does that give any ideas on what the problem is?

ashley-taylor commented 4 years ago

I have not forgotten about this. I have enough info to recreate is just not as straight forward as I was hoping. Need to call different endpoints depending on what type of job it is.

moul commented 4 years ago

another example here -> https://github.com/berty/berty/pull/2102/checks?check_run_id=795436874

ashley-taylor commented 4 years ago

can you try the latest version 1.2 When a PR comes in from a remote branch is some limits about what is allowed via the API. On a failure build can log the warning to the console in a particular format that get picked up as annotations. On a successful build from a remote branch can not log a notice annotation so currently log nothing. Will give the summary on success if it has API access. So local commits and pull should hopefully get the summary

ashley-taylor commented 4 years ago

have changed how these report back to github. Could you try switch the version of this plugin to @master and run it and tell me if it fixes your issue. Please don't leave it on the @master version If so will build a release with the change.

jmosul commented 4 years ago

@ashley-taylor we're just tried @master on our builds and it worked fine for our PHPUnit tests.

Thanks for fixing!