我构建了一个批处理文件,以便在AppVeyor上从我的CI服务器发布Github。一切正常,除非我尝试将我的资产上传到Github。我的技能对我帮助不大。有没有一种方法可以从cURL命令获取我的发布ID,以便在上传资产URL上使用它?非常感谢:)
编辑:我使用3个批处理文件:
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
但我不知道如何找到身份证。你能帮我吗? :)
答案 0 :(得分:4)
自答问题。找到一个搜索id的好方法真的很难,但现在它正在工作! :d
首先,在CI服务器上,构建工件后,创建一个标记。
git tag :yourversion
将您的标签推送到GitHub(我使用令牌来避免用户名和密码)
git push https://your_token:@github.com/you/yourrepo.git --tags
现在使用cURL创建一个版本。我使用了很多变量,所以我想用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
在response.json上有你的id。为了找到它,我使用这个.bat文件http://www.dostips.com/forum/viewtopic.php?f=3&t=4697 然后是一些变量。 您必须复制所有代码才能获得此工作!
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
最后,将您的工件发布为正文消息
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
享受你的发布!