chore: github api add token

This commit is contained in:
rankun 2020-02-24 14:28:28 +08:00
parent 39764c5b0e
commit d72b205c08
2 changed files with 16 additions and 2 deletions

View file

@ -97,10 +97,17 @@ jobs:
env:
githubFullName: ${{ github.event.repository.full_name }}
ref: ${{ github.event.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
run: |
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
$response = Invoke-RestMethod -Uri $url -Method Get
# github token防止api rate limite否则一个小时只能60个api请求
$token = ${env:github_token}
$authInfo = ("{0}" -f $token)
$authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
$authInfo = [System.Convert]::ToBase64String($authInfo)
$headers = @{Authorization=("barry-ran {0}" -f $authInfo)}
$response = Invoke-RestMethod -Uri $url -ContentType 'text/json' -Headers $headers -Method Get
[string]$latestUpUrl = $response.upload_url
Write-Host 'latestUpUrl:'$latestUpUrl
echo "::set-env name=uploadUrl::$latestUpUrl"

View file

@ -127,10 +127,17 @@ jobs:
env:
githubFullName: ${{ github.event.repository.full_name }}
ref: ${{ github.event.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
run: |
[string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1)
[string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag}
$response = Invoke-RestMethod -Uri $url -Method Get
# github token防止api rate limite否则一个小时只能60个api请求
$token = ${env:github_token}
$authInfo = ("{0}" -f $token)
$authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
$authInfo = [System.Convert]::ToBase64String($authInfo)
$headers = @{Authorization=("barry-ran {0}" -f $authInfo)}
$response = Invoke-RestMethod -Uri $url -ContentType 'text/json' -Headers $headers -Method Get
[string]$latestUpUrl = $response.upload_url
Write-Host 'latestUpUrl:'$latestUpUrl
echo "::set-env name=uploadUrl::$latestUpUrl"