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

API returns 500 on uploading data from a custom Github Action #1527

Closed
svetlyak40wt opened this issue Feb 14, 2021 · 13 comments
Closed

API returns 500 on uploading data from a custom Github Action #1527

svetlyak40wt opened this issue Feb 14, 2021 · 13 comments

Comments

@svetlyak40wt
Copy link

Hi! I'm adapting cl-coveralls for using inside a Github Action.

But API responds with 500 error with body:

{"message":"Build processing error.","error":true,"url":""}

on this payload:

{
  "service_name": "github",
  "service_job_id": "564926310",
  "repo_token": "<Secret Coveralls Repo Token>",
  "service_pull_request": 5,
  "git": {
    "head": {
      "id": "57daa8d96184d4c216f537f9f0508dff27a20050",
      "author_name": "Alexander Artemenko",
      "author_email": "[email protected]",
      "committer_name": "GitHub",
      "committer_email": "[email protected]",
      "message": "Merge 56548c9b6bcc8861cc0bfc5f4a9d7899812e2f0f into da0f1d54b5b2ffb262422aabeae1f3270b838b3c"
    },
    "branch": "refs/pull/5/merge"
  },
  "source_files": [
    {
      "name": "t/core.lisp",
      "source_digest": "3408a13ed105e7e6ea241a1f0dde4379",
      "coverage": [
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        null,
        1,
        1,
        null,
        null,
        1,
        1,
        1,
        1
      ]
    },
    {
      "name": "src/core.lisp",
      "source_digest": "08876868206b36023fac48c9d5c0470e",
      "coverage": [
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        null,
        1,
        1,
        1,
        null,
        1,
        1,
        1,
        null,
        1,
        1,
        null,
        1,
        1,
        1,
        null,
        1,
        1,
        null,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        1,
        1,
        null,
        1,
        1,
        1,
        null,
        null,
        1,
        1,
        null,
        1,
        1,
        null,
        1,
        null,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        null,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        null,
        null,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        null,
        null,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        null,
        null,
        1,
        1,
        0,
        null,
        null,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    }
  ]
}

Here is the run: https://github.com/40ants/cl-info/runs/1895864300?check_suite_focus=true

Is there a way to learn the reason why I receive this internal server error?

@svetlyak40wt
Copy link
Author

Here is an action's run info https://api.github.com/repos/40ants/cl-info/actions/runs/564926310. I pass id "564926310" in the payload as "service_job_id". This is the similar to what official Coveralls Github Action does.

@afinetooth
Copy link
Collaborator

afinetooth commented Feb 15, 2021

Hi @svetlyak40wt , with Github Actions, instead of passing the coveralls repo token, like:

"repo_token": "<Secret Coveralls Repo Token>"

You need to pass the secret github token, like:

"repo_token": ${{ secrets.GITHUB_TOKEN }}

If you want to use the official Coveralls Github Action, you'll need to pass that as github-token, like:

github-token: ${{ secrets.GITHUB_TOKEN }}

Please try that and let me know if you encounter further issues / new errors.

@svetlyak40wt
Copy link
Author

@afinetooth I know and use GITHUB_TOKEN: https://github.com/40ants/cl-info/blob/add-linter/.github/workflows/ci.yml#L91-L95

When I tried to use Coveralls token, I've received 422 error saying it is unable to find a repository.

I belive, this 500 is different than that 422.

@afinetooth
Copy link
Collaborator

afinetooth commented Feb 16, 2021

Hi @svetlyak40wt the file at the link you provided:
https://github.com/40ants/cl-info/blob/add-linter/.github/workflows/ci.yml#L91-L95

is actually passing the key coveralls-token in the ci.yml per:

      - uses: 40ants/run-tests@v2-betaAlexander Artemenko, 3 days ago: • Deleted docs system and moved to a run-tests/…
        with:Alexander Artemenko, 14 days ago: • Now with custom code.
          asdf-system: cl-infoAlexander Artemenko, 14 days ago: • Custom tests runner.
          coveralls-token: ${{ secrets.github_token }}Alexander Artemenko, 3 days ago: • Use github token as coveralls token.

We are looking for this format of incoming JSON:

{
  "repo_token": "v1.asdfasdf",
  "service_name": "github",
  "service_job_id": "asdfasdf",
  "source_files": [
    {
      "name": "example.rb",
      "source": "def four\n  4\nend",
      "coverage": [null, 1, null]
    },
    {
      "name": "two.rb",
      "source": "def seven\n  eight\n  nine\nend",
      "coverage": [null, 1, 0, 1, null]
    }
  ],
  "environment": {
    "branch": "test"
  },
  "git": {
    "branch": "refs/head/master\n",
    "head": {
      "id": "asdfasdf",
      "message": "a commit!",
      "author_name": "Nick Merwin",
      "committer_name": "Nick Merwin",
      "committer_email": "[email protected]"
    }
  }
}

So you'll want to use the key repo_token.

Again, that's if you're rolling your own Github Action.

If you're using our action you can use github-token. Our action replaces that key with repo_token in the incoming JSON, per our API Reference.

Sorry if I misunderstand something here, but I can confirm that coveralls-token won't work and is probably what's causing the 500 error.

You're right that the 500 error is different from the 422 you'll get if you're using the right key (repo_token) but passing the wrong value.

For good measure, try these two options, in order, in your ci.yml:

repo_token: ${{ secrets.GITHUB_TOKEN }}

Then:

github-token: ${{ secrets.GITHUB_TOKEN }}

The first should work. I suspect the second will also throw a 500 error.

@svetlyak40wt
Copy link
Author

@afinetooth you are misunderstand.

I'm working on my own action. It:

  1. Accepts github token as input with name coveralls-token:
    with:
           asdf-system: cl-info
           coveralls-token: ${{ secrets.github_token }}
    
  2. Pay attention, I'm passing the github_token as a value.
  3. Internally, this coveralls-token input variable is set as COVERALLS_REPO_TOKEN env variable.
  4. Utility which runs unittests, generates a coverage report and uses COVERALLS_REPO_TOKEN env variable as the value for repo_token key when sending HTTP request to Coveralls API.
  5. Remember, I'm putting secrets.github_token there on step 1?

That is it in the JSON I'm sending the report, repo_token contains github token. In my original issue's text:

{
  "service_name": "github",
  "service_job_id": "564926310",
  "repo_token": "<Secret Coveralls Repo Token>",
  "service_pull_request": 5,
  "git": {
    "head": {
      "id": "57daa8d96184d4c216f537f9f0508dff27a20050",
      "author_name": "Alexander Artemenko",
      "author_email": "[email protected]",
      "committer_name": "GitHub",
      "committer_email": "[email protected]",
      "message": "Merge 56548c9b6bcc8861cc0bfc5f4a9d7899812e2f0f into da0f1d54b5b2ffb262422aabeae1f3270b838b3c"
    },
    "branch": "refs/pull/5/merge"
  },
  "source_files": [
    {
      "name": "t/core.lisp",
      "source_digest": "3408a13ed105e7e6ea241a1f0dde4379",

Secret Coveralls Repo Token is a Github Token.

Can we trace this 500 error in coveralls logs? Maybe it returns some sort of request-id HTTP header, which can be used to grep your logs?

@svetlyak40wt
Copy link
Author

svetlyak40wt commented Feb 16, 2021

@afinetooth I've reproduced error again. This time with printing response headers:

(("cf-ray" . "622aba93d905e774-EWR") ("server" . "cloudflare")
   ("nel" . "{\"report_to\":\"cf-nel\",\"max_age\":604800}")
   ("expect-ct"
    . "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"")
   ("cf-request-id" . "084e92f0780000e774fe905000000001")
   ("cf-cache-status" . "DYNAMIC") ("x-xss-protection" . "1; mode=block")
   ("x-runtime" . "0.350985")
   ("x-request-id" . "f2e1dec5-9395-4607-a663-cf00174b1586")
   ("x-powered-by" . "Phusion Passenger Enterprise 5.3.7")
   ("x-frame-options" . "SAMEORIGIN") ("x-content-type-options" . "nosniff")
   ("strict-transport-security" . "max-age=15552000")
   ("status" . "500 Internal Server Error") ("cache-control" . "no-cache")
   ("connection" . "keep-alive") ("content-length" . "59")
   ("content-type" . "application/json; charset=utf-8")
   ("date" . "Tue, 16 Feb 2021 22:33:11 GMT"))

Here is the body of the request:

{"service_name":"github","service_job_id":"564926310","repo_token":"v1.b***********************************4300","service_pull_request":5,"git":{"head":{"id":"57daa8d96184d4c216f537f9f0508dff27a20050","author_name":"Alexander Artemenko","author_email":"[email protected]","committer_name":"GitHub","committer_email":"[email protected]","message":"Merge 56548c9b6bcc8861cc0bfc5f4a9d7899812e2f0f into da0f1d54b5b2ffb262422aabeae1f3270b838b3c"},"branch":"refs/pull/5/merge"},"source_files":[{"name":"t/core.lisp","source_digest":"3408a13ed105e7e6ea241a1f0dde4379","coverage":[1,1,1,1,1,1,1,1,1,1,null,null,1,1,null,null,1,1,1,1]},{"name":"src/core.lisp","source_digest":"08876868206b36023fac48c9d5c0470e","coverage":[1,1,1,1,1,1,1,1,1,1,null,null,1,1,1,null,1,1,1,null,1,1,null,1,1,1,null,1,1,null,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,null,1,1,null,1,1,1,null,null,1,1,null,1,1,null,1,null,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,null,1,1,1,1,1,1,1,1,1,1,null,null,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,null,null,null,null,null,null,null,1,1,1,1,1,1,1,1,1,1,null,null,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,null,null,1,0,0,0,0,0,0,0,0,0,0,null,null,1,1,0,null,null,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]}

Probably, x-request-id = "f2e1dec5-9395-4607-a663-cf00174b1586" can be used to find this error in your logs?

@afinetooth
Copy link
Collaborator

afinetooth commented Feb 17, 2021

@svetlyak40wt Thanks for the requestID. I was able to look this up in our production error tracking system.

First of all, your request JSON looks valid:

{
	"service_name": "github",
	"service_job_id": "564926310",
	"repo_token": "v1.b***********************************4300",
	"service_pull_request": 5,
	"git": {
		"head": {
			"id": "57daa8d96184d4c216f537f9f0508dff27a20050",
			"author_name": "Alexander Artemenko",
			"author_email": "[email protected]",
			"committer_name": "GitHub",
			"committer_email": "[email protected]",
			"message": "Merge 56548c9b6bcc8861cc0bfc5f4a9d7899812e2f0f into da0f1d54b5b2ffb262422aabeae1f3270b838b3c"
		},
		"branch": "refs/pull/5/merge"
	},
	"source_files": [{
		"name": "t/core.lisp",
		"source_digest": "3408a13ed105e7e6ea241a1f0dde4379",
		"coverage": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, null, 1, 1, null, null, 1, 1, 1, 1]
	}, {
		"name": "src/core.lisp",
		"source_digest": "08876868206b36023fac48c9d5c0470e",
		"coverage": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, null, 1, 1, 1, null, 1, 1, 1, null, 1, 1, null, 1, 1, 1, null, 1, 1, null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, 1, 1, null, 1, 1, 1, null, null, 1, 1, null, 1, 1, null, 1, null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, null, null, null, null, null, null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null, null, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null, null, 1, 1, 0, null, null, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	}]
}

But an error did occur and the top of the stacktrace is as follows:

app/models/build.rb:233:in `[]': wrong number of arguments (given 2, expected 1) (ArgumentError)
    from app/models/build.rb:233:in `apply_api_params'
    from app/models/job.rb:289:in `attach_to_build'
    from app/models/job.rb:114:in `from_api'
    from app/controllers/api_controller.rb:22:in `jobs'
    from gems/actionpack-5.0.7.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
    [...]

The issue is that the line cited is expecting a string:

pr = (params['service_pull_request'] || '')[/\d+/,0].to_i

But your service_pull_request param is passing an integer:

  [...]
  "service_pull_request": 5,
  [...]

Per the API Reference for service_pull_request:

Screen Shot 2021-02-17 at 11 56 08 AM

We should be throwing a more useful error there, but please change the data type and see if that works.

@svetlyak40wt
Copy link
Author

@afinetooth thank you for the detailed response. I've fixed cl-coveralls and now it works!

Here is my first successful build results: https://coveralls.io/builds/37113655

@svetlyak40wt
Copy link
Author

By the way,

  • cl-info is a library for which I want to build a report.
  • cl-coveralls is a library to collect coverage report and to push it to coveralls. Previously it worked for Travis and CircleCI, and now it will support GH Actions!
  • run-tests is an action which is able to run tests for any Common Lisp library and it uses cl-coverage library to upload reports. In this sense, it is similar to official https://github.com/coverallsapp/github-action, but also can run a testsuite.

@afinetooth
Copy link
Collaborator

afinetooth commented Feb 17, 2021

@svetlyak40wt great! Glad to hear it.

Thanks for the background!

We don't have cl-coveralls in our list of language integrations. Do you think we should add it under Lisp here?

Or do you think run-tests would be the more appropriate resource? Or a combination? Please feel free to suggest some copy. I'd be happy to add it to our site.

And thanks for adding Github Actions support to the library.

@svetlyak40wt
Copy link
Author

svetlyak40wt commented Feb 18, 2021

@afinetooth it would be nice to add both to the Lisp integrations page!

Please, use this text:

This library can collect and publish coverage reports
for Common Lisp code:
<a href="https://github.com/fukamachi/cl-coverall">fukamachi/cl-coverall</a>


And this is a GitHub Action, which automates test running and
coverage report publishing:
<a href="https://40ants.com/run-tests/">40ants/run-tests</a>

@afinetooth
Copy link
Collaborator

Great, @svetlyak40wt, thank you!

It's now up at:
https://docs.coveralls.io/lisp

@stale
Copy link

stale bot commented Jun 4, 2022

This issue has been automatically marked for closure because it has not had recent activity. It will be closed if no further activity occurs. If your issue is still active please add a comment and we’ll review as soon as we can. Thank you for your contributions.

@stale stale bot closed this as completed Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants