Search code examples
gitgithubgithub-api

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


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

curl -X POST -H "Authorization: token xxxxxxxxx"  -d '{"tag_name": "test", "name":"release-0.0.1","body":"this is a test release"}'  https://api.github.com/repos/xxxxxx

I can see that a new release is created. But there are two download buttons under it:

Source code (zip)
Source code (tar.gz)

How can I make a release without source code?

If I can't remove the source code attachment, how can I upload additional binary files? I tried to use the API Upload a release asset like this: POST https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name=foo.zip, it returns successfully but I couldn't find the binaries on Github release tab.


Solution

  • 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"