-
-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync fetch-configlet.ps1 script #2207
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
# This file is a copy of the | ||
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file. | ||
# Please submit bugfixes/improvements to the above file to ensure that all tracks | ||
# benefit from the changes. | ||
|
||
$ErrorActionPreference = "Stop" | ||
$ProgressPreference = "SilentlyContinue" | ||
|
||
if ($PSVersionTable.PSVersion.Major -le 5) { | ||
# PreserveAuthorizationOnRedirect requires PowerShell Core 7+ | ||
# TODO create a tool that install pwsh in the directory https://docs.microsoft.com/en-us/dotnet/core/tools/local-tools-how-to-use | ||
throw "Please run with PowerShell Core 'pwsh'. If you need to install pwsh globally: 'dotnet tool install --global PowerShell'" | ||
} | ||
|
||
function Get-DownloadUrl($FileName, $RequestOpts) { | ||
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest" | ||
$assets = Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @RequestOpts | Select-Object -ExpandProperty assets | ||
return $assets | Where-Object { $_.browser_download_url -match $FileName } | Select-Object -ExpandProperty browser_download_url -First 1 | ||
} | ||
|
||
# Use GITHUB_TOKEN to download the configlet metadata and binaries from github releases for github actions. | ||
$requestOpts = @{ | ||
Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } } | ||
MaximumRetryCount = 3 | ||
RetryIntervalSec = 1 | ||
} | ||
|
||
Function Get-DownloadUrl { | ||
$arch = If ([Environment]::Is64BitOperatingSystem) { "x86-64" } Else { "i386" } | ||
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest" | ||
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts ` | ||
| Select-Object -ExpandProperty assets ` | ||
| Where-Object { $_.name -match "^configlet_.+_windows_${arch}.zip$" } ` | ||
| Select-Object -ExpandProperty browser_download_url -First 1 | ||
} | ||
|
||
$outputDirectory = "bin" | ||
$arch = If ([Environment]::Is64BitOperatingSystem) { "64bit" } Else { "32bit" } | ||
$fileName = "configlet-windows-$arch.zip" | ||
if (!(Test-Path -Path $outputDirectory)) { | ||
Write-Output "Error: no ./bin directory found. This script should be ran from a repo root." | ||
exit 1 | ||
} | ||
|
||
Write-Output "Fetching configlet..." | ||
$downloadUrl = Get-DownloadUrl | ||
$outputFileName = "configlet.zip" | ||
$outputPath = Join-Path -Path $outputDirectory -ChildPath $outputFileName | ||
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputPath @requestOpts | ||
|
||
Write-Output "Fetching configlet download URL" | ||
$downloadUrl = Get-DownloadUrl -FileName $fileName -RequestOpts $requestOpts | ||
$outputFile = Join-Path -Path $outputDirectory -ChildPath $fileName | ||
$configletPath = Join-Path -Path $outputDirectory -ChildPath "configlet.exe" | ||
if (Test-Path -Path $configletPath) { Remove-Item -Path $configletPath } | ||
[System.IO.Compression.ZipFile]::ExtractToDirectory($outputPath, $outputDirectory) | ||
Remove-Item -Path $outputPath | ||
|
||
Write-Output "Fetching configlet binaries" | ||
# Use PreserveAuthorizationOnRedirect named parameter doesn't work on WSL | ||
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts | ||
Expand-Archive -Path $outputFile -DestinationPath $outputDirectory -Force | ||
Remove-Item -Path $outputFile | ||
$configletVersion = (Select-String -Pattern "/releases/download/(.+?)/" -InputObject $downloadUrl -AllMatches).Matches.Groups[1].Value | ||
Write-Output "Downloaded configlet ${configletVersion} to ${configletPath}" |
16 changes: 12 additions & 4 deletions
16
exercises/practice/reverse-string/.approaches/span/content.md
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like some other change to an unrelated file is added in this PR. Expected or incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa. Missed this comment. It was unintended but correct