Speed Up list-all/latest (#63)

* Switch to git ls-remote instead of parsing bucket.

* Update README to point to Travis.com
This commit is contained in:
Kenny Parnell 2021-11-16 09:58:02 -05:00 committed by GitHub
parent 85dab2f4f2
commit 09f1801f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 64 deletions

View File

@ -1,6 +1,6 @@
# asdf-golang
[![Build Status](https://travis-ci.org/kennyp/asdf-golang.svg?branch=master)](https://travis-ci.org/kennyp/asdf-golang)
[![Build Status](https://app.travis-ci.com/kennyp/asdf-golang.svg?branch=master)](https://app.travis-ci.com/kennyp/asdf-golang)
golang plugin for [asdf version manager](https://github.com/asdf-vm/asdf)

View File

@ -1,67 +1,10 @@
#!/usr/bin/env bash
set -eu
[ "${BASH_VERSINFO[0]}" -ge 3 ] && set -o pipefail
IFS=$'\n\t'
# This method is not stable, according to https://github.com/golang/go/issues/21667#issuecomment-325457742
BASE_URL='https://storage.googleapis.com/golang?marker='
NEXT_MARKER=''
TRUNCATED='true'
# Shamelessly stolen from: https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash {
function read_dom() {
local IFS=\>
read -rd \< ENTITY CONTENT
local RET=$?
TAG_NAME=${ENTITY%% *}
return $RET
}
function parse_dom() {
if [[ $TAG_NAME = "IsTruncated" ]] ; then
#echo "Is this page truncated: $CONTENT"
TRUNCATED=$CONTENT
elif [[ $TAG_NAME = "NextMarker" ]] ; then
#echo "What is the next marker: $CONTENT"
NEXT_MARKER=$CONTENT
elif [[ $TAG_NAME = "Key" ]] ; then
VERSIONS+=("${CONTENT}")
fi
}
function get_versions() {
XML=$(curl --silent "${BASE_URL}${NEXT_MARKER}")
while read_dom; do
parse_dom
done <<< "$XML"
}
# }
function loop_versions() {
if [[ $TRUNCATED = 'true' ]] ; then
get_versions
loop_versions
fi
}
mysed () {
if [ "$(uname | tr '[:upper:]' '[:lower:]' | sed -E 's/(darwin|freebsd)/HERE/')" = "HERE" ] ; then
sed -Ee "$1"
else
sed -re "$1"
fi
}
loop_versions
echo "${VERSIONS[@]}" \
| tr ' ' '\n' \
| grep '.tar.gz' \
| grep '\(linux\|darwin\|freebsd\)' \
| grep '\-\(amd64\|386\|armv6l\|armv7l\|arm64\)\.' \
| mysed 's/^go([^.]*).([^.]*).([^.]*).*/\1.\2.\3/' \
| mysed 's/.(linux|darwin|freebsd|src).*$//' \
| uniq \
| sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n \
| tr '\n' ' '
git ls-remote --tags https://github.com/golang/go "go*" \
| awk -F/go '{ print $2 }' \
| uniq \
| sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n \
| grep -v '^1\($\|\.0\|\.0\.[0-9]\|\.1\|\.1rc[0-9]\|\.1\.[0-9]\|.2\|\.2rc[0-9]\|\.2\.1\|.8.5rc5\)$' \
| tr '\n' ' '