Skip to content
Myr

Merge pull request #599 from ljharb/nvm_get_latest

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add `nvm_get_latest` This relates to #522, #561, #400. `nvm_get_latest` uses http://latest.nvm.sh which redirects to https://github.com/creationix/nvm/releases/latest which in turn redirects to the latest release tag.

authored by Jordan Harband · committed by Jordan Harband · parents c0a20f2, 25c6159 · Browse files · 4 files+181 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+181 added−0 removed

  • tests:+163 added−0 removed
  • other:+18 added−0 removed

4 files+181 added−0 removed

added:test/fast/Unit tests/nvm_get_latest missing curl or wget+20 added
1#!/bin/sh23die () { echo $@ ; cleanup ; exit 1; }45cleanup() {6 unset -f nvm_has7}89. ../../../nvm.sh1011nvm_has() { return 1 ; }1213OUTPUT="$(nvm_get_latest 2>&1)"14EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"15[ "_$OUTPUT" = "_nvm needs curl or wget to proceed." ] \16 || die "no curl/wget did not report correct error message, got '$OUTPUT'"17[ "_$EXIT_CODE" = "_1" ] \18 || die "no curl/wget did not exit with code 1, got $EXIT_CODE"1920cleanup
added:test/installation/nvm_get_latest/nvm_get_latest+117 added
1#!/bin/sh23die () { echo $@ ; cleanup ; exit 1; }45cleanup() {6 unset -f curl wget nvm_has7}89. ../../../nvm.sh1011EXPECTED_VERSION="v12.3.456"12URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION"13EXPECTED_CURL_ARGS="-w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"14EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"1516curl() {17 if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then18 echo 2>& "expected args ($EXPECTED_CURL_ARGS), got ($*)"19 return 120 else21 echo $URL22 fi23}24wget() {25 if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then26 echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)"27 return 128 else29 local WGET_CONTENTS30 WGET_CONTENTS="31--2014-12-21 18:11:14-- http://latest.nvm.sh/32Resolving latest.nvm.sh... 50.31.209.22933Connecting to latest.nvm.sh|50.31.209.229|:80... connected.34HTTP request sent, awaiting response... 35 HTTP/1.1 301 Moved Permanently36 Location: https://github.com/creationix/nvm/releases/latest37 Content-Type: text/html; charset=utf-838 Content-Length: 8439 Date: Mon, 22 Dec 2014 02:11:15 GMT40Location: https://github.com/creationix/nvm/releases/latest [following]41--2014-12-21 18:11:15-- https://github.com/creationix/nvm/releases/latest42Resolving github.com... 192.30.252.13043Connecting to github.com|192.30.252.130|:443... connected.44HTTP request sent, awaiting response... 45 HTTP/1.1 302 Found46 Server: GitHub.com47 Date: Mon, 22 Dec 2014 02:11:15 GMT48 Content-Type: text/html; charset=utf-849 Transfer-Encoding: chunked50 Status: 302 Found51 X-XSS-Protection: 1; mode=block52 X-Frame-Options: deny53 Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com54 Cache-Control: no-cache55 Vary: X-PJAX56 Location: $URL57 X-UA-Compatible: IE=Edge,chrome=158 Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Fri, 22-Dec-2034 02:11:15 GMT; secure; HttpOnly59 Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzV9--e2fa4cf5305d61aa58c0e0bf21fdb335a9660dcf; path=/; secure; HttpOnly60 X-Request-Id: 4b99bf200157dd845f76ab83e4093acc61 X-Runtime: 0.03087262 X-Rack-Cache: miss63 X-GitHub-Request-Id: 45B56780:3913:880EF6:54977DC364 Strict-Transport-Security: max-age=31536000; includeSubdomains; preload65 X-Content-Type-Options: nosniff66 Vary: Accept-Encoding67 X-Served-By: ef97014f01ea59c1ef337fe51a4d033168Location: $URL [following]69--2014-12-21 18:11:15-- $URL70Reusing existing connection to github.com:443.71HTTP request sent, awaiting response... 72 HTTP/1.1 200 OK73 Server: GitHub.com74 Date: Mon, 22 Dec 2014 02:11:15 GMT75 Content-Type: text/html; charset=utf-876 Transfer-Encoding: chunked77 Status: 200 OK78 X-XSS-Protection: 1; mode=block79 X-Frame-Options: deny80 Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com81 Cache-Control: no-cache, private82 Vary: X-PJAX83 X-UA-Compatible: IE=Edge,chrome=184 Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzUsIl9jc3JmX3Rva2VuIjoiemZTVDNIRGo0QzF0dzkyNXp6NFBRdGJVbTl4NSsxTGo1cngwVFQ3NDVwdz0ifQ%3D%3D--b72bfd5241907dcf557b226e74351ff39f0e9ede; path=/; secure; HttpOnly85 X-Request-Id: 305b0d158bf8c0b3fa488a33d768709186 X-Runtime: 0.03854487 X-Rack-Cache: miss88 X-GitHub-Request-Id: 45B56780:3913:880F19:54977DC389 Strict-Transport-Security: max-age=31536000; includeSubdomains; preload90 X-Content-Type-Options: nosniff91 Vary: Accept-Encoding92 X-Served-By: 926b734ea1992f8ee1f88ab967a93dac93Length: unspecified [text/html]94Saving to: ‘/dev/null’9596 0K .......... ......... 225K=0.09s97982014-12-21 18:11:15 (225 KB/s) - ‘/dev/null’ saved [20298]99100"101 "$WGET_CONTENTS" | while read line102 do103 2>& echo "$line"104 done105 fi106}107108OUTPUT="$(nvm_get_latest)"109EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"110[ "_$OUTPUT" = "_$EXPECTED_VERSION" ] \111 || die "success path did not return version '$EXPECTED_VERSION', got '$OUTPUT'"112[ "_$EXIT_CODE" = "_0" ] \113 || die "success path did not exit with code 0, got $EXIT_CODE"114115116cleanup117
added:test/installation/nvm_get_latest/nvm_get_latest failed redirect+26 added
1#!/bin/sh23die () { echo $@ ; cleanup ; exit 1; }45cleanup() {6 unset -f curl wget7}89. ../../../nvm.sh1011curl() {12 return 113}14wget() {15 return 116}1718OUTPUT="$(nvm_get_latest 2>&1)"19EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"20[ "_$OUTPUT" = "_http://latest.nvm.sh did not redirect to the latest release on Github" ] \21 || die "failed redirect did not report correct error message, got '$OUTPUT'"22[ "_$EXIT_CODE" = "_2" ] \23 || die "failed redirect did not exit with code 2, got $EXIT_CODE"2425cleanup26
modified:nvm.sh+18 added
10 unmodified lines
11nvm_has() {12 type "$1" > /dev/null 2>&113}1415nvm_get_latest() {16 local NVM_LATEST_URL17 if nvm_has "curl"; then18 NVM_LATEST_URL="$(curl -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"19 elif nvm_has "wget"; then20 NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"21 else22 >&2 echo 'nvm needs curl or wget to proceed.'23 return 124 fi25 if [ "_$NVM_LATEST_URL" = "_" ]; then26 >&2 echo "http://latest.nvm.sh did not redirect to the latest release on Github"27 return 228 else29 echo "$NVM_LATEST_URL" | awk -F'/' '{print $NF}'30 fi31}3233nvm_download() {34 if nvm_has "curl"; then35 curl $*36 elif nvm_has "wget"; then
1083 unmodified lines