How do I use the Github Release API for a no-source release?

I use blow command to publish the release to the Github repository:

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 see that a new release is being created. But underneath there are two download buttons:

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

      

How can I make a release without source code?

If I cannot remove the source code embed, how can I download additional binaries? 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 in the Github release tab.

+6


source to share


3 answers


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

  • build a release with POST /repos/:username/:repo/releases

    and save the field upload_url

    from the response
  • load your asset using POST $upload_url

    with additional parameters name

    and optional label

    (see this one )


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"

      

+6


source


I don't think you can according to the community. However, you can attach small files to the release. I believe this is how GitHub works since it is geared towards code viewing and providing the source is an important part.



+2


source


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

Add lines like:

src export-ignore

      

to exclude the "src" directory from part of the generated source package. Internally, github uses a "git archive" to create packages based on tags, and the "git archive" can be managed with ".gitattributes".

I don't know if you can avoid generating the source package entirely - but this is at least a workaround to control the contents of the source package

0


source







All Articles