Extract version from go.mod files (#32)

* Extract version from go.mod files

* make it work on linux too

* whitespace

* ignore asdf testing checkout

* fix test
This commit is contained in:
Michael Hale 2020-06-16 18:08:17 -04:00 committed by GitHub
parent 831b8db058
commit b7780500cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 4 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/asdf/

View File

@ -1,5 +1,5 @@
language: c
script: asdf plugin test golang . --asdf-plugin-gitref $TRAVIS_COMMIT go version
script: asdf plugin test golang $TRAVIS_BUILD_DIR --asdf-plugin-gitref $TRAVIS_COMMIT go version
before_script:
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y bsdmainutils; fi
- git clone https://github.com/asdf-vm/asdf.git

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash
echo ".go-version"
echo ".go-version go.mod"

21
bin/parse-legacy-file Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
get_legacy_version() {
current_file="$1"
basename=$(basename -- "$current_file")
if [ "$basename" == "go.mod" ]; then
GOLANG_VERSION=$(grep 'go\s*[0-9]' "$current_file" |
sed -e 's/.*heroku goVersion //' \
-e 's/[[:space:]]//' \
-e 's/go\(.*\)/\1/' |
head -1
)
else
GOLANG_VERSION=$(cat "$current_file")
fi
echo "$GOLANG_VERSION"
}
get_legacy_version "$1"