How to release automatically your artifact to GitHub

marocco2's Avatar

marocco2

19 Aug, 2014 03:10 PM

First, on your CI server, after building the artifact, create a tag.

git tag :yourversion

Push your tag to GitHub (I use a token to avoid username and password)

git push https://your_token:@github.com/you/yourrepo.git --tags

Now create a release with cURL. I use a lot of variables, so I want use echo to write the variables then push with a json file

echo Creating release...
echo {"tag_name": "%PLATFORM%_%APPVEYOR_BUILD_VERSION%","target_commitish": "%APPVEYOR_REPO_BRANCH%","name": "2spark v%APPVEYOR_BUILD_VERSION% for %PLATFORM% devices","body": "Release of 2spark app v%APPVEYOR_BUILD_VERSION%\n Commit by %APPVEYOR_REPO_COMMIT_AUTHOR% \n%APPVEYOR_REPO_COMMIT_MESSAGE%","draft": false,"prerelease": true} > json.json
curl -# -XPOST -H 'Content-Type:application/json' -H 'Accept:application/json' --data-binary @json.json https://api.github.com/repos/you/yourrepo/releases?access_token=your_token -o response.json
del json.json

On the response.json there is your id. To find it I use this .bat file http://www.dostips.com/forum/viewtopic.php?f=3&t=4697 and then some variables. YOU MUST COPY ALL CODE TO GET THIS WORKING!

echo Search the release id...
type response.json | findrepl id | findrepl /O:1:1 >> raw_id.txt
del response.json
echo Refining the id...
set /p raw_id_release=<raw_id.txt
set raw_id_release2=%raw_id_release:*"id": =%
set id_release=%raw_id_release2:,=%
echo The ID is %id_release% , yay!
del raw_id.txt

Finally, post your artifact as body message

echo Uploading artifact to Github...
curl -# -XPOST -H "Authorization:token your_token" -H "Content-Type:application/octet-stream" --data-binary @yourbinary.exe https://uploads.github.com/repos/you/yourrepo/releases/%id_release%/assets?name=yourbinary.exe
echo Done. Enjoy your release :)
EXIT

Enjoy your release!

  1. Support Staff 1 Posted by Feodor Fitsner on 19 Aug, 2014 07:31 PM

    Feodor Fitsner's Avatar

    Thanks for the guide! Where do you get cURL command line?

  2. 2 Posted by marocco2 on 19 Aug, 2014 07:37 PM

    marocco2's Avatar

    I browsed around the github API. https://developer.github.com/v3/repos/releases/
    Then I write it in a cURL command, which is not too difficult.
    The hardest part is find the ID, which is on the response, and refining it to get only the numbers (A week spent to discover it D:).
    I hope you can automate these commands on your CI server ✔

  3. Support Staff 3 Posted by Feodor Fitsner on 19 Aug, 2014 07:38 PM

    Feodor Fitsner's Avatar

    Oh, I mean curl.exe utility?

  4. 4 Posted by marocco2 on 19 Aug, 2014 07:42 PM

    marocco2's Avatar

    It's integrated on git package. I tested it on my git shell

  5. Support Staff 5 Posted by Feodor Fitsner on 19 Aug, 2014 07:44 PM

    Feodor Fitsner's Avatar

    I see, great. Thank you!

  6. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:47 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac