Skip to content

Commit 6310f1c

Browse files
Use authentication to retrieve Github resources (#1375)
1 parent b0d56dd commit 6310f1c

4 files changed

Lines changed: 23 additions & 21 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ jobs:
1111
with:
1212
dotnet-version: "3.0.100"
1313
- run: pwsh ./test.ps1
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bin/fetch-configlet

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
LATEST=https://github.com/exercism/configlet/releases/latest
3+
LATEST=https://api.github.com/repos/exercism/configlet/releases/latest
44

55
OS=$(
66
case $(uname) in
@@ -24,7 +24,14 @@ case $(uname -m) in
2424
echo 64bit;;
2525
esac)
2626
27-
VERSION="$(curl --head --silent $LATEST | awk -v FS=/ '/Location:/{print $NF}' | tr -d '\r')"
28-
URL=https://github.com/exercism/configlet/releases/download/$VERSION/configlet-$OS-${ARCH}.tgz
27+
FILENAME="configlet-${OS}-${ARCH}.tgz"
2928
30-
curl -s --location $URL | tar xz -C bin/
29+
if [ -z "${GITHUB_TOKEN}" ]
30+
then
31+
HEADER=""
32+
else
33+
HEADER="authorization: Bearer ${GITHUB_TOKEN}"
34+
fi
35+
36+
URL=$(curl --header $HEADER -s $LATEST | awk -v filename=$FILENAME '$1 ~ /browser_download_url/ && $2 ~ filename { print $2 }' | tr -d '"')
37+
curl --header $HEADER -s --location $URL | tar xz -C bin/

bin/fetch-configlet.ps1

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
Function RedirectLocationHeader([string]$url) {
2-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3-
4-
$latest = "https://github.com/exercism/configlet/releases/latest"
5-
$request = [System.Net.WebRequest]::Create($latest)
6-
$request.AllowAutoRedirect = $false
7-
$response = $request.GetResponse()
8-
9-
$response.GetResponseHeader("Location")
1+
Function DownloadUrl ([string] $FileName, $Headers) {
2+
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
3+
$json = Invoke-RestMethod -Headers $Headers -Uri $latestUrl
4+
$json.assets | Where-Object { $_.browser_download_url -match $FileName } | Select-Object -ExpandProperty browser_download_url
105
}
116

12-
Function LatestVersion {
13-
$location = RedirectLocationHeader("https://github.com/exercism/configlet/releases/latest")
14-
$location.Substring($location.LastIndexOf("/") + 1)
7+
Function Headers {
8+
If ($GITHUB_TOKEN) { $headers = @{ Authorization = "Bearer ${GITHUB_TOKEN}" } } Else { $headers = @{ } }
159
}
1610

1711
Function Arch {
1812
If ([Environment]::Is64BitOperatingSystem) { "64bit" } Else { "32bit" }
1913
}
2014

2115
$arch = Arch
22-
$version = LatestVersion
16+
$headers = Headers
2317
$fileName = "configlet-windows-$arch.zip"
24-
$url = "https://github.com/exercism/configlet/releases/download/$version/$filename"
2518
$outputDirectory = "bin"
2619
$outputFile = Join-Path -Path $outputDirectory -ChildPath $fileName
20+
$zipUrl = DownloadUrl -FileName $fileName -Headers $headers
2721

28-
Invoke-WebRequest -Uri $url -OutFile $outputFile
22+
Invoke-WebRequest -Headers $headers -Uri $zipUrl -OutFile $outputFile
2923
Expand-Archive $outputFile -DestinationPath $outputDirectory -Force
3024
Remove-Item -Path $outputFile

test.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ function Test-Using-Example-Implementation {
7777
Run-Command "dotnet test $testTarget"
7878
}
7979

80-
# Currently, configlet isn't stable and fails intermittently, so this check is removed until the root issue is fixed
81-
# Configlet-Lint
80+
Configlet-Lint
8281
Clean
8382
Copy-Exercises
8483
Enable-All-Tests

0 commit comments

Comments
 (0)