How to automatically release your artifact on 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 really help me. Is there a way to get my release identifier from cURL commands to use it when loading resource urls? Thank you 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 do not know how to find the identifier. Could you help me?:)

+6
source share
1 answer

The answer to the question. It was very difficult to find a good way to search for an identifier, but now it works !: D

How to automatically release your artifact on GitHub

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

 git tag :yourversion 

Click the tag on GitHub (I use a token to avoid username and password)

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

Now create the cURL release. I use a lot of variables, so I want to use echo to write variables, and then click using 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 

There is your identifier on response.json. To find it, I use this .bat file http://www.dostips.com/forum/viewtopic.php?f=3&t=4697 and then some variables. YOU SHOULD COPY ALL CODE TO GET THIS WORK!

 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 a 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!

+4
source

Source: https://habr.com/ru/post/973928/


All Articles