How to use Github Release API to make a release without source code?

后端 未结 3 547
栀梦
栀梦 2021-01-11 15:06

I am using blow command to publish a release on Github repo:

curl -X POST -H \"Authorization: token xxxxxxxxx\"  -d \'{\"tag_name\": \"test\", \"name\":\"rel         


        
相关标签:
3条回答
  • 2021-01-11 15:26

    You can control the contents of sorcecode archive within automatic generation using the .gitattributes file (and make it part of your repository).

    Add lines like:

    src export-ignore
    

    to exclude the directory "src" from being part of the generated source package. Internally github uses "git archive" to create packages based on the tags - and "git archive" can be controlled via ".gitattributes".

    Don't know whether you can avoid generating the source package completely - but this is at least a workaround to control the contents of the source code package

    0 讨论(0)
  • 2021-01-11 15:33

    I don't think you can on the community version. You can attach small binaries to the release though. I believe this is the way that GitHub works, as it is oriented around browsing the code, and providing the source is the important part.

    0 讨论(0)
  • 2021-01-11 15:38

    To create a new release and upload additional binaries, you can :

    • create the release using POST /repos/:username/:repo/releases and store the upload_url field from the response
    • upload your asset using POST $upload_url with additional parameters name and optional label (refer to this)

    A quick example using bash, curl and jq (JSON parser) :

    #!/bin/bash
    
    token=YOUR_TOKEN
    repo=username/your-repo
    
    upload_url=$(curl -s -H "Authorization: token $token"  \
         -d '{"tag_name": "test", "name":"release-0.0.1","body":"this is a test release"}'  \
         "https://api.github.com/repos/$repo/releases" | jq -r '.upload_url')
    
    upload_url="${upload_url%\{*}"
    
    echo "uploading asset to release to url : $upload_url"
    
    curl -s -H "Authorization: token $token"  \
            -H "Content-Type: application/zip" \
            --data-binary @test.zip  \
            "$upload_url?name=test.zip&label=some-binary.zip"
    
    0 讨论(0)
提交回复
热议问题