Skip to content
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

Add configlet #1737

Merged
merged 3 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# OS specific auto-generated folders and files
*.swp
.DS_Store

# Platform specific tools (use fetch-configlet)
bin/configlet
bin/configlet.exe

# IDE folders and files
.idea
Comment on lines +9 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should go into local exclude files since people use different IDEs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really care tbh. I added it because a few other repos have it; I agree that it should be local ignored, but this forces keeping it out of this repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't really care either, but it also isn't harmful so I'm fine with having it here!


# package.json generated content
node_modules

# Ignore npm error/log
npm-debug.log

# Ignore yarn lockfile and error, in case someone accidentally runs yarn
yarn.lock
yarn-error.log
52 changes: 52 additions & 0 deletions bin/fetch-configlet
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -eo pipefail

readonly LATEST='https://api.github.com/repos/exercism/configlet/releases/latest'

case "$(uname)" in
(Darwin*) OS='mac' ;;
(Linux*) OS='linux' ;;
(Windows*) OS='windows' ;;
(MINGW*) OS='windows' ;;
(MSYS_NT-*) OS='windows' ;;
(*) OS='linux' ;;
esac

case "$OS" in
(windows*) EXT='zip' ;;
(*) EXT='tgz' ;;
esac

case "$(uname -m)" in
(*64*) ARCH='64bit' ;;
(*686*) ARCH='32bit' ;;
(*386*) ARCH='32bit' ;;
(*) ARCH='64bit' ;;
esac

if [ -z "${GITHUB_TOKEN}" ]
then
HEADER=''
else
HEADER="authorization: Bearer ${GITHUB_TOKEN}"
fi

FILENAME="configlet-${OS}-${ARCH}.${EXT}"

get_url () {
curl --header "$HEADER" -s "$LATEST" |
awk -v filename=$FILENAME '$1 ~ /browser_download_url/ && $2 ~ filename { print $2 }' |
tr -d '"'
}

URL=$(get_url)

case "$EXT" in
(*zip)
curl --header "$HEADER" -s --location "$URL" -o bin/latest-configlet.zip
unzip bin/latest-configlet.zip -d bin/
rm bin/latest-configlet.zip
;;
(*) curl --header "$HEADER" -s --location "$URL" | tar xz -C bin/ ;;
esac
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions bin/fetch-configlet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Function DownloadUrl ([string] $FileName, $Headers) {
$latestUrl = "https://api.github.com/repos/exercism/configlet/releases/latest"
$json = Invoke-RestMethod -Headers $Headers -Uri $latestUrl
$json.assets | Where-Object { $_.browser_download_url -match $FileName } | Select-Object -ExpandProperty browser_download_url
}

Function Headers {
If ($GITHUB_TOKEN) { @{ Authorization = "Bearer ${GITHUB_TOKEN}" } } Else { @{ } }
}

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

$arch = Arch
$headers = Headers
$fileName = "configlet-windows-$arch.zip"
$outputDirectory = "bin"
$outputFile = Join-Path -Path $outputDirectory -ChildPath $fileName
$zipUrl = DownloadUrl -FileName $fileName -Headers $headers

Invoke-WebRequest -Headers $headers -Uri $zipUrl -OutFile $outputFile
Expand-Archive $outputFile -DestinationPath $outputDirectory -Force
Remove-Item -Path $outputFile
SleeplessByte marked this conversation as resolved.
Show resolved Hide resolved