简体   繁体   English

如何自动将您的工件发布到GitHub

[英]How to release automatically your artifact to GitHub

I built a batch file to make Github releases from my CI server on AppVeyor. 我构建了一个批处理文件,以便在AppVeyor上从我的CI服务器发布Github。 Everything works fine except when I try to upload my asset to Github. 一切正常,除非我尝试将我的资产上传到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? 有没有一种方法可以从cURL命令获取我的发布ID,以便在上传资产URL上使用它? Thanks very much :) 非常感谢 :)

EDIT: I use 3 batch files: 编辑:我使用3个批处理文件:

AppveyorBuildReleases.bat 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 file_size.bat

set size=%~z1
AppVeyorBuildReleases2.bat

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? 你能帮我吗? :) :)

Self-answered question. 自答问题。 It was really hard to find a good way to search the id, but now it's working! 找到一个搜索id的好方法真的很难,但现在它正在工作! :D :d

How to release automatically your artifact to GitHub 如何自动将您的工件发布到GitHub

First, on your CI server, after building the artifact, create a tag. 首先,在CI服务器上,在构建工件之后,创建一个标记。

git tag :yourversion 

Push your tag to GitHub (I use a token to avoid username and password) 将您的标签推送到GitHub(我使用令牌来避免用户名和密码)

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

Now create a release with cURL. 现在使用cURL创建一个版本。 I use a lot of variables, so I want use echo to write the variables then push with a json file 我使用了很多变量,所以我想用echo写入变量然后用json文件推送

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. 在response.json上有你的id。 To find it I use this .bat file http://www.dostips.com/forum/viewtopic.php?f=3&t=4697 and then some variables. 为了找到它我使用这个.bat文件http://www.dostips.com/forum/viewtopic.php?f=3&t=4697然后是一些变量。 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! 享受你的发布!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM