简体   繁体   中英

devpi: manually upload toxresult.json

I currently have a Jenkins pipeline which builds and tests my python package using tox . If all unittests pass, it will be uploaded to my local devpi index.

Using devpi test <mypackage> I can attach the test results to the release file on the index. But this will download the already built package again, repeat all of the already passed test suites defined in the tox.ini file and only then upload the results in form of a toxresult.json .

Is there any way to directly upload the toxresult.json alongside the release files? According to the quickstart and the documentation of test command there seems to be no command line option, and neither in the upload command.

Of course I could change my Jenkins pipeline to skip the tests before uploading and then build, upload and test the package using devpi. If the devpi test command fails I can remove the package from the index. But I would rather not upload a package with failing tests in the first place.

The anonymous uploads

It's relatively easy if you allow the anonymous user to upload test results (which is the default setting IIRC). Make a POST request to the URL of the uploaded dist, passing tox results as JSON payload. Example:

$ curl -i \
    -H "content-type: application/json" \
    -X POST \
    --data-binary "@/tmp/toxreport.json" \
    http://my-server/myuser/myindex/+f/19b/d3544d03b1716/mypkg-1.0.tar.gz

On success, you should get a result similar to

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Content-Length: 143
Content-Type: application/json
Date: Wed, 08 Jan 2020 15:48:32 GMT
Server: waitress
X-Devpi-Api-Version: 2
X-Devpi-Master-Uuid: d800735d04a14c2d9bde920149cb8dbc
X-Devpi-Serial: 42
X-Devpi-Server-Version: 5.3.1
X-Devpi-Uuid: d800735d04a14c2d9bde920149cb8dbc

{
  "result": "myuser/myindex/+f/19b/d3544d03b1716/mypkg-1.0.tar.gz.toxresult-20200108154832-0",
  "type": "toxresultpath"
}

You can find the target URL in the File column of the files table on the project page. Or query the JSON API and filter the results, eg

$ devpi getjson /myuser/myindex/mypkg | jq -r '[ .result[] | .["+links"][] | .href ]'

Authenticated uploads

devpi uses basic auth, so simply pass the base64-encoded credentials in the Authorization: Basic header. Example, with curl again:

$ curl -i \
    --user myuser:mypass \
    -H "content-type: application/json" \
    -X POST \
    --data-binary "@/tmp/toxreport.json" \
    http://my-server/myuser/myindex/+f/19b/d3544d03b1716/mypkg-1.0.tar.gz

If you need details on the test upload authentication, check out my other answer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM