Last active
May 19, 2020 04:59
-
-
Save danclien/d77038817dc696b656a7eeaf0917f542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Probably ~90% correct | |
# Be sure to update the line that sets MatchingAssets to whatever requirement you need | |
# Only downloads the first asset in MatchingAssets | |
jobname: | |
steps: | |
- name: Download latest | |
id: download | |
shell: pwsh | |
run: | | |
# Requires a GitHub personal access token with `repo` scope | |
[char[]]$Token = "${{ secrets.BUILD_GITHUB_TOKEN }}" | |
$Base64Token = [System.Convert]::ToBase64String($Token); | |
$Repository = "user/repo" | |
$OutputPath = "${{ github.workspace }}/output.zip" | |
$Headers = @{ | |
Authorization = "Basic $Base64Token" | |
} | |
# Get latest release | |
Write-Host "Checking for latest release" | |
$LatestRelease = Invoke-RestMethod -Headers $Headers -Uri "https://api.github.com/repos/$Repository/releases/latest" -Method GET | |
Write-Host "Latest release is $($LatestRelease.tag_name)" | |
# Get all assets for the release | |
$Assets = Invoke-RestMethod -Headers $Headers -Uri $LatestRelease.assets_url -Method GET | |
Write-Host "Release assets:" | |
$Assets | Select-Object -ExpandProperty "browser_download_url" | |
# Find assets matching pattern | |
$MatchingAssets = $Assets | Where-Object { $_.browser_download_url.Contains("-win-")} | |
# Download the first asset | |
$DownloadUrl = $MatchingAssets[0].url | |
Write-Host "Downloading $DownloadUrl" | |
$DownloadHeaders = @{ | |
Accept = "application/octet-stream" | |
Authorization = "Basic $Base64Token" | |
} | |
Write-Host "Downloading $DownloadUrl to $OutputPath" | |
Invoke-RestMethod -Headers $DownloadHeaders -Uri $DownloadUrl -Method GET -OutFile $OutputPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment