Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release automatically your artifact to GitHub

I built a batch file to make Github releases from my CI server on AppVeyor. Everything works fine except when I try to upload my asset to Github. My skills don't help me very much. Is there a method to get my release id from cURL commands to use it on upload assets URL? Thanks very much :)

EDIT: I use 3 batch files:

AppveyorBuildReleases.bat

git tag %PLATFORM%_%APPVEYOR_BUILD_VERSION% 
git push https://token_here:@github.com/2spark/SparklrWP.git --tags
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/2spark/SparklrWP/releases?access_token=token_here 
del json.json
move c:\projects\SparklrWP\SparklrForWindowsPhone\SparklrForWindowsPhone\Bin\%PLATFORM%\%CONFIGURATION%\SparklrForWindowsPhone_%CONFIGURATION%_%PLATFORM%.xap c:\projects\SparklrWP
rename c:\projects\SparklrWP\SparklrForWindowsPhone_%CONFIGURATION%_%PLATFORM%.xap SparklrForWindowsPhone.xap
file_size.bat "c:\projects\SparklrWP\SparklrForWindowsPhone.xap"

file_size.bat

set size=%~z1
AppVeyorBuildReleases2.bat

AppVeyorBuildReleases2.bat

curl -XPOST -H "Authorization:token token_here" -H "Content-Type:application/octet-stream" -H "Content-Length:%size%" --data-binary @SparklrForWindowsPhone.xap https://uploads.github.com/repos/2spark/SparklrWP/releases/TheIDgoesHERE/assets?name=SparklrForWindowsPhone.xap
EXIT

But I don't know how to find the id. Can you help me please? :)

like image 871
Marocco2 Avatar asked Aug 17 '14 12:08

Marocco2


1 Answers

Self-answered question. It was really hard to find a good way to search the id, but now it's working! :D

How to release automatically your artifact to GitHub

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!

like image 93
2 revs Avatar answered Sep 22 '22 02:09

2 revs