簡體   English   中英

如何自動將您的工件發布到GitHub

[英]How to release automatically your artifact to GitHub

我構建了一個批處理文件,以便在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

但我不知道如何找到身份證。 你能幫我嗎? :)

自答問題。 找到一個搜索id的好方法真的很難,但現在它正在工作! :d

如何自動將您的工件發布到GitHub

首先,在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

享受你的發布!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM