Re: [go-nuts] Check for minimum Go version

2017-08-10 Thread Michael Banzon
Thanks for the responses.

I will try a few options and see what fit best.

For a bit of context I’m making a script to check if the entire toolchain 
needed to build a project is present on the machine. The script checks for 
node/npm, Go, GCC and a few other tools (like go-bindata eg.). The real 
challenge (atm) is minimum required versions and that this must run on Windows, 
Linux and macOS. A pragmatic solution would be to cut this effort short and 
have the team accept “if build fails, check that this list of tools is 
installed” (it is a <10 ppl team). Another option I’m toying is having the 
(up-to-date) toolchain in a container.

-- 
Michael Banzon
https://michaelbanzon.com/




> Den 10. aug. 2017 kl. 09.14 skrev Konstantin Khomoutov :
> 
> On Wed, Aug 09, 2017 at 03:11:48PM +0200, Michael Banzon wrote:
> 
>> Is there a way to have a (bash) script check if the version of the Go
>> compiler installed is a specific minimum version?
> 
> In the light of [1], I think you could combine checking of the presense
> of the `go` tool itself with build tags.
> Say, something like this (untested):
> 
> >8
>  set -eu
> 
>  rc=0
>  go version >/dev/null || rc=$?
>  if [ $rc -ne 0 ]; then
>echo "The 'go' tool is not available" >&2
>exit 2
>  fi
> 
>  d=`mktemp -d`
>  f=`mktemp`
>  trap "rm -rf '$d' '$f'" EXIT INT TERM QUIT
>  cd "$d"
> 
>  cat >false.go <<'EOF'
>  // +build !go1.7
>  package main
> 
>  import "os"
> 
>  func main() {
>os.Exit(1)
>  }
>  EOF
> 
>  cat >true.go <<'EOF'
>  // +build go1.7
>  package main
> 
>  import "os"
> 
>  func main() {
>os.Exit(0)
>  }
>  EOF
> 
>  go build -o "$f" "$d/*.go"
> 
>  rc=0
>  "$f" || rc=1
> 
>  if [ $rc -ne 0 ]; then
>echo "Insufficient Go version" >&2
>exit 2
>  fi
> 
>  exit 0
> >8
> 
> One possible caveat is that `mktemp` by default creates its filesystem
> entries under $TMPDIR or /tmp, and that directory might be mounted with
> "noexec" on certain systems.  So if your setup script (or whatever it
> is) has a luxury of using its own scratch space, you should probably do
> that (like creating a temp. directory using `mktemp -f ~/.cache/XX`
> or something like this).
> 
> 1. https://github.com/golang/go/issues/21207
> 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Check for minimum Go version

2017-08-10 Thread Konstantin Khomoutov
On Wed, Aug 09, 2017 at 03:11:48PM +0200, Michael Banzon wrote:

> Is there a way to have a (bash) script check if the version of the Go
> compiler installed is a specific minimum version?

In the light of [1], I think you could combine checking of the presense
of the `go` tool itself with build tags.
Say, something like this (untested):

>8
  set -eu
  
  rc=0
  go version >/dev/null || rc=$?
  if [ $rc -ne 0 ]; then
echo "The 'go' tool is not available" >&2
exit 2
  fi
  
  d=`mktemp -d`
  f=`mktemp`
  trap "rm -rf '$d' '$f'" EXIT INT TERM QUIT
  cd "$d"
  
  cat >false.go <<'EOF'
  // +build !go1.7
  package main
  
  import "os"
  
  func main() {
os.Exit(1)
  }
  EOF
  
  cat >true.go <<'EOF'
  // +build go1.7
  package main
  
  import "os"
  
  func main() {
os.Exit(0)
  }
  EOF
  
  go build -o "$f" "$d/*.go"
  
  rc=0
  "$f" || rc=1
  
  if [ $rc -ne 0 ]; then
echo "Insufficient Go version" >&2
exit 2
  fi
  
  exit 0
>8

One possible caveat is that `mktemp` by default creates its filesystem
entries under $TMPDIR or /tmp, and that directory might be mounted with
"noexec" on certain systems.  So if your setup script (or whatever it
is) has a luxury of using its own scratch space, you should probably do
that (like creating a temp. directory using `mktemp -f ~/.cache/XX`
or something like this).

1. https://github.com/golang/go/issues/21207

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Check for minimum Go version

2017-08-09 Thread 'Chris Manghane' via golang-nuts
You might want to follow the discussion in golang.org/issue/21207 which
might be related to this, depending on the reason you need to know the
minimum Go version. `go version` doesn't return the version number on
non-tagged releases so if you're building off of tip, for example, the
output is a bit harder to parse in terms "what's the minimum tagged
version?"

Hopefully that's helpful,
Chris

On Wed, Aug 9, 2017 at 7:05 AM, Noilson Caio  wrote:

> Maybe something like this may help you
>
> #!/bin/bash## requirements: bc, awk, tr, cut##_gocurrel="$(go version|awk 
> '{print $3}'|tr -d "go"|cut -d"." -f1-2)"_gominrel="1.5"###_key=$(echo 
> "$_gominrel > $_gocurrel" | bc -l)###if [ "$_key" != "0" ]then
>   echo "Ops! Current go release is $_gocurrel and you need $_gominrel"
>   exit 1fi###
>
>
>
> On Wed, Aug 9, 2017 at 10:15 AM, Shawn Milochik 
> wrote:
>
>> Running "go version" at the command line returns a version number. You
>> can parse that.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Noilson Caio Teixeira de Araújo
> https://ncaio.wordpress.com
> https://br.linkedin.com/in/ncaio
> https://twitter.com/noilsoncaio
> https://jammer4.wordpress.com/
> http://8bit.academy
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Check for minimum Go version

2017-08-09 Thread Shawn Milochik
Running "go version" at the command line returns a version number. You can
parse that.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Check for minimum Go version

2017-08-09 Thread Michael Banzon
Hi,

Is there a way to have a (bash) script check if the version of the Go compiler 
installed is a specific minimum version?

-- 
Michael Banzon
https://michaelbanzon.com/




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.